- Home /
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 :
http://i.imgur.com/0A1xLFS.png
http://i.imgur.com/eHRNOSG.png
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 :/
If any of you know how to achieve this, I would be grateful :)
Sylafrs.
Answer by villevli · Aug 28, 2016 at 06:19 PM
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.
Okay, I've just tried with drastic values, and it seems to work :)
Offset 0, -100000
Thank you