custom shader transparency problem

Hey folks…
I’m playing with the structured buffer shaders. Cool stuff, but I can’t get something to work…

Here is a simple shader that draws multiple squares at different positions.

Shader "Custom/TestShader" {
    Properties {
        _Color ("Color", Color) = (1,1,1,1)

    }
    SubShader {
        
           Blend SrcAlpha OneMinusSrcAlpha
        Cull Off

     Pass {
        CGPROGRAM

        #pragma vertex vert
        #pragma fragment frag

        #include "UnityCG.cginc"

        StructuredBuffer<float> buffer;

        float4 _Color;

        struct ps_input {
          float4 pos : SV_POSITION;
          float4 col : COLOR0;
        };

           ps_input vert(uint id : SV_VertexID, uint inst : SV_InstanceID) {
           
          ps_input o;

          float3 worldPos = float3(buffer[inst],buffer[inst],0);

          [branch] switch (id) {
              case 0: worldPos = worldPos + float3(-0.5,-0.5,0); break;
              case 1: worldPos = worldPos + float3(-0.5,0.5,0); break;
              case 2: worldPos = worldPos + float3(0.5,-0.5,0); break;

              case 3: worldPos = worldPos + float3(-0.5,0.5,0); break;
              case 4: worldPos = worldPos + float3(0.5,0.5,0); break;
              case 5: worldPos = worldPos + float3(0.5,-0.5,0); break;        
          };

         o.pos = mul(UNITY_MATRIX_VP, float4(worldPos, 1.0f));
         o.col = _Color;
            return o;

        }

        // Pixel function returns a solid color for each point.
        float4 frag(ps_input i) : COLOR{
                return i.col;
        }

        ENDCG
      }
        }

        FallBack Off
}

If I place an (semi-transparent)object in front of this squares, the squares are always visible at its full color.
Squares don’t get dimmed. I have my Render Queues set correctly.

Does anybody have any suggestions?

Thanks…

The Blend and Cull states actually should go inside the Pass block.

Yes. But it doesn’t make a difference.
I’m guessing that it has something to do with the fact, that vertices and their distance to camera, are calculated inside the shader - at rendering time.

Call for rendering is in the OnRenderObject() function.

If anybody else has same issue, I’ve found the way to fix it.

OnRenderObject() is called after all camera rendering, so objects will always be drawn on top of the other objects.
The way to fix it is to use
Graphics.DrawMeshInstancedIndirect
There is a nice example on Unity - Scripting API: Graphics.DrawMeshInstancedIndirect