Version: 2019.4
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 renderingThe process of drawing graphics to the screen (or to a render texture). By default, the main camera in Unity renders its view to the screen. More info
See in Glossary
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 bufferA memory store that holds an 8-bit per-pixel value. In Unity, you can use a stencil buffer to flag pixels, and then only render to pixels that pass the stencil operation. More info
See in Glossary
without writing to the render target.

Render pipeline compatibility

Feature name Built-in Render Pipeline Universal Render Pipeline (URP) High Definition Render Pipeline (HDRP) Custom SRP
ColorMask Yes Yes Yes Yes

Usage

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

Parameter Value Function
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.

Examples

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