Transparency is a difficult effect to render accurately in pipeline architectures like OpenGL. Opaque objects can just cover the background. But for translucent objects, they must render by blending with the “background”. Translucent objects must be rendered from far to near. It’s very complex and complicated to render pixels from far to near. A possible solution to this issue is Order Independent Transparency technique.
Order Independent Transparency is drawing objects in any order that can get accurate results. In fragment shader, depth sorting can be done so that the programmer need not sort objects before rendering. There are a variety of techniques for doing this. The most common one is to keep a list of colors for each pixel, sort them by depth, and then blend them together in the fragment shader.
The algorithm can be expressed as three phases:
- Render opaque scene objects.
- Render transparent scene objects.
- All fragments are stored using per-pixel linked lists.
- Store fragments: color, alpha, & depth.
- Screen quad resolves and composites fragment lists.
- each pixel in fragment shader sorts associated linked list.
- blending fragments in sorted order with background.
- output final fragments.
In fragment shader, some classical sort algorithms are implemented. The effect of OIT via merge sort is shown as the following figure.
Thanks for the basic code of GLSL COOKBOOK.
Gang Liao, liao.gang@kaust.edu.sa