next up previous contents
Next: 7 Antialiasing Up: 8.4 Blending Previous: 6.3 Painting

6.4 Blending with the Accumulation Buffer

The accumulation buffer is designed for integrating multiple images. Instead of simply replacing pixel values with incoming pixel fragments, the fragments are scaled, then added to the existing pixel value. In order to maintain accuracy over a number of blending operations, the accumulation buffer has a higher number of bits per color component than a typical color buffer.

The accumulation buffer can be cleared like any other buffer. You can use glClearAccum() to set the red, green, blue, and alpha components of its clear color. Clear the accumulation buffer by bitwise or'ing in the GL_ACCUM_BUFFER_BIT value to the parameter of the glClear() command.

You can't render directly into the accumulation buffer. Instead you render into a selected color buffer, then use glAccum() to accumulate that image into the accumulation buffer. The glAccum() command reads from the currently selected read buffer. You can set the buffer you want it to read from using the glReadBuffer() command.

The glAccum() command takes two arguments, op and value. The possible settings for op are described in Table reftab:accumop.

  table1083
Table: glAccum() op values

Since you must render to another buffer before accumulating, a typical approach to accumulating images is to render images to the back buffer some number of times, accumulating each image into the accumulation buffer. When the desired number of images have been accumulated, the contents of the accumulation buffer are copied into the back buffer, and the buffers are swapped. This way, only the final, accumulated image is displayed.

Here is an example procedure for accumulating n images:

  1. Call glDrawBufferGL_BACK(GL_BACK) to render to the back buffer only
  2. Call glReadBufferGL_BACK(GL_BACK) so that the accumulation buffer will read from the back buffer.

Note that the first two steps are only necessary if the application has changed the selected draw and read buffers. If the visual is double buffered, these settings are the default.



    2
  1. Clear the back buffer with glClear(), then render the first image
  2. Call glAccumGL_LOAD, 1.f/n(GL_LOAD, 1.f/n); this allows you to avoid a separate step to clear the accumulation buffer.
  3. Alter the parameters of your image, and re-render it
  4. Call glAccumGL_ACCUM,1.f/n(GL_ACCUM,1.f/n) to add the second image into the first.
  5. Repeat the previous two steps n - 2 more times...
  6. Call glAccumGL_RETURN, 1.f(GL_RETURN, 1.f) to copy the completed image into the back buffer
  7. Call glutSwapBuffers if your using GLUT, or whatever's appropriate to swap the front and back buffers.

The accumulation buffer provides a way to do ``multiple exposures'' in a scene, while maintaining good color resolution. There are a number of image effects that can be done using the accumulation buffer to improve the realism of a rendered image [21, 33]. They include antialiasing, motion blur, soft shadows, and depth of field. To create these effects, the image is rendered multiple times, making small, incremental changes to the scene position (or selected objects within the scene), and accumulating the results.


next up previous contents
Next: 7 Antialiasing Up: 8.4 Blending Previous: 6.3 Painting

David Blythe
Thu Jul 17 21:24:28 PDT 1997