Question about multi-pass rendering and the depth buffer.

Hi there.

How would you go about doing multi pass rendering in OpenGL for a basic
terrain engine. From what I hear, Quake III does all it’s own fog code
simply because GL_FOG compliance cannot be guaranteed on all cards. This involves doing multipass
rendering over a textured surface.

I’m sure programs that use multi pass rendering draw a textured poly and
then draw another poly (this time a flat shaded poly who’s colour matches
the fog colour and who’s opacity varies with distance) over the top of the
old one.

Can this be done whilst still using the OpenGL depth buffer?

If one draws the entire landscape and then draws it again but flat shaded
with varying opacity I imagine the depth buffer will go super glitchy as it
tries to decide which poly is on top of which.

I thought about going through every polygon in the terrain, drawing a
textured poly, turning off the depth buffer, drawing a fog coloured poly
over the top, turning the depth buffer back on and moving onto the next poly
but I think that the method would be slow, not to mention the fact that it
may not work at all.

Any thoughts, or even URLs for that matter?

Regards,
Nick

If you draw the exact same poly twice (I mean same coordinates, same modelview matrix and same projection matrix), the depth component of the fragments generated will be EXACTLY the same.

What you can do then is :

1 - Enable Depth Buffer / Disable Blending
2 - Set Depth Func to GL_LEQUAL
3 - Render your terrain
4 - Enable Blending
5 - Render your terrain with special colours.

Regards.

Eric

I forgot to mention that for fog, you can use GL_EXT_fog_coord ; this extension enables you to specify the amount of fog per vertex (like glColor3f(r,g,b) but here you use glFogCoordf(f)).

Then, you do not need your second pass !

Regards.

Eric

Thankyou!

I shall code this up tonight.

Thanks again.

On the second pass, make sure to set the DepthFunc to GL_EQUAL and the DepthMask to FALSE.

  • Matt