在 Galacean 引擎中,每个 Shader Pass
代表一次 GPU 绘制过程,因此我们可以对每个 Pass
的渲染状态进行单独设置。在 ShaderLab 中我们有2种设置方式。
...
Pass "0" {
...
BlendState blendState {
Enabled = true;
ColorBlendOperation = BlendOperation.Add;
...
}
BlendState = blendState;
...
}
...
如全局变量章节所示,通过在各个层级全局变量域中声明渲染状态变量,然后通过 BlendState = blendState
进行指定。
...
Pass "0" {
...
BlendState {
Enabled = true;
ColorBlendOperation = BlendOperation.Add;
...
}
...
}
...
DepthState
、StencilState
和 RasterState
的设置同理。
全局变量域也可以是 SubShader
或Shader
层级,其作用域跟其他全局变量遵循同一规则。即如果是在 SubShader
层级全局变量域中设置的渲染状态,会对该 SubShader
下所有 Pass
生效。
单个渲染状态属性设置同样也有2种方式。
Shader "Demo" {
...
BlendState customBlendState
{
Enabled = true;
// 常量赋值方式
SourceColorBlendFactor = BlendFactor.SourceColor;
// 变量赋值方式
DestinationColorBlendFactor = material_DstBlend;
}
...
Pass "0" {
...
BlendState = customBlendState;
...
}
}
上述案例中对于 BlendState
属性赋值展示了 2 种方式: 常量赋值 和 变量赋值 方式:
赋值语句右端为指定的对应引擎枚举变量,譬如:BlendFactor.SourceColor。
渲染队列的设置例外: RenderQueueType = Transparent;
赋值语句右端为任一变量名,变量具体值可由开发者通过脚本方式在运行时通过 ShaderData.setInt("material_DstBlend", BlendFactor.SourceColor)
API 进行指定。