In the Galacean engine, each Shader Pass
represents a GPU rendering process, so we can set rendering states for each Pass
individually. In ShaderLab, there are two ways to configure these states.
...
Pass "0" {
...
BlendState blendState {
Enabled = true;
ColorBlendOperation = BlendOperation.Add;
...
}
BlendState = blendState;
...
}
...
As shown in the global variables section, you can declare rendering state variables in different scope levels and then assign them using BlendState = blendState
.
...
Pass "0" {
...
BlendState {
Enabled = true;
ColorBlendOperation = BlendOperation.Add;
...
}
...
}
...
The configuration for DepthState
, StencilState
, and RasterState
follows the same pattern.
The global variable scope can also be at the SubShader
or Shader
level. Its scope follows the same rules as other global variables. For example, a rendering state defined at the SubShader
level will apply to all Pass
es under that SubShader
.
There are also two methods for configuring individual rendering state properties:
Shader "Demo" {
...
BlendState customBlendState
{
Enabled = true;
// Constant assignment
SourceColorBlendFactor = BlendFactor.SourceColor;
// Variable assignment
DestinationColorBlendFactor = material_DstBlend;
}
...
Pass "0" {
...
BlendState = customBlendState;
...
}
}
The above example demonstrates two approaches for assigning BlendState
properties: constant assignment and variable assignment.
The right-hand side of the assignment statement uses specific engine enum values, e.g.: BlendFactor.SourceColor
.
An exception exists for render queue configuration: RenderQueueType = Transparent;
The right-hand side of the assignment uses a variable name. The actual value can be set at runtime by developers through the API ShaderData.setInt("material_DstBlend", BlendFactor.SourceColor)
.