Blend 命令可确定 GPU 如何将片元着色器的输出与渲染目标进行合并。
此命令的功能取决于混合操作,您可以使用 BlendOp 命令进行设置。请注意,虽然所有图形 API 和硬件都支持混合功能,但对某些混合操作的支持较为有限。
启用混合会禁用 GPU 上的一些优化(主要是删除隐藏的表面/Early-Z),这些优化会增加 GPU 帧时间。
以下是最常见的混合类型的语法:
Blend SrcAlpha OneMinusSrcAlpha // Traditional transparency
Blend One OneMinusSrcAlpha // Premultiplied transparency
Blend One One // Additive
Blend OneMinusDstColor One // Soft additive
Blend DstColor Zero // Multiplicative
Blend DstColor SrcColor // 2x multiplicative
Shader "Examples/CommandExample"
{
SubShader
{
// The rest of the code that defines the SubShader goes here.
Pass
{
// Enable regular alpha blending for this Pass
Blend SrcAlpha OneMinusSrcAlpha
// The rest of the code that defines the Pass goes here.
}
}
}
此示例代码演示在 SubShader 代码块中使用此命令的语法。
Shader "Examples/CommandExample"
{
SubShader
{
// Enable regular alpha blending for this SubShader
Blend SrcAlpha OneMinusSrcAlpha
// The rest of the code that defines the SubShader goes here.
Pass
{
// The rest of the code that defines the Pass goes here.
}
}
}