render order of transparent Surface shader is incorrect
Hello
I’m working on a project where I’m trying to emulate the N64 graphics. Therefore, I’ve been doing some shaders (I know more than just the basic, but I’m not an expert). Most of them takes the colors of the vertices and blend them with the texture (if there’s any).
I run into a problem when I’m doing a surface shader that is transparent. More specifically, the render order, of materials that use this shader, isn’t correct. I read a lot of documentation online and forum post, but either I can’t find the solution, or I did find it, but it was to complicated for me to figure out how to implement. Here is two picture that show this problem.
No problem from this point of view:
When I turn the camera and zoom, we can see the problem:
Finally, here is my shader code:
Shader "N64/TransparentFragmentLit"
{
Properties
{
_MainTex("Texture", 2D) = "white" {}
}
SubShader
{
Tags { "Queue" = "Transparent" "RenderType" = "Transparent" }
LOD 200
ZWrite On
Blend SrcAlpha OneMinusSrcAlpha
CGPROGRAM
#pragma surface surf Lambert vertex:vert alpha
#pragma target 3.0
sampler2D _MainTex;
struct Input {
fixed4 vertColor;
fixed2 uv_MainTex;
};
void vert(inout appdata_full v, out Input o)
{
// Initializes the variable name(o) of given type(Input) to zero.
UNITY_INITIALIZE_OUTPUT(Input, o);
o.vertColor = v.color;
}
void surf(Input IN, inout SurfaceOutput o)
{
fixed4 textColor = tex2D(_MainTex, IN.uv_MainTex);
o.Albedo = IN.vertColor.rgb * textColor.rgb;
o.Alpha = textColor.a;
}
ENDCG
}
FallBack "Diffuse"
}
Hope anyone can help me :)