Depth Buffer

Started by pdid, January 23, 2017, 23:01:04

Previous topic - Next topic

pdid

What is the difference between glEnable(GL_DEPTH_TEST) and glDepthMask(true)?

spasi

When GL_DEPTH_TEST is enabled, the depth of incoming fragments will be tested against the current depth in the framebuffer, using the function specified with glDepthFunc. Fragments will be discard or accepted based on that test.

When glDepthMask is set to true, any fragments that make it to the end of the rendering pipeline will update the framebuffer with their depth.

This is useful when doing a Z pre-pass. In the depth pass, GL_DEPTH_TEST is enabled, glDepthFunc is set to GL_LEQUAL (or GL_GEQUAL, depending on the setup) and glDepthMask is set to true. In the shading pass(es), GL_DEPTH_TEST is again enabled, glDepthFunc is set to GL_EQUAL and glDepthMask is set to false. Doing no depth writes in the shading pass(es) saves framebuffer bandwidth.

Kai

Just read the documentation of glEnable (search for GL_DEPTH_TEST) and of glDepthMask.
You can have the following constellations:
1. GL_DEPTH_TEST enabled and depth mask = true:
   - fragments are depth-tested and the depth is written to the depth buffer
2. GL_DEPTH_TEST enabled and depth mask = false:
   - fragments are depth-tested but the depth is NOT written to the depth buffer
   - this is the mode you would render transparent objects in after you've rendered opaque ones
3. GL_DEPTH_TEST disabled and depth mask = true:
   - Fragments are NOT being depth-tested and NEITHER written to the depth buffer
4. GL_DEPTH_TEST disabled and depth mask = false:
   - Same as 3.