Multi-Pass Rendering Algorithms
- Can render into multiple buffers or even the same buffers multiple times
- Can be hard to reason about because there is no direct way to see most of these buffers
- Requires allocating buffers at initialization of OpenGL to ensure they are available during program
- Basic operation is masking: determining whether an operation changes none, some, or all of the buffer
- Buffers are defined by
- Type of values they store
- Logical operations they support
- Way they are written and read
- Several interesting applications: mirrors, shadows, dynamic environment maps, antialiasing, blur effects
Color Buffers
- stores color values, either RGBA or index, for each pixel
- used for drawing onto window — only buffer that produces visible results
- separate left and right buffers for stereo viewing
- separate front and back buffers for animation using double-buffering
Depth Buffer
- stores depth, or z, value from which color comes for each pixel
- typically used for determining visible objects
Select Buffer
- stores finite amount of pick information for each pixel rendered
- pick information is of the following format
- number of names for object found
- z value of near intersection
- z value of far intersection
- all names, really IDs, for given object selected
- typically used for selecting, or picking, objects in scene with mouse
- works by intersecting ray cast from mouse point with objects in scene
Accumulation Buffer
- stores color values, RGBA only, for each pixel
- typically used to combine a series of images, or renders, into a final, composite, image
- five operations can be performed on the AB:
- Clear AB
- Color buffer * value -> copy to AB
- Color buffer * value -> add to AB
- Arithmetic operation (* or +) on AB
- AB * value -> copy to color buffer
- works by combining rectangular blocks of colors
aliased shapes |
averaged, or anti-aliased, shapes |
Stencil Buffer
- stores single mask value for each pixel rendered
- two major functions used in stenciling
glStencilFunc
determines what the stencil test isglStencilOp
determines what happens to stencil buffer if stencil test passes or fails
can also use the depth buffer to inform output (i.e., if something is in front of the stencil)
- typically used for masking irregularly shaped regions of screen, e.g., view from windshield of car
- note, do not treat stencil as “expensive”, in fact, stencil is “free” when already depth testing
dissolving floor |
mirror |
Selecting Buffers for Reading and Writing
- in OpenGL you can draw into nearly any buffer
- in GLUT_SINGLE mode (default), the front buffer is enabled
- in GLUT_DOUBLE mode (default in JOGL), the back buffer is also enabled
- can change this by using glDrawBuffer()
// select front buffer for drawing/writing glDrawBuffer(GL_FRONT); // select back buffer glDrawBuffer(GL_BACK);
- similar calls to perform actions on a specific buffer: glReadBuffer(), glClear()
References
- Multi-pass rendering by Stephen Chenney
- Multi-pass rendering by Glenn Chappell
- Uses of the Stencil Buffer by Mark J. Kilgard
- Accumulation Buffer: Hardware Support for High-Quality Rendering by P. Haeberli and K. Akeley
- Creating Shadows