glColorMask and glDepthMask determine which parts of the frame buffer are actually written to.
The idea of ​​an early Z-clipping is to first display only part of the depth buffer - the actual savings come from sorting the geometry near far so that the GPU can quickly discard occluded fragments. However, when drawing a Z-buffer, you do not want to draw a color component: this allows you to switch shaders, texturing, i.e. In short, everything is computationally intensive.
A word of warning: Early Z only works with opaque geometry . In fact, the entire depth buffer algorithm only works for opaque material. Once you mix, you will have to sort far close and not use depth buffering (search for “order-independent transparency” for algorithms to fix related problems).
S, if you have something that has been mixed, remove it from the “early Z” stage.
In the first pass you set
glDepthMask(1); // enable depth buffer writes glColorMask(0,0,0); // disable color buffer writes glDepthFunc(GL_LESS); // use normal depth oder testing glEnable(GL_DEPTH_TEST); // and we want to perform depth tests
After completing the Z-transition, you will change the settings
glDepthMask(0);
GL_LEQUAL does the job, but also allows fragments even closer than in the depth buffer. But since updating the depth buffer does not happen, everything that happens between the source and the stored depth will overwrite it every time something is drawn there.
A small theme change is to use the “early Z” depth buffer as a geometry buffer in several deferred dimming then.
To save additional geometry, check out Occlusive Queries . With occlusal requests, you ask the GPU how much if any fragments pass all the tests. It's like a voxel engine, you probably use octree or Kd tree. Drawing spatial separation faces (with glDepthMask (0), glColorMask (0,0,0)) of the tree branches before the branch intersects tells you if any geometry in this branch is visible at all. This, combined with near and far sorted bypass and (coarse) truncation on the tree, will give you huge performance benefits.