Transparent and cutout shader in one.

I’m trying to create/find a shader where some transparent elements, placed on top of each other, will not mix together. The result should still be transparent, but the colors should not mix; only the top layer should contribute the color.

What techniques are available for this? I’m guessing the ordinary cutout shaders will kill all semi-transparency, and z-buffer isn’t available for transparent shaders anyway? Some sort of stencil buffer maybe? It needs to work in URP.

7983630--1025439--transparency.png

Before rendering transparent materials render top layer with fully transparent material but with z-write enabled.
This will cover all later transparent material that are inside.
Render all your transparent materials, but the topmost layer with z-test LEqual (this actually should be default)

And this won’t cut a hole in other transparent and opaque materials?

It will, this is why you do it after the opaque materials and before the transparent ones.

I found my way.
My shader is now based on the urp example and the stencil buffer:

It turned out the stencil buffer is perfect for my use case.