I’m looking to improve my portal code. I need a way to clear the depth buffer, but only for those areas enabled by the stencil. Doing a
clear() operation won’t work, because clear doesn’t respect the stencil test.
What I’ve read online suggests that the way to do this is to render a quad that covers the viewport, with depth write enabled unconditionally and color write disabled. However, what I am unclear on is the best way to arrange the geometry of that quad in thew world such that the generated depth values correspond to the “cleared” state of the depth buffer, or something close to it. Would it be better to create a new ortho camera for this and render the quad in 2D, or try to place the quad in the 3D scene somehow, but very far away from the camera? Both of these approaches seem rather complex.