DreamShaderLang
编译器行为

诊断与排错

DreamShaderLang 常见错误、定位来源和处理方法。

DreamShaderLang 的错误大致分为四层:本地编辑诊断、解析错误、生成错误、Unreal 材质编译错误。

诊断来源

来源说明
VSCode 本地诊断编辑时发现语法、引用和简单语义问题。
Unreal Parser保存或重编时解析 .dsm / .dsh
Material Generator创建节点、连接输出、应用设置时产生。
Unreal Material CompilerUnreal 自身材质编译报错。

Source map

.dsm import 了 .dsh,DreamShader 会尽量把错误映射回真实源文件行列:

DShader/Shared/Common.dsh:12:5

这对共享 helper 很重要。否则所有错误都会落到展开后的合并文本里,难以定位。

常见解析错误

错误原因处理
Shader(Name="...") is requiredShader 缺少 Name补上资产路径。
Only one top-level Shader block is currently supported一个文件里写了多个 Shader拆成多个 .dsm
Shader must provide a Graph blockShader 没有 Graph添加 Graph = { ... }
Unknown shader sectionShader 中写了不支持的 section。使用 Properties / Settings / Outputs / Graph
Shader graph sections now use Graph还在 Shader 里使用 Code改为 Graph
Namespace may only contain Function or GraphFunction blocksnamespace 里放了其他顶层块。只保留 Function / GraphFunction

常见 Graph 错误

错误原因处理
Unknown Graph function函数未定义或未 import。检查 import 和 namespace。
Graph variable is declared more than once重复声明局部变量。改名或复用已有变量。
Arithmetic operators cannot be applied to Texture2D values对纹理对象做算术。先采样,或只对采样结果运算。
String literals can only be used in named UE builtin arguments字符串作为普通值使用。只在 UE.* 命名参数里使用字符串。
Graph if condition ... must evaluate to a scalar value条件不是标量。使用 .r.x 或 ComponentMask。
Graph if statement cannot select Texture2D value分支选择纹理对象。分支选择采样后的数值。
input ... is not optional and cannot use defaultoptShaderFunction / VirtualFunction 输入使用了 default给输入加 opt,或传入真实表达式。
StaticSwitchParameter ... requires True=... and False=...静态开关调用缺少分支。同时提供 TrueFalse 命名参数。
StaticSwitchParameter ... cannot switch Texture object values静态开关直接选择纹理对象。改为选择采样后的数值。
Graph #Region must include a nameregion 缺少名称。写成 #Region "Surface"
Graph #EndRegion has no matching #Region多写或错放 #EndRegion检查 region 配对。

Function 调用错误

错误原因正确写法
must be called with explicit out variables多输出 Function / GraphFunction 被当作单值表达式。ApplyTint(a, b, result);
currently uses positional arguments only使用了命名参数。Fn(a, b, outValue);
out argument must be a plain variable nameout 位置传了表达式。先声明变量再传入。
expects N arguments输入和输出目标数量不对。参数数量必须等于 inout
UE.* calls are not allowed in Function普通 Function 体内调用了图节点入口。改用 GraphFunction

UE builtin 错误

错误原因处理
Unsupported UE builtin call调用了未注册的 UE.*,又没写 OutputType使用 UE.Expression(..., OutputType="...")
Generic UE.* calls require named arguments泛型调用用了位置参数。改成命名参数。
Class must be a literal valueClass 不是字符串或字面量。Class="Sine"
OutputType is not supported输出类型不在支持范围。使用 float1/2/3/4 或纹理类型。
OutputIndex is out of range输出索引不存在。检查 MaterialExpression 输出。
UE.CollectionParam requires Collection=Path(...)MPC 读取缺少 Collection。Collection=Path(Game, "Collections/MPC_Name")
UE.CollectionParam collection ... does not contain parameter ...指定的 MPC 中没有该参数。检查 Material Parameter Collection 里的参数名。

VSCode 扩展 1.2.26 起,UE.CollectionParam(Collection=Path(...), ...) 中的 Path(...) 会被当作 DreamShader helper 处理,不再误报 Unknown function 'Path'。扩展 1.4.x 起,本地诊断改由新的 parser-based language core 提供,并陆续覆盖 .dsfLayout、Graph region、VolumeTexture / Texture3D 和 Function builtin,能更稳定地区分 InputsGraphFunctionSettingsOutputs 和 metadata context。

Layout 错误

错误原因处理
Layout statement is missing a trailing ';'Node(...)Comment(...) 后缺少分号。补上 ;
Layout statement should be Node(...) or Comment(...)Layout 中写了其他调用。只使用 NodeComment
Layout argument ... must use Key=Value syntax参数使用了位置写法。改为 X=0Var="Name"
Layout argument 'X' must be an integer坐标或尺寸不是整数。使用整数坐标。
Layout Comment Color must be a float4 literalColor 不是 float4(...) 字面量。写成 Color=float4(0.10, 0.16, 0.22, 0.35)

Material Layer 错误

错误原因处理
ShaderLayer must output exactly one MaterialAttributes valueShaderLayer 输出缺失、过多或类型不是 MaterialAttributes只声明一个 MaterialAttributes 输出。
ShaderLayerBlend must declare at least two MaterialAttributes inputsLayer Blend 输入不满足原生 Layer Blend 形状。至少声明两个 MaterialAttributes 输入。
MaterialLayer is deprecated使用了旧兼容关键字。改为 ShaderLayer / ShaderLayerBlend

材质输出错误

错误原因处理
Unsupported material outputBase.* 名称不支持。输出绑定
bound material property expects a different type输出变量类型与目标不匹配。修改声明类型或绑定目标。
Expression output target must use .Pin[index]辅助输出节点格式错误。使用 Expression(Class="...").Pin[0]

排错顺序

  1. 先看 VSCode 红线,修掉明显语法和 import 问题。
  2. 执行 DreamShaderLang: Recompile Current Source
  3. 看 Unreal Output Log 或 VSCode 桥接诊断。
  4. 如果是材质编译器错误,定位到生成的 Custom 节点代码。
  5. 对复杂逻辑,先缩小到最小 .dsm,再逐步恢复 import 和 helper。

本页目录