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 {} …
SubShader
{
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.