Shader that renders only pixels that arent hidden by other pixels on Z axis (mask particle system behind sprite)

I have a scene with 2 sprites, first sprite has z = 10, second sprite has z = 20, between them i have a particle system at z = 15. (part of first sprite overlaps part of second sprite) I managed to make a sprite shader that renders sprites in right order depending on Z axis (using default sprite shader and turning on “ZWrite On” and “ZTest Always”), but problem is to put particles systems between them.

In my understanding (very low knowledge and experience in shaders) i need to check if there is a pixel rendered at z = 10, and if there is discard pixel from particle system, if there is no pixles rendered at z = 10 then render pixel from particle system?

Using sorting layers is not an option, because my scene will have over 40 sprites in 40 different order in layer, and if i have 20 particles between them it will make 80 SetPass calls. I want to make 2 pass render, first pass to render all sprites, and then particles but cut out parts of particles that are behind sprites that are in front of it.

Is it even possible, so I know to keep trying?
Thanks in advance.

If someone ends up here in this post here is workaround that did job for me…

I placed particles in front of everything (closes to camera), and in front of particles placed a 2D plane mesh that had shape of object that supposed to be in front of particles.

Mesh has this shader:

Shader "Mobile/PanelMask" 
{ 
SubShader 
{
Tags { "Queue" = "Transparent-1" } 
ColorMask 0 
ZWrite Off

	   Pass{
            Stencil {
                Ref 1  
                Pass replace
            }
        }
    }
}

While particle shader have:

Stencil {
    Ref 0
    Comp equal
    Pass Replace
}

So mesh is masking particles and effect is like particles are behind object, where I need them to be. Mesh is created from PolygonCollider2D, for easy and fast creation.