Sets the color channel writing mask, which prevents the GPU from writing to channels in the render target.
By default, the GPU writes to all channels (RGBA). For some effects you might want to leave certain channels unmodified; for example, you can disable color rendering to render uncolored shadows. Another common use case is to disable color writes completely so that you can populate one buffer with data without writing to others; for example, you might want to populate the stencil buffer without writing to the render target.
Feature name | 빌트인 렌더 파이프라인 | 유니버설 렌더 파이프라인(URP) | 고해상도 렌더 파이프라인(HDRP) | Custom SRP |
---|---|---|---|---|
ColorMask | 지원 | 지원 | 지원 | 지원 |
This command makes a change to the render state. Use it in a Pass
block to set the render state for that Pass, or use it in a SubShader
block to set the render state for all Passes in that SubShader.
Signature | Example syntax | 기능 |
---|---|---|
ColorMask <channels> |
ColorMask RGB |
Write to the given channels of the default render target. |
ColorMask <channels> <render target> |
ColorMask RGB 2 |
As above, but for a given render target. |
파라미터 | 값 | 기능 |
---|---|---|
render target | Integer, 0 through 7. | The render target index. |
channels | 0 |
Enables color writes to the R, G, B, and A channels. |
R |
Enables color writes to the red channel. | |
G |
Enables color writes to the green channel. | |
B |
Enables color writes to the blue channel. | |
A |
Enables color writes to the alpha channel. | |
Any combination of R , G , B , and A without spaces. For example: RB
|
Enables color writes to the given channels. |
Shader "Examples/CommandExample"
{
SubShader
{
// The rest of the code that defines the SubShader goes here.
Pass
{
// Enable writing only to the RGB channels for this Pass, which disables writing to the alpha channel
ColorMask RGB
// The rest of the code that defines the Pass goes here.
}
}
}
This example code demonstrates the syntax for using this command in a SubShader block.
Shader "Examples/CommandExample"
{
SubShader
{
// Enable writing only to the RGB channels for this SubShader, which disables writing to the alpha channel
ColorMask RGB
// The rest of the code that defines the SubShader goes here.
Pass
{
// The rest of the code that defines the Pass goes here.
}
}
}