您的位置:首页 > 移动开发 > Unity3D

Unity3d Shader开发(三)Pass(Blending )

2013-09-29 15:33 921 查看
混合被用于制作透明物体。



当图像被渲染时,所有着色器被执行以后,所有贴图被应用后,像素将被写到屏幕。他们是如何通过Blend命令的控制和已有的图像合并呢?

Syntax 语法

Blend OffTurn off blending 关闭混合Blend SrcFactor DstFactor配置并启动混合。产生的颜色被乘以SrcFactor. 已存在于屏幕的颜色乘以DstFactor,并且两者将被叠加在一起。Blend SrcFactor DstFactor, SrcFactorA DstFactorA同上,但是使用不同的要素来混合alpha通道BlendOp Min | Max | Sub | RevSub不是添加混合颜色在一起,而是对它们做不同的操作。

Properties 属性

以下所有属性对SrcFactor或DstFactor都可用。Source指的是被计算的颜色,Destination是已经在屏幕上的颜色。

OneThe value of one - use this to let either the source or the destination color come through fully.
值为1,使用此设置来让源或是目标颜色完全的通过。
ZeroThe value zero - use this to remove either the source or the destination values.
值为0,使用此设置来删除源或目标值。
SrcColorThe value of this stage is multiplied by the source color value.
此阶段的值是乘以源颜色的值。
SrcAlphaThe value of this stage is multiplied by the source alpha value.
此阶段的值是乘以源alpha的值。
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.
此阶段的值是乘以帧缓冲区源alpha的值。
OneMinusSrcColorThe value of this stage is multiplied by (1 - source color).
此阶段的值是乘以(1 - source color)
OneMinusSrcAlphaThe value of this stage is multiplied by (1 - source alpha).
此阶段的值是乘以(1 - source alpha)
OneMinusDstColorThe value of this stage is multiplied by (1 - destination color).
此阶段的值是乘以(1 - destination color)
OneMinusDstAlphaThe value of this stage is multiplied by (1 - destination alpha).
此阶段的值是乘以(1 - destination alpha)

Details 细节

Below are the most common blend types:

以下是最常见的混合类型:

BlendSrcAlphaOneMinusSrcAlpha//
Alpha blendingBlendOneOne//
AdditiveBlendOneOneMinusDstColor//
Soft AdditiveBlendDstColorZero//
MultiplicativeBlendDstColorSrcColor//
2x Multiplicative

这里是一个着色器的小例子,添加一个纹理,无论是否已在屏幕上:

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




  第一个pass渲染光照、alpha混合纹理到屏幕上。Alpha通道决定的透明度。

  第二个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]
}
}
}
}


内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: