Jump to content
  • Advertisement
Sign in to follow this  
fazekaim

OpenGL early depth rendering

This topic is 4429 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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...

Share this post


Link to post
Share on other sites
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 Writes
glColorMask(FALSE, FALSE, FALSE);

// Draw Scene to depth buffer only
RenderSceneZ();

// Enable Color Writes
glColorMask(TRUE, TRUE, TRUE);

// Disable Depth Writes
glDepthMask(FALSE);

// Set Depth Function (only same depth passes)
glDepthFunc(GL_EQUAL);

// Draw Scene again
RenderSceneColor();


Hope that helps

Share this post


Link to post
Share on other sites
Thanks a lot!

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

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
why do u render the depth and the color split from each other ?

Share this post


Link to post
Share on other sites
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).

Share this post


Link to post
Share on other sites
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...

Share this post


Link to post
Share on other sites
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...

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!