Shader to mask what is before it

Hi,

I’m trying to make a selection ‘mesh’.
To do that, I used the DepthMask available here : http://wiki.unity3d.com/index.php?title=DepthMask

Example : http://i.imgur.com/ccx9wUr.png

(I’m not using the set render queue script, I set the Custom Render Queue in the material myself using the Debug mode of the inspector).
My second element uses a simple Unlit/Color.

In the image : everything is good, but that’s because my units have the same Y position.

My issue is that when my units have different Y position, for example :

I believe the issue would be resolved if the shader also masks what is drawn in front of it.
I tried tweaking many values (ZTest, asn), tried to play with stencils, create a custom shader for the second element as-well and tweaking the values… Can’t find the solution :confused:

If any of you know how to achieve this, I would be grateful :slight_smile:

Sylafrs.

You can try to use Offset to “move” the object closer to camera in the depth buffer.
Also make sure your render queues are right, this page has the info about them. That wiki page about the depth mask uses wrong (outdated?) queue values.