next up previous contents
Next: 12.4 Using the Alpha Up: 12. Transparency Previous: 12.2 Alpha Blending

   
12.3 Sorting

The sorting step can be complicated. The sorting should be done in eye coordinates, so it is necessary to transform the geometry to eye coordinates in some fashion. If transparent objects interpenetrate, the individual triangles should be sorted and drawn from back to front. Ideally, polygons which interpenetrate should be tessellated along their intersections, sorted, and drawn independently, but this is typically not required to get good results. Frequently only crude or perhaps no sorting at all gives acceptable results.

If there is a single transparent object, or multiple transparent objects which do not overlap in screen space (i.e., each screen pixel is touched by at most one of the transparent objects), a shortcut may be taken under certain conditions. If the objects are closed, convex, and viewed from the outside, culling may be used to draw the backfacing polygons prior to the front facing polygons. The steps are as follows:

tex2html_nowrap 32.
Enable culling: glEnableGL_CULL_FACE(GL_CULL_FACE).
tex2html_nowrap 33.
Configure face culling to eliminate front facing polygons: glCullFace(FRONT).
tex2html_nowrap 34.
Draw the object.
tex2html_nowrap 35.
Configure face culling to eliminate back facing polygons: glCullFace(BACK).
tex2html_nowrap 36.
Draw the object again.
tex2html_nowrap 37.
Disable culling: glDisableGL_CULL_FACE(GL_CULL_FACE).

We assume that the vertices of the polygons of the object are arranged in a counter-clockwise direction when the object is viewed from the outside. If necessary, we can specify that polygons oriented clockwise should be considered front-facing with the glFrontFace() command.

Drawing depth buffered opaque objects mixed with transparent objects takes somewhat more care. The usual trick is to draw the background and opaque objects first in any order with depth testing enabled, depth buffer updates enabled, and blending disabled. Next, the transparent objects are drawn from back to front with blending enabled, depth testing enabled but depth buffer updates disabled so that transparent objects do not occlude each other.


next up previous contents
Next: 12.4 Using the Alpha Up: 12. Transparency Previous: 12.2 Alpha Blending
David Blythe
1999-08-06