You have to use ZTest GEqual
in the shader of the masked object, not the mask itself. Also note that the depth mask and the masked objects have to be rendered before all other objects. So you should use the following render queues:
- Depth mask:
Geometry - 20
or2080
- Masked objects:
Geometry - 10
or2090
(A more detailed description of depth masks can be found in the Unity Wiki.)
You should also disable z-buffer writes for the masked objects (ZWrite Off
). This means that if the masked objects overlap, they won't render correctly. You'll probably also run into problems with the rest of the geometry. A better approach is to use stencil buffers which are available in the Pro version of Unity 4.2.