Version: 2020.3
ShaderLab command: BlendOp
ShaderLab command: Conservative

ShaderLab command: ColorMask

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.

Valid parameter values

파라미터 기능
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.
        }
    }
}
ShaderLab command: BlendOp
ShaderLab command: Conservative
Copyright © 2023 Unity Technologies
优美缔软件(上海)有限公司 版权所有
"Unity"、Unity 徽标及其他 Unity 商标是 Unity Technologies 或其附属机构在美国及其他地区的商标或注册商标。其他名称或品牌是其各自所有者的商标。
公安部备案号:
31010902002961