early depth rendering

Started by
7 comments, last by nts 17 years, 9 months ago
Hello, i read a lot of papers about performance tips using opengl, and "early depth rendering" is talked by in almost all of them. I searched on the google without significant result. Could anybody explain me how to realize early depth rendering? I have several rendering stages: - water - shadow - normal rendering - and a rendering for blur effect i hope i can use this to avoid innecessary depth writing. thanks...
Advertisement
Usually refers to filling the depth buffer as a prepass (no color writes), then setting depth testing to equal and only writing to the color buffer. The technique is mostly used if you have a lot of overdraw (Doom 3 uses it).

Basically to enable/disable color writing you would use glColorMask. To enable/disable depth writing you would use glDepthMask. To set the depth compare mode you would use glDepthFunc.

Basic Process...
// Disable Color WritesglColorMask(FALSE, FALSE, FALSE); // Draw Scene to depth buffer onlyRenderSceneZ(); // Enable Color WritesglColorMask(TRUE, TRUE, TRUE); // Disable Depth WritesglDepthMask(FALSE); // Set Depth Function (only same depth passes)glDepthFunc(GL_EQUAL); // Draw Scene againRenderSceneColor();


Hope that helps

Thanks a lot!

one other question: can i use the depth values when i draw water (scaling with -1 in y direction) ?
Quote:Original post by fazekaim
Thanks a lot!

one other question: can i use the depth values when i draw water (scaling with -1 in y direction) ?


You mean flip the scene to render the reflect/refract texture? You can't reuse the depth in that case since it would no longer be valid (not sure how you would access it anyway).

As I said the technique is useful when you have a lot of overdraw. I think Doom 3 had up to 6 passes of overdraw.

why do u render the depth and the color split from each other ?
Quote:Original post by Anonymous Poster
why do u render the depth and the color split from each other ?
So that you only do the possibly expensive color calculations (texturing, lighting, etc) for pixels that are visible (have the same depth as what's in the depth buffer), hence reducing overdraw and using less fillrate. Note however that this only works with opaque objects; you will still need to render transparent objects from back-to-front and with depth-writing turned off after this (and with GL_LESS or GL_LEQUAL depth function instead of GL_EQUAL).
Thanks guys!

Is there any available tutorial about this?

My render process:
- render scene for water, flipped scene
- render scene for shadows, using special projection matrix and color mask is false
- render scene for the screen
- render scene for a kind of blur effect

i thought to able to make the rendering faster using early depth rendering...
Could be used this to improve those engines that perform complex pixel shaders? I heard that shaders do pixel rejection late after most of the code has already been executed, so loosing the main benefits of doing a first z-only pass...
Quote:Original post by cignox1
Could be used this to improve those engines that perform complex pixel shaders? I heard that shaders do pixel rejection late after most of the code has already been executed, so loosing the main benefits of doing a first z-only pass...


If the shader does not modify the fragment depth then an early depth test is done before the shader is even executed.

This topic is closed to new replies.

Advertisement