Multipass Rendering

and related techniques


Different graphical elements can be drawn with separate projections.

A 2D overlay can be drawn using an orthographic projection, on top of a scene drawn with a perspective projection.

Disable the depth test for the 2D part.

2D overlays are used for such things as heads-up-displays, text information, lens flares, etc.



A 3D overlay can also be drawn - e.g. a 3D cockpit console in a flight simulator.

Depth buffering can cause objects from the main scene to hide parts of the overlay.
But disabling depth buffering can cause the overlay to be rendered incorrectly.

Avoid this by clearing just the depth buffer before drawing the overlay.


Multiple Views

Multiple projections can also be used for multiple views of a scene.

Different views typically occupy different regions of the screen.

This is accomplished using viewports.
In OpenGL, the "scissor test" is also needed.

Define the region of the window to use as follows:

    glViewport(x, y, width, height)
    glScissor(x, y, width, height)

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.

Important OpenGL functions that will be used are:


A mirror effect can be created by drawing the scene an extra time, scaled by -1 in one direction.

Things that may be needed:


Multipass Texturing

Multiple passes can be used to combine several different texture effects on a single object.

Each additional pass is blended with the previous pass.

+ =


Accumulation Buffer

A separate buffer that can be used to combine multiple renderings from the color buffer.

Allows for multipass techniques that would have problems due to depth-buffering or blending conflicts between the different passes.


Accumulation Buffer

Functions are:

Clear the accumulation buffer

glAccum(GL_ACCUM, factor)
Add frame buffer to accumulation buffer. Contents of color buffer are multiplied by factor.

glAccum(GL_RETURN, factor)
Copy contents of accumulation buffer back to color buffer. Contents are multiplied by factor.

Accumulation buffer is typically 16 bits per component, as compared to 8 bits per component for the color buffer.

Motion Blur

Motion blur is simulated by rendering several frames, with objects moved between each rendering, and adding the results together.

The update function for moving objects may need to be modified, to move them by "sub-frame" amounts.

Example: motionblur.cpp

Textures from Frame Buffer

Normally, a texture is defined using data in main memory - an image that was read from a file, or created algorithmically.

It is also possible to take image data from the frame buffer and load it into a texture.

glCopyTexImage2D(GL_TEXTURE_2D, 0,
                 GL_RGB, x, y,
                 width, height, 0)

copies data from part of the frame buffer into the active texture.