《Unity着色器圣经》3.1.9 | SubShader颜色遮罩

目录索引

译文

颜色遮罩命令允许 GPU 只写入选定的颜色通道,兼容内置渲染管线(Built-in)和可编程渲染管线(SRP)。

当我们新建一个着色器时,GPU 默认写入颜色的所有通道(RGBA)。然而在某些情况下,我们可能只想显示其中一些通道(例如R通道)。

  • ColorMask R 我们的模型看起来将是红色的
  • ColorMask G 我们的模型看起来将是绿色的
  • ColorMask B 我们的模型看起来将是蓝色的
  • ColorMask A 我们的模型将会被透明度影响
  • ColorMask RG 我们可以混合使用两个通道

我们已经知道“RGBA”各字母分别是红(Red)、绿(Green)、蓝(Blue)和 Alpha 的简称,所以,如果我们把遮罩的值配置为“G”,我们就只会得到 G 通道上的颜色作为输出。这个ShaderLab命令简单好用,我们可以在SubShader或Pass语义块中使用它。

其语法如下所示:

Shader "InspectorPath/shaderName" 
{ 
    Properties { … } 
    SubShader 
    { 
        Tags { "Queue"="Geometry" } 
        ColorMask RGB 
    } 
}

原文对照

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 
    } 
}
© 版权声明
THE END
喜欢就支持一下吧
点赞0 分享
评论 抢沙发

请登录后发表评论

    暂无评论内容