A material contains Shader, ShaderData, and RenderStates.
A Shader is a program that runs on the GPU, typically consisting of a vertex shader and a fragment shader. You can conveniently write this code using ShaderLab syntax.
Like other programming languages, we use many variables when writing shaders. Refer to the built-in variables documentation to find the desired built-in variables. You can also manually upload shader data and macro switches via the ShaderData tutorial:
Galacean supports configuring BlendState, DepthState, StencilState, and RasterState.
Let's take a standard rendering process for a transparent object as an example. We enable transparent blending and disable depth writing since transparent objects are rendered additively. We also set it to the transparent render queue:
material.renderQueueType = RenderQueueType.Transparent;
material.renderState.depthState.writeEnabled = false;
material.renderState.blendState.enabled = true;
We recommend using ShaderLab for configuration:
Pass "Pass0" {
DepthState {
WriteEnabled = false;
}
BlendState {
Enabled = true;
SourceColorBlendFactor = BlendFactor.SourceAlpha;
DestinationColorBlendFactor = BlendFactor.OneMinusSourceAlpha;
SourceAlphaBlendFactor = BlendFactor.One;
DestinationAlphaBlendFactor = BlendFactor.OneMinusSourceAlpha;
}
RenderQueueType = Transparent;
}
Render states can also be set as variables and controlled via ShaderData. For details, see ShaderLab Render State Configuration.