赞
踩
1、Blend SrcAlpha OneMinusSrcAlpha 正常模式(透明度混合)
2、Blend OneMinusDstColor One 柔和相加(soft Additive)
3、Blend DstColor Zero 正片叠底 (Multiply)相乘
4、Blend DstColor SrcColor 两倍相乘 (2X Multiply)
5、 变暗
- BlendOp Min
- Blend One One
6、变亮
- BlendOp Max
- Blend One One
7、Blend OneMinusDstColor One 滤色,等同于Blend One OneMinusSrcColor
8、Blend One One 线性变淡
测试代码
- Shader "Wp/Blend"{
- Properties{
- _Color("Color", Color) = (1, 1, 1, 1)
- _MainTex("MainTex", 2D) = "White" {}
- _AlphaScale("AlphaScale", Range(0, 1)) = 1
- }
-
- SubShader{
- Tags{
- "Queue" = "Transparent"
- "Ignoreprojector" = "True"
- "RenderType" = "Transparent"
- }
- Pass{
- ZWrite off
- // Blend SrcAlpha OneMinusSrcAlpha
- // Blend OneMinusDstColor One
- // Blend DstColor Zero
- // Blend DstColor SrcColor
- // BlendOp Max
- // Blend One One
- // Blend OneMinusDstColor One
- Blend One One
-
- CGPROGRAM
-
- #pragma vertex vert
- #pragma fragment frag
-
- fixed4 _Color;
- sampler2D _MainTex;
- float4 _MainTex_ST;
- float _AlphaScale;
-
- struct a2v{
- float4 pos : POSITION;
- float4 normal : NORMAL;
- float texcoord : TEXCOORD0;
- };
-
- struct v2f{
- float4 pos : SV_POSITION;
- float3 worldNormal : TEXCOORD0;
- float3 worldPos : TEXCOORD1;
- float4 uv : TEXCOORD2;
- };
-
- v2f vert(a2v v){
- v2f o;
- o.pos = mul(UNITY_MATRIX_MVP, v.pos);
- return o;
- }
-
- fixed4 frag(v2f i) : SV_Target{
- return fixed4(_Color.rgb, _Color.a * _AlphaScale);
- }
-
- ENDCG
- }
- }
- Fallback "Diffuse"
- }
资源包下载:。。
混合操作(op)
1.Add :将混合后的源颜色(片元着色器产生的颜色值)和目标颜色(颜色缓冲区中读取到的值)相加。默认采用这种操作。等式为:
o=srcfactor*s+dstfactor*d ,举例:源颜色为(0,1,0,1)绿色,目标颜色为(1,0,0,1)红色,混合后为(1,1,0,2)黄色。
- Blend SrcAlpha One
- // finalColor = i.color * i.color.a + screenColor * (1)
- // (0,1,0,1) * 1 + (1,0,0,1) * 1 = (1,1,0,2)
2.Sub:
o=srcfactor*s-dstfactor*d
3.RevSub
o=dstfactor*d-srcfactor*s
4.Min
分别判断rgba四个分量的比较结果,混合因子不起作用
5.Max
分别判断rgba四个分量的比较结果,混合因子不起作用
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。