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.