Version: 2023.1
ShaderLab 命令:Blend
ShaderLab 命令:ColorMask

ShaderLab 命令:BlendOp

指定 Blend 命令使用的混合操作。要使该命令生效,在同一个 Pass 代码块(如果该命令在 Pass 代码块中)或 SubShader 代码块(如果该命令在 SubShader 代码块中)中还必须有一个 Blend 命令。

并非所有设备都支持所有混合操作,支持取决于图形 API 和硬件。对于不支持的混合操作,不同的图形 API 以不同的方式处理:GL 跳过不支持的操作,Vulkan 和 Metal 回退到 Add 操作。

渲染管线兼容性

功能名称 内置渲染管线 通用渲染管线 (URP) 高清渲染管线 (HDRP) 自定义 SRP
BlendOp 是 是 是 是

用法

此命令会更改渲染状态。在 Pass 代码块中使用它可为该通道设置渲染状态,或者在 SubShader 代码块中使用它可为该子着色器中的所有通道设置渲染状态。

签名 示例语法 功能
BlendOp <operation> BlendOp Sub 设置 Blend 命令使用的混合操作。

有效参数值

参数 值 功能
operation Add 将源和目标相加。
Sub 从源减去目标。
RevSub 从目标减去源。
Min Use the smaller of source and destination. (1)
Max Use the larger of source and destination. (1)
LogicalClear Logical operation: Clear (0) (1)
LogicalSet Logical operation: Set (1) (1)
LogicalCopy Logical operation: Copy (s) (1)
LogicalCopyInverted 逻辑操作:Copy inverted (!s) 2
LogicalNoop Logical operation: Noop (d) (1)
LogicalInvert Logical operation: Invert (!d) (1)
LogicalAnd Logical operation: And (s & d) (1)
LogicalNand Logical operation: Nand !(s & d) (1)
LogicalOr Logical operation: Or (s | d) (1)
LogicalNor Logical operation: Nor !(s | d) (1)
LogicalXor Logical operation: Xor (s ^ d) (1)
LogicalEquiv Logical operation: Equivalence !(s ^ d) (1)
LogicalAndReverse Logical operation: Reverse And (s & !d) (1)
LogicalAndInverted Logical operation: Inverted And (!s & d) (1)
LogicalOrReverse Logical operation: Reverse Or (s | !d) (1)
LogicalOrInverted Logical operation: Inverted Or (!s | d) (1)
Multiply Advanced OpenGL blending operation: Multiply (2)
Screen Advanced OpenGL blending operation: Screen (2)
Overlay Advanced OpenGL blending operation: Overlay (2)
Darken Advanced OpenGL blending operation: Darken (2)
Lighten Advanced OpenGL blending operation: Lighten (2)
ColorDodge Advanced OpenGL blending operation: ColorDodge (2)
ColorBurn Advanced OpenGL blending operation: ColorBurn (2)
HardLight Advanced OpenGL blending operation: HardLight (2)
SoftLight Advanced OpenGL blending operation: SoftLight (2)
Difference Advanced OpenGL blending operation: Difference (2)
Exclusion Advanced OpenGL blending operation: Exclusion (2)
HSLHue Advanced OpenGL blending operation: HSLHue (2)
HSLSaturation Advanced OpenGL blending operation: HSLSaturation (2)
HSLColor Advanced OpenGL blending operation: HSLColor (2)
HSLLuminosity Advanced OpenGL blending operation: HSLLuminosity (2)

注意:

  1. Logical operations require DX 11.1+ or Vulkan.
  2. Advanced OpenGL blending operations require GLES3.1 AEP+, GL_KHR_blend_equation_advanced, or GL_NV_blend_equation_advanced. They can only be used with standard RGBA blending; they are not compatible with separate RGB and alpha blending.

示例

Shader "Examples/CommandExample"
{
    SubShader
    {
         // 此处是定义子着色器的代码的其余部分。

        Pass
        {    
             // 为此通道启用减法混合
             Blend SrcAlpha One
             BlendOp RevSub
            
              // 此处是定义通道的代码的其余部分。
        }
    }
}

此示例代码演示在 SubShader 代码块中使用此命令的语法。

Shader "Examples/CommandExample"
{
    SubShader
    {
         // 为此子着色器启用减法混合
         Blend SrcAlpha One
         BlendOp RevSub

         // 此处是定义子着色器的代码的其余部分。

        Pass
        {    
              // 此处是定义通道的代码的其余部分。
        }
    }
}
ShaderLab 命令:Blend
ShaderLab 命令:ColorMask