- Home /
Alpha blending with more than one pass
I'm trying to create a shader which renders different parts of an object with different alpha depending on object coordinates. The following shader works, as long as I have only one pass (result not very good) but fails (no blending with background) when I have 2 passes:
This works:
Shader "Custom/Bugtest" {
Properties {
}
SubShader {
Tags { "RenderType"="Transparent" "IgnoreProjector"="True" "Queue" = "Transparent" }
LOD 200
ZWrite Off
Blend SrcAlpha OneMinusSrcAlpha
Cull off
CGPROGRAM
#pragma surface surf Lambert
#pragma target 3.0
#include "UnityCG.cginc"
struct Input {
float3 worldPos;
};
void surf (Input IN,inout SurfaceOutput o) {
float4 objpos = mul( _World2Object, float4(IN.worldPos,1.0) );
o.Albedo=float3(1,0.5,0.5);
if (objpos.x>0)
o.Alpha=0.25;
else
o.Alpha=1.0;
}
ENDCG
}
FallBack "Transparent/VertexLit"
}
But this not:
Shader "Custom/Bugtest" {
Properties {
}
SubShader {
Tags { "RenderType"="Transparent" "IgnoreProjector"="True" "Queue" = "Transparent" }
LOD 200
ZWrite Off
Blend SrcAlpha OneMinusSrcAlpha
Pass {
Cull front
}
Pass {
Cull back
}
CGPROGRAM
#pragma surface surf Lambert
#pragma target 3.0
#include "UnityCG.cginc"
struct Input {
float3 worldPos;
};
void surf (Input IN,inout SurfaceOutput o) {
float4 objpos = mul( _World2Object, float4(IN.worldPos,1.0) );
o.Albedo=float3(1,0.5,0.5);
if (objpos.x>0)
o.Alpha=0.25;
else
o.Alpha=1.0;
}
ENDCG
}
FallBack "Transparent/VertexLit"
}
Comment