Why my shader cannot do alpha blend correctly ?

As this image , cloud_1top and cloud_2top is at above of cloud_1bottom and cloud_2bottom, and they all use material with my shader assigned. While i adjust the view of scene, the alpha blending seems wrong in some angle. I guess the problem is at the render sequence and z-write, am i right ? And i m very appreciate if anyone can tell me how to fix the shader (code at last)

Shader "MC/Unlit-AlphaColor" {
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 100
   
    ZWrite On
    Blend SrcAlpha OneMinusSrcAlpha
   
    Pass { 
        CGPROGRAM
            #pragma vertex vert
            #pragma fragment frag
           
            #include "UnityCG.cginc"

            struct appdata_t {
                float4 vertex : POSITION;
                float2 texcoord : TEXCOORD0;
            };

            struct v2f {
                float4 vertex : SV_POSITION;
                half2 texcoord : TEXCOORD0;
            };

            sampler2D _MainTex;
            float4 _MainTex_ST;
            fixed4 _Color;
           
            v2f vert (appdata_t v)
            {
                v2f o;
                o.vertex = UnityObjectToClipPos(v.vertex);
                o.texcoord = TRANSFORM_TEX(v.texcoord, _MainTex);
                return o;
            }
           
            fixed4 frag (v2f i) : SV_Target
            {
                fixed4 col = tex2D(_MainTex, i.texcoord) * _Color;
                //col.a = 0.1;
                return col;
            }
        ENDCG
    }
}

ZWrite Off

Thanks for reply ,but i have tried that and it didn’t work :frowning:

That’ll fix the issue in the screenshot you posted. If you’re taking about issues with sorting when not using ZWrite On, this is because this is an unsolved issue for efficient real time rendering.

I recently wrote a lot in this topic here:
https://forum.unity.com/threads/srp-transparent-sorting-bug.540740/

Short version, there’s not really anything you can do in the shader. The best solution is to manually sort the quads yourself in some way.

2 Likes

Thanks very much for the suggestion !
I found that the built-in shader Particles/Alpha Blended and Particles/VertexLit Blended can solve this perfectly , but idk why :stuck_out_tongue: May be it used OIT ?

"Unity’s perspective depth sorting is purely* based on distance to per mesh bounds centers, and orthographic depth sorting is purely based on bounds center depth (distance along the view axis). "

https://forum.unity.com/threads/srp-transparent-sorting-bug.540740/
when i learn the topic bgolus recommend , i 'm aware of this quote. I think it explains reason why the bug occurs while my view angle changing.