mirror of
https://github.com/galacean/engine.git
synced 2026-07-07 03:34:30 +08:00
86 lines
2.3 KiB
Plaintext
86 lines
2.3 KiB
Plaintext
---
|
|
title: 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
|
|
|
|
```glsl showLineNumbers {4, 10}
|
|
...
|
|
Pass "0" {
|
|
...
|
|
BlendState blendState {
|
|
Enabled = true;
|
|
ColorBlendOperation = BlendOperation.Add;
|
|
...
|
|
}
|
|
|
|
BlendState = blendState;
|
|
...
|
|
}
|
|
...
|
|
```
|
|
|
|
As shown in the [global variables section](./global), you can declare rendering state variables in different scope levels and then assign them using `BlendState = blendState`.
|
|
|
|
### 2. Declaration within Global Variable Scope
|
|
|
|
```glsl showLineNumbers {4}
|
|
...
|
|
Pass "0" {
|
|
...
|
|
BlendState {
|
|
Enabled = true;
|
|
ColorBlendOperation = BlendOperation.Add;
|
|
...
|
|
}
|
|
|
|
...
|
|
}
|
|
...
|
|
```
|
|
|
|
<Callout type="info">
|
|
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](./global/#Global_Variable_Scope) as other global variables. For example, a rendering state defined at the `SubShader` level will apply to all `Pass`es under that `SubShader`.
|
|
</Callout>
|
|
|
|
## Rendering State Property Configuration
|
|
|
|
There are also two methods for configuring individual rendering state properties:
|
|
|
|
```glsl showLineNumbers {7,9}
|
|
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`.
|
|
|
|
<Callout type="warning">
|
|
An exception exists for render queue configuration: `RenderQueueType = Transparent;`
|
|
</Callout>
|
|
|
|
### 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)`. |