Reference Manual>Shader Reference>ShaderLab syntax: Shader>ShaderLab syntax: SubShader>ShaderLab syntax: Pass>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.
All following properties are valid for both SrcFactor & DstFactor. Source refers to the calculated color, Destination is the color already on the screen.
One | The value of one - use this to let either the source or the destination color come through fully. |
Zero | The value zero - use this to remove either the source or the destination values. |
SrcColor | The value of this stage is multiplied by the source color value. |
SrcAlpha | The value of this stage is multiplied by the source alpha value. |
DstColor | The value of this stage is multiplied by frame buffer source color value. |
DstAlpha | The value of this stage is multiplied by frame buffer source alpha value. |
OneMinusSrcColor | The value of this stage is multiplied by (1 - source color). |
OneMinusSrcAlpha | The value of this stage is multiplied by (1 - source alpha). |
OneMinusDstColor | The value of this stage is multiplied by (1 - destination color). |
OneMinusDstAlpha | The value of this stage is multiplied by (1 - destination alpha). |
Below are the most common blend types:
Blend SrcAlpha OneMinusSrcAlpha // Alpha blending Blend One One // Additive Blend OneMinusDstColor One // Soft Additive Blend DstColor Zero // Multiplicative Blend DstColor SrcColor // 2x Multiplicative
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:
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] } } } }
Page last updated: 2012-05-31