ShaderLab syntax: Blending

ShaderLab syntax: Blending

Blending is used to make transparent objects.


 

When graphics are rendered, after all shaders have executed and all textures have been applied, the pixels are written to the screen. How they are combined with what is already there is controlled by the Blend command.


Syntax

Blend Off
Turn off blending
Blend   SrcFactor   DstFactor
Configure & enable blending. The generated color is multiplied by the   SrcFactor. The color already on screen is multiplied by   DstFactorand the two are added together.
Blend   SrcFactor   DstFactor,   SrcFactorA   DstFactorA
Same as above, but use different factors for blending the alpha channel.
BlendOp   BlendOp
Instead of adding blended colors together, do a different operation on them.

Blend operations

The following blend operations can be used:


AddAdd source and destination together.
SubSubtract source from destination.
RevSubSubtract destination from source.
MinUse the smaller of source and destination.
MaxUse the larger of source and destination.
LogicalClearLogical operation: Clear (0) DX11.1 only.
LogicalSetLogical operation: Set (1) DX11.1 only.
LogicalCopyLogical operation: Copy (s) DX11.1 only.
LogicalCopyInvertedLogical operation: Copy inverted (!s) DX11.1 only.
LogicalNoopLogical operation: Noop (d) DX11.1 only.
LogicalInvertLogical operation: Invert (!d) DX11.1 only.
LogicalAndLogical operation: And (s & d) DX11.1 only.
LogicalNandLogical operation: Nand !(s & d) DX11.1 only.
LogicalOrLogical operation: Or (s | d) DX11.1 only.
LogicalNorLogical operation: Nor !(s | d) DX11.1 only.
LogicalXorLogical operation: Xor (s ^ d) DX11.1 only.
LogicalEquivLogical operation: Equivalence !(s ^ d) DX11.1 only.
LogicalAndReverseLogical operation: Reverse And (s & !d) DX11.1 only.
LogicalAndInvertedLogical operation: Inverted And (!s & d) DX11.1 only.
LogicalOrReverseLogical operation: Reverse Or (s | !d) DX11.1 only.
LogicalOrInvertedLogical operation: Inverted Or (!s | d) DX11.1 only.

Blend factors

All following properties are valid for both SrcFactor & DstFactor in the Blend command. Source refers to the calculated color, Destinationis the color already on the screen. The blend factors are ignored if BlendOp is using logical operations.


OneThe value of one - use this to let either the source or the destination color come through fully.
ZeroThe value zero - use this to remove either the source or the destination values.
SrcColorThe value of this stage is multiplied by the source color value.
SrcAlphaThe value of this stage is multiplied by the source alpha value.
DstColorThe value of this stage is multiplied by frame buffer source color value.
DstAlphaThe value of this stage is multiplied by frame buffer source alpha value.
OneMinusSrcColorThe value of this stage is multiplied by (1 - source color).
OneMinusSrcAlphaThe value of this stage is multiplied by (1 - source alpha).
OneMinusDstColorThe value of this stage is multiplied by (1 - destination color).
OneMinusDstAlphaThe value of this stage is multiplied by (1 - destination alpha).

Details

Below are the most common blend types:


Blend SrcAlpha OneMinusSrcAlpha // Alpha blendingBlend One One // AdditiveBlend OneMinusDstColor One // Soft AdditiveBlend DstColor Zero // MultiplicativeBlend DstColor SrcColor // 2x Multiplicative

Example

Here is a small example shader that adds a texture to whatever is on the screen already:


Shader "Simple Additive" { Properties { _MainTex ("Texture to blend", 2D) = "black" {} } SubShader { Tags { "Queue" = "Transparent" } Pass { Blend One One SetTexture [_MainTex] { combine texture } } }}

And a more complex one, Glass. This is a two-pass shader:

  1. The first pass renders a lit, alpha-blended texture on to the screen. The alpha channel decides the transparency.
  2. The second pass renders a reflection cubemap on top of the alpha-blended window, using additive transparency.

Shader "Glass" { Properties { _Color ("Main Color", Color) = (1,1,1,1) _MainTex ("Base (RGB) Transparency (A)", 2D) = "white" {} _Reflections ("Base (RGB) Gloss (A)", Cube) = "skybox" { TexGen CubeReflect } } SubShader { Tags { "Queue" = "Transparent" } Pass { Blend SrcAlpha OneMinusSrcAlpha Material { Diffuse [_Color] } Lighting On SetTexture [_MainTex] { combine texture * primary double, texture * primary } } Pass { Blend One One Material { Diffuse [_Color] } Lighting On SetTexture [_Reflections] { combine texture Matrix [_Reflection] } } }}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

警醒与鞭策

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值