- Home /
Depth Masking of sprites.
http://wiki.unity3d.com/index.php?title=DepthMask
Does this tech work for sprites?
Implemented, but no matter which render queue value I set for masking rectangle it masks all sprites. Is DepthMasking suitable for sprites any how?
Answer by gfoot · Jan 06, 2014 at 07:35 PM
Try setting the sorting layer of the renderer you're using to render the depth only geometry, in the same way that you'd use it to control which sprites render on to of each other. The catch is that unity doesn't currently expose this in the inspector, so you need to use a custom editor class or explicit code to set the value you want in Start for example.
Also note that you ought to be able to use a SpriteRenderer for this if you change the material to use a depth-only shader, and this might be more comfortable.
Yes I found how it should work. Depth$$anonymous$$ask shader "Queue" parameter should be changed to "Transparent" and all that SetRenderQueue magic is not need, rendering order should be set with sorting layers as you said.
$$anonymous$$eshRenderer with custom editor is ok
:| and that moment when I realized that Depth$$anonymous$$asking would not work for my task after implementing it.
I haven't been able to find a depth only shader that isn't fixed function and therefor incompatible with with SpriteRenderer. The depthmask shader in the wiki linked doesn't work.
While it complains it is fixed function it actually works. Ok, not the version from wiki. it should be fixed. Here is $$anonymous$$e Depth$$anonymous$$askShader
Shader "Custom/$$anonymous$$ask" {
SubShader {
// Render the mask after regular geometry, but before masked geometry and
// transparent things.
Tags {"Queue" = "Transparent" }
// Don't draw in the RGBA channels; just the depth buffer
Color$$anonymous$$ask 0
ZWrite On
// Do nothing specific in the pass:
Pass {
}
}
}
The difference is that rendering order is set not by "Queue" but by SpriteRenderers layer and layer order.
Answer by Keyjin · Apr 28, 2014 at 08:44 PM
hey i have the problem that my DepthMask doesn't work can anyone give me please a example?
EDIT: get it by myself
Shader "Sprites/SubstractClipping"{
Properties{
_MainTex ("Base (RGB), Alpha (A)", 2D) = "white" {}
}
SubShader{
Tags{"Queue" = "Transparent"}
Pass{
ZWrite on
Offset -1, -1
ColorMask 0
Blend SrcAlpha OneMinusSrcAlpha
}
}
}
this works fine
Answer by Heikki-Hiltunen · Dec 28, 2016 at 04:18 PM
I'm working on a game mixing sprite characters with 3D backgrounds. I've succesfully used the depth mask shader to punch window "holes" etc. to the wall behind the characters. But is it possible for the sprite characters to pass through these kinds of "holes" (for example if I wanted to make a door in a side wall)? I hadn't got that working. Works fine with mesh objects though. Is this because sprite renderer does not write to the depth buffer at all?
Your answer
Follow this Question
Related Questions
Sprite color invert 1 Answer
Zelda Lens of Truth effect in a 2D game with sprites 1 Answer
Flipping a 2D Sprite in Javascript 0 Answers