Next | Prev | Up | Top | Contents | Index

Using Advanced Multisampling Options

Advanced multisampling options provide additional rendering capabilities. This section discusses:

Figure 8-2 shows how the subsamples in one pixel are turned on and off.

  1. First, the primitive is sampled at the locations defined by a sample pattern. If a sample is inside the polygon, it is turned on, otherwise, it is turned off. This produces a coverage mask.

  2. The coverage mask is then ANDed with a user-defined sample mask, defined by a call to glSampleMaskSGIS() (see "Using a Multisample Mask to Fade Levels of Detail").

  3. You may also choose to convert the alpha value of a fragment to a mask and AND it with the coverage mask from step 2.

    Enable GL_SAMPLE_ALPHA_TO_MASK_SGIS to convert alpha to the mask. The fragment alpha value is used to generate a temporary mask, which is then ANDed with the fragment mask.

Figure 8-2 : Sample Processing During Multisampling The two processes--using a multisample mask created by glSampleMaskSGIS() and using the alpha value of the fragment as a mask--can both be used for different effects.

When GL_SAMPLE_ALPHA_TO_MASK_SGIS is enabled, it's usually appropriate to enable GL_SAMPLE_ALPHA_TO_ONE_SGIS to convert the alpha values to 1 before blending. Without this option, the effect would be colors that are twice as transparent.

Note: When you use multisampling, blending reduces performance. Therefore, when possible, disable blending and instead use GL_SAMPLE_MASK_SGIS or GL_ALPHA_TO_MASK.


Color Blending and Screen-Door Transparency

Multisampling can be used to solve the problem of blurred edges on textures with irregular edges, such as tree textures, that require extreme magnification. When the texture is magnified, the edges of the tree look artificial, as if the tree were a paper cutout. To make them look more natural by converting the alpha to a multisample mask, you can obtain several renderings of the same primitive, each with the samples offset by a specific amount. See "Accumulating Multisampled Images" for more information.

The same process can be used to achieve screen-door transparency: If you draw only every other sample, the background shines through for all other samples, resulting in a transparent image. This is useful because it doesn't require the polygons to be sorted from back to front. It is also faster because it doesn't require blending.


Using a Multisample Mask to Fade Levels of Detail

You can use a mask to specify a subset of multisample locations to be written at a pixel. This feature is useful for implementing fade-level-of-detail in visual simulation applications. You can use multisample masks to perform the blending from one level of detail of a model to the next by rendering the additional data in the detailed model using a steadily increasing percentage of subsamples as the viewpoint nears the object.

To achieve this blending between a simpler and a more detailed representation of an object, or to achieve screen-door transparency discussed in the previous section, either call glSampleMaskSGIS() or use the Alpha values of the object and call glSampleAlphaToMaskSGIS(). Below is the prototype for glSampleMaskSGIS():

void glSampleMaskSGIS (GLclampf value, boolean invert);
To define a multisample mask using glSampleMaskSGIS(), follow these steps:

  1. Enable GL_SAMPLE_MASK_SGIS.

  2. Call glSampleMaskSGIS() with, for example, value set to .25 and invert set to GL_FALSE.

  3. Render the object once for the more complex level of detail.

  4. Call glSampleMaskSGIS() again with, for example, value set to .25 and invert set to GL_TRUE.

  5. Render the object for the simpler level of detail.

    This time, the complementary set of samples is used because of the use of the inverted mask.

  6. Display the image.

  7. Repeat the process for larger sample mask values of the mask as needed (as the viewpoint nears the object).

Accumulating Multisampled Images

You can enhance the quality of the image even more by making several passes, adding the result in the accumulation buffer. The accumulation buffer averages several renderings of the same primitive. For multipass rendering, different sample locations need to be used in each pass to achieve high quality.

When an application uses multisampling in conjunction with accumulation, it has to call glSamplePatternSGIS() with one of the following patterns as an argument:

Accumulating multisample results can also extend the capabilities of your system. For example, if you have only enough resources to allow four subsamples, but you are willing to render the image twice, you can achieve the same effect as multisampling with eight subsamples. Note that you do need an accumulation buffer, which also takes space.

To query the sample pattern, call glGetIntegerv() with pname set to GL_SAMPLE_PATTERN_SGIS. The pattern should be changed only between complete rendering passes.

For more information, see "The Accumulation Buffer," in Chapter 10, "The Framebuffer," of the OpenGL Programming Guide.


Next | Prev | Up | Top | Contents | Index