- Home /
Shaders: How to ztest against specific layers?
I made this shader to overlay a color when my player's mesh is hidden by other geometry in the scene:
SubShader
{
Tags { "Queue"="Overlay+1" }
Pass
{
ZWrite Off
ZTest Greater
Lighting Off
Cull off
Color [_ColorInvisible]
}
Pass
{
ZTest Less
Material {
Diffuse [_Color]
Ambient (0,0,0,0)
}
Lighting On
SeparateSpecular On
SetTexture [_MainTex] {combine texture * primary DOUBLE, texture * primary}
}
}
The shader is working great but I'm unable to make it work only with specific layers:
I would like to make the overlay only when my player (wich has the above shader applied) is behind objects on a specific layer (i.e Wall layer).
How can i achieve this?
Thanks in advance.
I've already seen this related question but it wasn't enough to help me solve my problem.
http://answers.unity3d.com/questions/298459/unity-shader-masking-a-specific-layer.html
Answer by zharik86 · Dec 18, 2014 at 08:20 PM
I think, you should set sequence of drawing of shaders: at first walls, then the player, further all that remained. For wall and some object use "Queue" = "Geometry" (default). For player change to "Queue" = "Geometry + 10". For all remained object use, for example, "Queue" = "Geometry + 100". For more information about Queue see docs. I hope that it will help you.
Your answer
Follow this Question
Related Questions
Mesh rendered wierdley without depth buffer 1 Answer
Problems with depth values in _CameraDepthTexture 4 Answers
Camera layering : UI shader is cleared by second camera with Depth Only flag 1 Answer
How to get Unity's DOF effect with custom shaders? 0 Answers
The meaning of the depth map value 1 Answer