DreamShaderLang
语言参考

UE 节点入口参考

Graph 与 Properties 中可用的 UE.* 材质节点创建入口。

UE.* 是 DreamShaderLang 创建 Unreal MaterialExpression 的入口。它可以在 Graph 表达式中使用,也可以在 Properties 中声明为预置节点。

这些入口和 .dsh 共享库无关。即使项目没有内置库文件,UE.* 仍然是语言层的节点创建语法。

Graph 调用

Graph = {
    float2 uv = UE.TexCoord(Index=0);
    float time = UE.Time();
    float pulse = UE.Expression(Class="Sine", OutputType="float1", Input=time);
}

常用 UE.* 节点入口:

调用输出说明
UE.TexCoord(...)float2Texture Coordinate。
UE.Time(...)float1Time。
UE.Panner(...)float2Panner。
UE.WorldPosition()float3World Position。
UE.ObjectPositionWS()float3Object Position WS。
UE.CameraVectorWS()float3Camera Vector WS。
UE.ScreenPosition()float4Screen Position。
UE.VertexColor()float4Vertex Color。
UE.TransformVector(...)float3Vector Transform。
UE.TransformPosition(...)float3Position Transform。
UE.Expression(...)显式指定泛型 MaterialExpression 创建入口。

UE.TexCoord

float2 uv = UE.TexCoord(Index=0);
float2 tiled = UE.TexCoord(Index=0, UTiling=2.0, VTiling=2.0);

参数:

参数类型说明
Index整数字面量UV channel。
UTiling数字字面量U 平铺。
VTiling数字字面量V 平铺。
UnMirrorU布尔字面量设置 UnMirrorU。
UnMirrorV布尔字面量设置 UnMirrorV。

UE.Time

float t = UE.Time();
float looped = UE.Time(Period=2.0, IgnorePause=true);

参数:

参数类型
Period数字字面量
IgnorePause布尔字面量

UE.Panner

float2 uv = UE.TexCoord(Index=0);
float t = UE.Time();
float2 panned = UE.Panner(Coordinate=uv, Time=t, SpeedX=0.1, SpeedY=0.0);

参数:

参数类型说明
Coordinatefloat2 表达式输入 UV。
Timefloat 表达式时间输入。
Speedfloat2 表达式速度输入。
SpeedX数字字面量X 速度。
SpeedY数字字面量Y 速度。
FractionalPart布尔字面量使用小数部分。

Transform

vec3 worldNormal = UE.TransformVector(
    Input=LocalNormal,
    Source="Tangent",
    Destination="World");

vec3 worldPos = UE.TransformPosition(
    Input=LocalPosition,
    Source="Local",
    Destination="World");

UE.TransformVector 的坐标系:

Tangent, Local, World, View, Camera, Instance

UE.TransformPosition 的坐标系:

Local, World, PeriodicWorld, TranslatedWorld, FirstPerson, View, Camera, Instance

泛型 UE.Expression

UE.Expression 可以创建任意可解析的 UMaterialExpression 子类。

float pulse = UE.Expression(
    Class="Sine",
    OutputType="float1",
    Input=UE.Time());

规则:

参数必需说明
ClassMaterialExpression 类名,可省略 MaterialExpression 前缀。
OutputType / ResultType告诉 DreamShader 输出类型。
Output / OutputName按输出名选择输出 pin。
OutputIndex按索引选择输出 pin。

其他命名参数会尝试绑定到该 MaterialExpression 的 UPROPERTY:

属性类型参数值
FExpressionInputGraph 表达式。
普通属性字面量。

示例:

float r = UE.Expression(
    Class="ComponentMask",
    OutputType="float1",
    Input=UV,
    R=true);

Properties 中的 UE.*

Properties 也可以声明 UE.* 节点,让它像 property 一样在 Graph 中可用。

Properties = {
    UE.TexCoord(Index=0) UV;
    UE.Time(Period=4.0) Time;
}

Graph = {
    Color = vec3(Time, UV.x, UV.y);
}

Properties 中的 UE.* 不支持等号默认值,参数应写在括号里。

// 正确
UE.TexCoord(Index=0) UV;

// 错误
UE.TexCoord UV = 0;

泛型 property 节点

Properties 中也可以用 OutputType 触发泛型 MaterialExpression:

Properties = {
    UE.Expression(Class="Sine", OutputType="float1", Input=Time) Pulse;
}

不过更常见的写法是在 Graph 中直接调用 UE.Expression(...),因为 Graph 中的输入关系更清晰。

On this page