Multipass Rendering

The techniques generally referred to as multipass rendering involve rendering objects (or an entire scene) multiple times, each time with different OpenGL settings.

The purpose is to achieve effects that are not normally possible in just a single rendering of a scene.

The important OpenGL functions that will be used are:





Multipass Transparency

We first saw an example of multipass rendering in Class 8, when dealing with drawing-order issues in transparency.

By rendering the transparent objects twice, with different glCullFace settings, we could blend the backs and fronts of the objects properly.

Example: drawbacks.cpp





If only the very front layer of a transparent object is needed, another technique can be used.

This technique eliminates the errors in complex objects (like the teapot), where the drawing order cannot be easily controlled.

We draw the object twice. The first time only updates the depth buffer, in order to find the very front polygons. The second pass draws color, but will only draw the front polygons - those that match whatever is in the depth buffer.

Example: transparency.cpp

        glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE);

disables writing to the color buffer - only depth information will be written.

        glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);

re-enables writing to the color buffer.

        glDepthFunc(GL_EQUAL);

tells the depth-buffering algorithm to only draw a point ("fragment") if its depth is the same as what's already in the depth buffer.

        glDepthFunc(GL_LESS);

is the default depth-buffering mode. In this case, a fragment is only drawn if it is closer to the viewer than what's already in the depth buffer.



This method relies on the object geometry being exactly the same in both passes, so that the depth information will come out the same.



next