next up previous contents
Next: 8.5 Blending Transitions Up: 8. Blending and Compositing Previous: 8.3 Painting

8.4 Blending with the Accumulation Buffer

The accumulation buffer is designed for combining multiple images. Instead of simply replacing pixel values with incoming pixel fragments, the fragments are scaled and then added to the existing pixel value. In order to maintain accuracy over many 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 2.


 
Table: glAccum() Operations
Operation Action
GL_ACCUM read from selected buffer, scale by value, then add into accumulation buffer
GL_LOAD read from selected buffer, scale by value, then use image to replace contents of accumulation buffer
GL_RETURN scale image by value, then copy into buffers selected for writing
GL_ADD add value to R, G, B, and A components of every pixel in accumulation buffer
GL_MULT clamp value to range -1 to 1, then scale R, G, B, and A components of every pixel in accumulation buffer.
 

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.

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.

The accumulation buffer provides a way to take ``multiple exposures'' of a scene, while maintaining good color resolution. There are a number of image effects that can be implemented with the accumulation buffer to improve the realism of a rendered image [43,70], including antialiasing, motion blur, soft shadows, and depth of field. To create these effects, render the image multiple times, making small, incremental changes to the scene position (or selected objects within the scene), and accumulate the results.


next up previous contents
Next: 8.5 Blending Transitions Up: 8. Blending and Compositing Previous: 8.3 Painting
David Blythe
1999-08-06