ShaderLab syntax: Blending
来源:互联网 发布:使用美团数据分析 编辑:程序博客网 时间:2024/05/29 13:42
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.
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:
- The first pass renders a lit, alpha-blended texture on to the screen. The alpha channel decides the transparency.
- 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] } } }}
- ShaderLab syntax: Blending
- ShaderLab: Blending
- ShaderLab Syntax
- ShaderLab Tutorials-Alpha Blending-1
- ShaderLab Tutorials-Alpha Blending-2
- 【Unity5.x Shdaers】ShaderLab: Blending 混合
- Shader Learing(ShaderLab syntax篇)
- Blending
- 混合 blending
- Image blending
- image blending
- Alpha Blending
- [UnityShader]Blending
- Color Blending
- Poisson Blending
- OpenGL Blending
- Alpha blending
- Unity-shaderLab
- SQLServer 存储过程
- TLD(Tracking-Learning-Detection)算法学习与源码解析(三)之 tld.cpp源码解析
- Linux kernel 性能优化(五)Linux虚拟内存优化
- 浅谈PB使用心得
- 两种实现线程的方法
- ShaderLab syntax: Blending
- 开张啦!
- ubuntu下安装mysql遇到的问题
- Ibatis调用oracle储存过程出现数据类型错误或参数个数错误
- 安卓错误E/AndroidRuntime(2726): java.lang.NullPointerException的问题解决
- MonoDevelop 实现中文支持
- 国内验证码广告
- eclipse更改默认工作路径
- 【学习】ListView中控制子控件的隐藏和显示