Transparency and Depth
Functions
glutInitDisplayMode( GL_RGBA | GL_DEPTH ...);
glClearColor(R,G,B,A);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glEnable(GL_DEPTH_TEST);
glDepthMask(GL_TRUE);
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPH,GL_ONE_MINUS_SRC_ALPHA);
Topics
- Depth buffers and depth mask
- Hidden surface elimination
- Object-based algorithms
- The z-buffer algorithm
- blending
- transparency by blending
- combining transparency with depth
- why it is hard
- how to do it
- imagine we draw the following quads in the order Red, Green, Blue:
The resulting picture needs to combine some green with red and some
green with blue, so the blue needs to overwrite the red pixels that are
behind the green and then be combined with the green, and that just
doesn't happen:
- If depth function is on and depth mask is
on, most of the blue square isn't drawn.
- If depth function is on and depth mask is
off, the blue square is drawn, but the blue doesn't
combine with green, it combines with the red/green combination.
- If depth function is off the depth mask is
irrelevant, and the blue square is drawn, combining with the red/green
combo. If the red were drawn after the blue, the wrong picture would
result.
- So, we usually draw all the opaque stuff first, then turn off the
depth mask or test, and draw all the transparent stuff, working towards
the camera.
- depth resolution
- what does it mean?
- we lose r = log2(far/near) bits of resolution
Demos
Written by Scott D. Anderson
scott.anderson@acm.org

This work is licensed under a Creative Commons
License.