类型和值
DreamShaderLang 的标量、向量、纹理、Path 与字面量规则。
DreamShaderLang 的公开语法主要围绕材质图与 HLSL helper。Properties、Inputs、Outputs 与 Graph 支持一组有限但实用的类型。
标量类型
| 类型 | 说明 |
|---|---|
float / float1 | 1 分量浮点。 |
half / half1 | 1 分量 half。 |
int | 1 分量整数。 |
uint | 1 分量无符号整数。 |
bool | 1 分量布尔。 |
在材质图中,这些最终都按 Unreal 材质表达式的标量输出处理。
向量类型
| 类型族 | 支持类型 |
|---|---|
| float | float2 / float3 / float4 |
| half | half2 / half3 / half4 |
| int | int2 / int3 / int4 |
| uint | uint2 / uint3 / uint4 |
| bool | bool2 / bool3 / bool4 |
GLSL 风格别名
| 别名 | 等价类型 |
|---|---|
vec2 / vec3 / vec4 | float2 / float3 / float4 |
ivec2 / ivec3 / ivec4 | int2 / int3 / int4 |
uvec2 / uvec3 / uvec4 | uint2 / uint3 / uint4 |
bvec2 / bvec3 / bvec4 | bool2 / bool3 / bool4 |
Function 的 HLSL 代码会把这些别名规范化成 HLSL 风格类型。mat2 / mat3 / mat4 会规范化为 float2x2 / float3x3 / float4x4,主要用于 helper 代码;Graph、Properties 和输出 pin 当前主要面向标量、向量和纹理。
纹理类型
| 类型 | 用途 |
|---|---|
Texture2D | 2D 纹理对象。 |
TextureCube | Cube 纹理对象。 |
Texture2DArray | 2D Array 纹理对象。 |
VolumeTexture / Texture3D | 3D / Volume 纹理对象。 |
SamplerState | 采样器类型,主要用于 helper 参数。 |
纹理值可以作为 Properties,也可以作为 Function / ShaderFunction 参数。ShaderFunction.Properties 中的 const Texture2D PreviewTex; 会生成 Texture Object helper,可作为 Inputs 的预览默认值。const TextureCube、const Texture2DArray 和 const VolumeTexture 建议显式指定默认资产,避免目标项目缺少合适默认资源。Graph if 不能在两条分支之间选择纹理对象。
MaterialAttributes
MaterialAttributes 表示 Unreal 的完整材质属性聚合值。它适合把一组材质属性作为一个值从 ShaderFunction / VirtualFunction 返回,或在 Shader 中绑定到主材质输出:
Outputs = {
MaterialAttributes Attrs;
Base.MaterialAttributes = Attrs;
}
Graph = {
Attrs.BaseColor = Color;
Attrs.Roughness = Roughness;
}MaterialAttributes 不是普通数值向量,不能参与加减乘除或向量构造。读取成员时会得到对应的数值类型,例如 Attrs.BaseColor 是 float3,Attrs.Roughness 是 float。
Parameter 节点类型
Properties 中除了通用类型,也可以写显式 Unreal Parameter 节点类型:
| 类型 | 用途 |
|---|---|
ScalarParameter | 标量材质参数。 |
VectorParameter / DoubleVectorParameter | 向量材质参数。 |
TextureObjectParameter | 纹理对象参数。 |
TextureSampleParameter2D / TextureSampleParameterCube / TextureSampleParameter2DArray | 纹理采样参数。 |
StaticBoolParameter | 静态布尔参数。 |
StaticSwitchParameter | 静态开关参数,可在 Graph 中连接 True / False 分支。 |
这些类型主要用于更明确地控制生成出来的 Unreal MaterialExpression 类型。参数分组、排序、说明和节点专属属性使用声明尾部的反射属性块:
ScalarParameter Roughness = 0.35 [
Group="Surface";
SortPriority=10;
Description="Material roughness";
];在 Properties 声明前加 const 会生成不可外部调参的常量/helper 节点:
Properties = {
const float PreviewStrength = 1.0;
const Texture2D PreviewTex;
}属性块按 Unreal MaterialExpression 的 UPROPERTY 名称反射写入节点;不写的字段保持 Unreal 默认值。
字面量
标量
float a = 1.0;
float b = -0.5;
float c = 1e-3;向量构造
vec2 uv = vec2(0.5, 0.5);
vec3 color = vec3(1.0, 0.2, 0.1);
float4 rgba = float4(color, 1.0);构造器支持不同分量值组合,只要最终能合并成目标向量宽度。
Brace initializer
vec3 color = {1.0, 0.2, 0.1};
float4 rgba = {color, 1.0};Brace initializer 常用于把已有标量或向量拼成目标类型。
字符串
字符串字面量主要用于 UE.* 的命名参数:
float pulse = UE.Expression(
Class="Sine",
OutputType="float1",
Input=UE.Time());普通图表达式中不能把字符串当作值参与运算。
Path(...)
纹理 property、对象类 Settings、VirtualFunction 的 Options.Asset 和 UE.CollectionParam(...) 的 Collection 可以使用 Path(...) 指定 Unreal 资产。
Properties = {
Texture2D MainTex = Path(Game, "/Textures/T_Main");
Texture2D PluginTex = Path(Plugins.MoonToon, "/Textures/T_Plugin");
Texture2D DefaultTex = Path("/Engine/EngineResources/DefaultTexture");
TextureCube SkyTex = Path(Engine, "/EngineResources/DefaultTextureCube");
VolumeTexture NoiseVolume = Path(Game, "/Textures/T_NoiseVolume");
}规则:
| 形式 | 结果 |
|---|---|
Path(Game, "/Textures/T_Main") | /Game/Textures/T_Main.T_Main |
Path(Engine, "/EngineResources/DefaultTexture") | /Engine/EngineResources/DefaultTexture.DefaultTexture |
Path(Plugin.MoonToon, "MaterialFunctions/Buffer/Writer") | /MoonToon/MaterialFunctions/Buffer/Writer.Writer |
Path(Plugins.MoonToon, "MaterialFunctions/Buffer/Writer") | 与 Plugin.MoonToon 相同。 |
Path("/Game/Textures/T_Main") | 保留 /Game 根。 |
Path("/Engine/EngineResources/DefaultTexture") | 保留 /Engine 根。 |
如果路径没有写 .AssetName,生成器会根据最后一段自动补齐对象路径。
已移除别名
早期别名 Scalar / Color / Vector 已移除。请使用:
| 旧写法 | 新写法 |
|---|---|
Scalar | float |
Vector | float2 / float3 / float4 |
Color | float3 / float4 或 vec3 / vec4 |