在所有着色器执行完毕,所有纹理都被应用,所有像素准备被呈现到屏幕之后,使用Blend命令来操作这些像素进行混合。
3.2 blend的语法
BlendOff:关闭blend混合(默认值)
BlendSrcFactor DstFactor :配置并启动混合。产生的颜色被乘以SrcFactor. 已存在于屏幕的颜色乘以DstFactor,并且两者将被叠加在一起。
BlendSrcFactor DstFactor, SrcFactorA DstFactorA:同上,但是使用不同的要素来混合alpha通道
BlendOpBlendOpValue:不是添加混合颜色在一起,而是对它们做不同的操作。
BlendOpOpColor, OpAlpha:同上,但是使用不同的操作来处理alpha通道
AlphaToMaskOn:里面新添加的,常用在开启多重渲染(MSAA)的地表植被的渲染。
Unity中的混合因子(和OpenGL的差不多):
One | 值为1,使用此设置来让源或是目标颜色完全的通过。 |
Zero | 值为0,使用此设置来删除源或目标值。 |
SrcColor | 此阶段的值是乘以源颜色的值。 |
SrcAlpha | 此阶段的值是乘以源alpha的值。 |
DstColor | 此阶段的值是乘以帧缓冲区源颜色的值。 |
DstAlpha | 此阶段的值是乘以帧缓冲区源alpha的值。 |
OneMinusSrcColor | 此阶段的值是乘以(1 - source color) |
OneMinusSrcAlpha | 此阶段的值是乘以(1 - source alpha) |
OneMinusDstColor | 此阶段的值是乘以(1 - destination color) |
OneMinusDstAlpha | 此阶段的值是乘以(1 - destination alpha) |
混合的操作符(Blend operations)
Add | Add source and destination together. |
Sub | Subtract destination from source. |
RevSub | Subtract source from destination. |
Min | Use the smaller of source and destination. |
Max | Use the larger of source and destination. |
LogicalClear | Logical operation: Clear (0) DX11.1 only. |
LogicalSet | Logical operation: Set (1) DX11.1 only. |
LogicalCopy | Logical operation: Copy (s) DX11.1 only. |
LogicalCopyInverted | Logical operation: Copy inverted (!s) DX11.1 only. |
LogicalNoop | Logical operation: Noop (d) DX11.1 only. |
LogicalInvert | Logical operation: Invert (!d) DX11.1 only. |
LogicalAnd | Logical operation: And (s & d) DX11.1 only. |
LogicalNand | Logical operation: Nand !(s & d) DX11.1 only. |
LogicalOr | Logical operation: Or (s | d) DX11.1 only. |
LogicalNor | Logical operation: Nor !(s | d) DX11.1 only. |
LogicalXor | Logical operation: Xor (s ^ d) DX11.1 only. |
LogicalEquiv | Logical operation: Equivalence !(s ^ d) DX11.1 only. |
LogicalAndReverse | Logical operation: Reverse And (s & !d) DX11.1 only. |
LogicalAndInverted | Logical operation: Inverted And (!s & d) DX11.1 only. |
LogicalOrReverse | Logical operation: Reverse Or (s | !d) DX11.1 only. |
LogicalOrInverted | Logical operation: Inverted Or (!s | d) DX11.1 only |
下列是最经常使用的混合类型
Blend SrcAlpha OneMinusSrcAlpha // Alphablending alpha混合
Blend One One // Additive 相加混合
Blend One OneMinusDstColor // Soft Additive柔和相加混合
Blend DstColor Zero // Multiplicative 相乘混合
BlendDstColor SrcColor // 2x Multiplicative 2倍相乘混合