Is it possible to display only the objects behind a given object in proper order

Hi,

Say, I have a quad and I want to display only the objects behind the quad with their default depth.
What I can do is render the quad invisible and then use ZTest set to greater than and then only the objects behind the quad will be visible, but they will be drawn in reverse order (because of the greater than depth test).
Is there a was I can have them drawn with the normal ztest, but still be only drawn if their depth is greater than the depth of the quad?

As a workaround, I use the depth mask shader (applied to a big plane with a square hole in it) and I modify the projection matrix of the camera to move the near clip plane so that the objects infront of the ‘quad’ are culled.
This though has imprecision errors.
Is there some sort of ingenious and efficient way to draw only the objects behind the quad, but with less than ztest?

yes, looks like it.
Could you please upload the package. I hope it would fit my needs, but even if it doesn’t someone else might find it useful.
Thanks a lot.

thank you very much sir. This is exactly what I wanted. I am only worried it might be too expensive performance wise for my case, but hopefully it won’t be.

in the spirit of making the forums a better place, I want to point out that this implementation has precision problems when the masking object is far far away from the camera. Otherwise it works beautifully. I think this could be overcome using render depth functionality.

and in the spirit of making unity documentation a better place, the depth shader here has not been updated with unity 3