目录索引
译文
有些类型的混合易于掌控,例如用 Alpha 通道加上透明效果的“SrcAlpha OneMinusSrcAlpha 混合”,但还有一些类型的混合无法为着色器生成透明度。在这种情况下,就需要使用到“透明度遮罩(AlphaToMask)”,它可以在 Alpha 通道上应用遮罩,是一种与内置渲染管线(Built-in)和可编程渲染管线(SRP)都兼容的技术。
与混合不同的是,混合可以生成不同级别的透明度(从 0.0f 到 1.0f 不等),而 AlphaToMask 只能生成整数(0或1),这意味着透明度遮罩是一种更苛刻的透明度类型。透明度遮罩在一些特定情况下很有用,例如植被和传送门效果。
- AlphaToMask On
- AlphaToMask Off 默认值(关闭状态)
我们可以在子着色器(SubShader)或 pass 语义块中使用这个命令,它只有开(On)或关(Off)两个值,通过如下方式进行声明:
Shader "InspectorPath/shaderName"
{
Properties { … }
SubShader
{
Tags { "RenderType"="Opaque" }
AlphaToMask On
}
}
和混合不一样的是,在开启了AlphaToMask的情况下,无需再添加 Transparency 标签或其他命令。我们只需要加上AlphaToMask命令,第四个通道“A”就会自动获得遮罩的属性。
原文对照
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.0f” to “1.0f”, 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 { "RenderType"="Opaque" }
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.
暂无评论内容