DreamShaderLang
语言核心

Section

Shader 与 ShaderFunction 内部 section 的语义。

ShaderShaderFunction 的主体由 section 组成。section 形式固定为:

SectionName = {
    ...
}

分号可写可不写,但建议统一省略 section 后的分号。

Properties

Properties 用在 Shader 中,声明材质参数或来自 UE.* 的内置节点属性。

Properties = {
    float Strength = 1.0;
    vec3 Tint = vec3(1.0, 0.8, 0.6);
    Texture2D MainTex = Path(Game, "/Textures/T_Main");
}

生成器会为普通 property 创建参数节点:

类型生成节点
标量Scalar Parameter。
向量Vector Parameter。
纹理Texture Object Parameter。
UE.*对应 Unreal MaterialExpression。

Inputs

Inputs 用在 ShaderFunction 中,声明材质函数输入 pin。

Inputs = {
    vec3 InColor;
    vec3 InTint;
    float Strength;
}

Inputs 也可在旧语义中写作 Properties,但新文档统一使用 Inputs

Outputs

Outputs 有两种语义。

Shader 中,它声明中间输出变量,并把变量绑定到 Unreal 材质属性或辅助输出节点:

Outputs = {
    vec3 Color;
    float Alpha;

    Base.EmissiveColor = Color;
    Base.Opacity = Alpha;
}

ShaderFunction 中,它声明材质函数输出 pin:

Outputs = {
    vec3 OutColor;
}

Outputs 也可在旧语义中写作 Results,但新文档统一使用 Outputs

Settings

Settings 配置 Unreal 材质或材质函数属性。

Settings = {
    Domain = "Surface";
    BlendMode = "Opaque";
    ShadingModel = "DefaultLit";
    TwoSided = true;
}

常用设置:

设置示例说明
Domain / MaterialDomain"UI"材质域。
BlendMode / RenderType"Translucent"混合模式。
ShadingModel"Unlit"Shading Model。
TwoSidedtrue双面渲染。
Wireframefalse线框渲染。
OpacityMaskClipValue0.3333Masked clip 阈值。

ShaderFunction 常见设置:

设置示例
Description"Tint helper"
ExposeToLibrarytrue
LibraryCategories"DreamShader,Color"

更多见 材质设置参考

Graph

Graph 是 DreamShaderLang 的材质图 DSL。

Graph = {
    vec2 uv = UE.TexCoord(Index=0);
    float t = UE.Time();
    Color = vec3(t, t, t);
}

ShaderShaderFunction 都必须用 Graph 描述图。旧的 Code = { ... } 不再用于 ShaderShaderFunction

Section 支持矩阵

SectionShaderShaderFunction
Properties支持可作为 Inputs 兼容写法
Inputs不支持支持
Outputs支持输出声明和绑定支持输出 pin
Results不支持可作为 Outputs 兼容写法
Settings支持支持
Graph必填支持
Code不支持不支持

On this page