[osg-users] How do I access the Z-Buffer content from the last render pass

Jean-Sébastien Guay jean-sebastien.guay at cm-labs.com
Mon Mar 9 06:58:43 PDT 2009

Hi Robert,

> You'll need to render the scene to a FBO with texture attached to as
> the depth buffer, then reuse this texture in the second pass.

Just to add specifics to Daniel's question, in case the approach is not 
right and you can suggest something else.

We want to render something in screen space (from a previous offscreen 
render pass) onto a screen-aligned quad over the results of the main 
render pass (the scene), and we know the depth of every given pixel in 
the previous render pass. The desired effect is that even though the 
screen-aligned quad is close to the camera, a given pixel should not be 
rendered if its depth is greater than something else that's already in 
the frame buffer.

So yes, we could assign the main pass's depth render target to a texture 
and use that in the post-render pass, but would there be a better way?

Perhaps a better strategy would be to render the screen-aligned quad 
first, before the rest of the scene, setting the fragment depth to the 
appropriate value there? Then the main render pass would just do the 
normal z-buffer test using the value we set before, since we clear 
neither the color buffer nor the depth buffer between those two passes. 
Since the screen-aligned quad's contents don't (currently) have 
transparency, that would work.

Thanks in advance,

Jean-Sebastien Guay    jean-sebastien.guay at cm-labs.com

More information about the osg-users mailing list