赞
踩
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.
在所有着色器执行完毕,所有纹理都被应用,所有像素准备被呈现到屏幕之后, 使用Blend命令来操作这些像素进行混合。
指导:
Blend 混合是将源色和目标色以某种方式混合生成特效的技术。混合常用来绘制透明或半透明的物体。在混合中起关键作用的α值实际上是将源色和目标色按给定比率进行混合,以达到不同程度的透明。α值为0则完全透明,α值为1则完全不透明。混合操作只能在RGBA模式下进行,颜色索引模式下无法指定α值。物体的绘制顺序会影响到OpenGL的混合处理。
参考文章:http://hi.baidu.com/ÖÙÁÁÁÁ/blog/item/5fc565445e19714a500ffebb.html
All following properties are valid for both SrcFactor & DstFactor. Source refers to the calculated color, Destination is the color already on the screen.
下面列出的所有属性是对SrcFactor & DstFactor有效。Source 是指计算出的颜色,Destination 指的是已经的屏幕上的颜色。
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 alpha混合 Blend One One // Additive 相加混合 Blend One OneMinusDstColor // Soft Additive 柔和相加混合 Blend DstColor Zero // Multiplicative 相乘混合 Blend DstColor SrcColor // 2x Multiplicative 2倍相乘混合
Here is a small example shader that adds a texture to whatever is on the screen already:
这里是1个着色器的小例子:将一个纹理添加到屏幕上,无论它是否已经在屏幕上。
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个更复杂的着色器:玻璃。它含有2个pass
The second pass renders a reflection cubemap on top of the alpha-blended window, using additive transparency.
第二个pass渲染一个反射立方体贴图在alpha混合得视窗的顶部,使用附加的透明度。
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] } } } }
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。