Use stencil buffer to hide objects with same shader?

Hey there, I’m very new to shaders,

I have two objects in my scene, both use the same shader to get a transparent affect.

What I want though is that when the two objects are overlapping, I want the top object to hide the object underneath it. So you can see through the first object and not see the second object at all underneath but still see the rest of the scene behind it.

Basically these are UI elements that I want to be able to overlap and hide one another, but still see the game scene behind them.

I’ve looked into depth mask and stencil buffers but it seems to always assume you are working with two different objects and shaders.

I’m using the Shader from this project here for the “blurry refractions” - Extending Unity 5 rendering pipeline: Command Buffers | Unity Blog

P.S. I modified the shader by adding a _Transparency prop and setting col.a = _Transparency in the frag function and Blend SrcAlpha OneMinusSrcAlpha so that I could see through alpha values in the PNGs for the UI, just in case that affects anything

I actually solved this after looking at lots of other solutions for similar tasks by doing the following -

instead of doing col.a = _Transparency

i did if (col.a < _Transparency) discard