Models using transparent shader are overlapping themselves

Here’s two examples :
Opaque : https://i.imgur.com/iaRX57X.png
Transparent : https://i.imgur.com/4fUtHVE.png
Seen from up :
Opaque : https://i.imgur.com/Sw2itEw.png
Transparent : https://i.imgur.com/8O1Hv2y.png
I need to have a shader compatible with Sorting Layers since my game is a mix of 2D and 3D, that’s why I’m using the Standard transparent one

Any way to fix this issue ?

That’s a common issue and no easy / cheap solution. First of all you should enable zWrite in your shader which transparent shaders most the time do not do. However depending on your model and if you want to see self occluded parts or not. The triangle of a mesh are usually rendered in order as they are defined in the mesh. This order is never changed.

Any kind of sorting happens on a per object basis. If you want to prevent any self overlapping for transparent shaders you would need a two pass approach. First just drawing into the depth buffer, second pass just drawing into the color buffer. That way only the closest visible surface of an object will be drawn.

Just like explained in the example here for the semi transparent shader.

In case someone search for this question like I just did, add following code into your shader:

Blend SrcAlpha OneMinusSrcAlpha

            Stencil {
                 Ref 10
                 ReadMask 10
                 Comp NotEqual
                 Pass Replace
             }

I found adding this to the “Transparent/Diffuse ZWrite” shader worked for me, not in a separate pass. Not an expert with shaders but was delighted my transparent scorch marks on the ground did not overlap each other cutting the others out, now they overlap nicely and fade into eachother.

ZWrite On
ColorMask 0

This is the full shader:

Shader "Transparent/Diffuse ZWrite" {
    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
       
        ZWrite On
        ColorMask 0

        // paste in forward rendering passes from Transparent/Diffuse
        UsePass "Transparent/Diffuse/FORWARD"
    }
    Fallback "Transparent/VertexLit"
}