Rendering State Setup

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.

1. Explicit Assignment

...
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.

2. Declaration within Global Variable Scope

...
Pass "0" {
  ...
  BlendState {
    Enabled = true;
    ColorBlendOperation = BlendOperation.Add;
    ...
  }
 
  ...
}
...
  1. The configuration for DepthState, StencilState, and RasterState follows the same pattern.

  2. 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 Passes under that SubShader.

Rendering State Property Configuration

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.

Constant 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;

Variable Assignment

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).

Was this page helpful?