Antialiasing in OpenGL

Built-in antialiasing

Turn on polygon antialiasing with glEnable(GL_POLYGON_SMOOTH) (there are eqivilant antialiasing commands for points and lines). This causes pixels on the edges of the polygon to be assigned fractional alpha values based on their coverage, as though they were lines being antialiased. As alpha values are being used, blending needs to be enabled to see the results. A good blending function to use for antialiasing is;

glBlendFunc (GL_SRC_ALPHA_SATURATE, GL_ONE);  

Use glHint() to try to get the fastest or highest quality antialiasing. OpenGL will use prefiltering or supersampling depending on the implementation

 

Antialiasing with the Accumulation Buffer

The accumulation buffer can be used for such things as scene anti-aliasing, motion blur, simulating photographic depth of field, and calculating the soft shadows that result from multiple light sources. Other techniques are possible, especially in combination with some of the other buffers.

OpenGL graphics operations don't write directly into the accumulation buffer. Typically, a series of images is generated in one of the standard colour buffers, and these are accumulated, one at a time, into the accumulation buffer. When the accumulation is finished, the result is copied back into a colour buffer for viewing. To reduce rounding errors, the accumulation buffer may have higher precision (more bits per colour) than the standard colour buffers. Rendering a scene several times obviously takes longer than rendering it once, but the result is higher quality. You can decide what trade-off between quality and rendering time is appropriate for your application.

Chequered plane, rendered normally on top. Rendered in 16 passes to the accumulation buffer on bottom.

You can use the accumulation buffer the same way a photographer can use film for multiple exposures. A photographer typically creates a multiple exposure by taking several pictures of the same scene without advancing the film. If anything in the scene moves, that object appears blurred. Not surprisingly, a computer can do more with an image than a photographer can do with a camera. For example, a computer has exquisite control over the viewpoint, but a photographer can't shake a camera a predictable and controlled amount.

Examples of using the accumulation buffer

Accumulation buffer results

 

glAccum()

To perform scene anti-aliasing, first clear the accumulation buffer. Then loop several times (say, n ) through code that draws the image in a slightly different position (jittered, by less than one pixel), accumulating the data with glAccum(GL_ACCUM, 1.0/n ); and finally calling glAccum(GL_RETURN, 1.0).