Hey,
Im new to shaders but Im trying to achieve a very simple ambient lit transparent shader. The problem I have is represented on the image bellow.
Either the transparent pixels make transparent objects on the background invisible, or back objects are rendered last, in front of front objects. My shader code is as follows:
Shader "Diffuse Ambient Lit Transparent" {
Properties {
_MainTex ("Base (RGB)", 2D) = "white" {}
}
SubShader {
Pass {
Tags { "RenderType" = "Transparent" "Queue" = "Transparent" "IgnoreProjector"="True"}
ZWrite Off
Blend SrcAlpha OneMinusSrcAlpha
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
sampler2D _MainTex;
fixed4 _MainTex_ST;
struct vertexInput {
float4 vertex : POSITION;
float4 texcoord0 : TEXCOORD0;
};
struct vertexOutput {
float4 pos : SV_POSITION;
fixed2 uv : TEXCOORD0;
};
vertexOutput vert(vertexInput v) {
vertexOutput o;
o.pos = mul(UNITY_MATRIX_MVP, v.vertex);
o.uv = v.texcoord0;
return o;
}
fixed4 frag (vertexOutput i) : COLOR {
fixed4 finalColor = tex2D(_MainTex, i.uv) * (UNITY_LIGHTMODEL_AMBIENT * 2);
return finalColor;
}
ENDCG
}
}
}
The difference between screenshots is only turning On or Off the ZWrite.
Anybody can give me a hand?
Thanks in advance,
Best regards,
Allan