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

Introduction to the shader programming language

3.1.8. SubShader AlphaToMask

This post is also available in…

There are some types of Blending that are very easy to control, e.g., the “SrcAlpha OneMinusSrcAlpha Blend”, which adds a transparent effect with the Alpha channel included, but there are other cases where Blending is not capable of generating transparency for our shader. In this case, the “AlphaToMask” property is used which applies a mask over the Alpha channel and is a technique compatible with both Built-in RP and Scriptable RP. 

Unlike Blending, a mask can only assign the values “one or zero” to the Alpha channel, what does this mean? While the Blending can generate different levels of transparency; levels from “0.0” to “1.0”, AlphaToMask can only generate integers. This translates to a harsher type of transparency, which works in specific cases, e.g., it is very useful for vegetation in general and to create space portal effects.

  • AlphaToMask On.
  • AlphaToMask Off, default value.

To activate this command, we can declare it in both the SubShader field and the pass field. It only has two values: “On and Off”, and it is declared in the following way: 

Shader “InspectorPath / shaderName”
    Properties {} …
        Tags { "Queue" = "Transparent" “RenderType”=”Transparent”} 
        Blend OneMinusDstColor One    
        AlphaToMask On

It should be noted that, unlike Blending, in this case, it is not necessary to add Transparency tags or other commands. We just add AlphaToMask and automatically the fourth color channel “A” acquires the qualities of the mask in our program.

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