Alpha Diffuse Surface Shader issue

Hi!

I’m trying to build some custom shaders for my next title but I bumped into some problems.
As you can see on picture below:

top left: looks relatively fine

other pictures shows issues with sorting rendered mesh. (whole “ground” is a single mesh)

[12739-strange+effect.jpg|12739]

for makign screenshot I have used a bit modified shader:
Shader “Transparent/Diffuse” {
Properties {
_Color (“Main Color”, Color) = (1,1,1,1)
_MainTex (“Base (RGB) Trans (A)”, 2D) = “white” {}
}

SubShader {
	Tags {"Queue"="Transparent" "IgnoreProjector"="True" "RenderType"="Transparent"}
	LOD 200

CGPROGRAM
#pragma surface surf Lambert alpha

sampler2D _MainTex;
fixed4 _Color;

struct Input {
	float2 uv_MainTex;
};

void surf (Input IN, inout SurfaceOutput o) {
	fixed4 c = tex2D(_MainTex, IN.uv_MainTex) * _Color;
	o.Albedo = c.rgb;
	o.Alpha = c.a;
}
ENDCG
}

Fallback "Transparent/VertexLit"
}

Bud I get exactly same issue with native version of this shader (its default Alpha-Diffuse.shader avaliable with unity)

issue dissapears as soon as I use:

    #pragma surface surf Lambert

instead of

    #pragma surface surf Lambert alpha

but I simply need to be able use transparency in shader.

Any help would be much appreciated.

Thank you

Once you add “alpha” it disables writing into ZBuffer and then it can overdraw itself. I think in your case you don’t need alpha-blendting, but alpha-testing. There is a pragma for that: alphatest:VariableName (Unity - Manual: Writing Surface Shaders).