Skip to main content

How to combine depth and sencilstencil tests?

Source Link

How to combine depth and sencil tests?

I have a continuous height-mapped mesh to represent landscape. I use the stencil test to create holes in the mesh. I draw holes to the stencil buffer and then use it to discard mesh fragments. Everything works fine except that my holes are visible through the mesh even if they are occluded by higher ground.

enter image description here

Is there any way to apply depth testing to a hole, keeping my mesh drawn in a single call to glDrawElements?