Get an 20% OFF using the RELEASE code on your book purchase. For a limited time.

Introduction to the shader programming language

3.1.9. SubShader ColorMask

This post is also available in…

This command allows our GPU to limit itself to writing a selected color channel and is compatible with both Built-in RP and Scriptable RP. 

When we create a shader, by default the GPU writes all channels corresponding to the color (RGBA), however, in some cases, we may want to show only some color channels (e.g. red channel or “R” of an effect).

ColorMask R         // our object will look red.
ColorMask G         // our object will look green.
ColorMask B         // our object will look blue.
ColorMask A         // our object will be affected by transparency. 
ColorMask RG        // we can use two channel mixing.

As we already know, the acronym RGBA stands for Red, Green, Blue and Alpha, therefore, if we configure our mask with the value “G” we will only show the green channel as color output. This ShaderLab command is very simple to use, and we can utilize it in both the SubShader and the Pass. 

Its syntax is as follows:

Shader “InspectorPath / shaderName”
{
    Properties {} ...
    SubShader
    {
        Tags { "Queue" = "Geometry”} 
        ColorMask RGB
    }
}

Follow us to stay informed about all the latest news, updates, and more.

Join the group to share your experiences with other developers.

Subscribe to our channel and keep learning game dev!

jettelly-logo

Jettelly Team

We are a team of indie developers with more than 9 years of experience in video games. As an independent studio, we have developed Nom Noms in which we published with Hyperbeard in 2019. We are currently developing The Unity Shader Bible.

Follow us on our social networks.