O'Reilly logo

OpenGL Insights by Christophe Riccio, Patrick Cozzi

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Efficient Layered Fragment
Buffer Techniques
Pyarelal Knowles, Geoff Leach, and F abio Zambetta
20.1 Introduction
Rasterization typically resolves visible surfaces using the depth buffer, computing just
the front-most layer of fragments. However, some applications require all fragment
data, including those of hidden surfaces. In this chapter, we refer to these data and the
technique to compute them as a layered fragment buffer (LFB). LFBs can be used for
order-independent transparency, multilayer transparent shadow maps, more accurate
motion blur, indirect illumination, ambient occlusion, CSG, and relief imposters.
With the introduction of atomic operations and random access to video memory
exposed via image units in OpenGL 4.2, it is now possible to capture all fragments
in a single rendering pass of the geometry. This chapter describes and compares
two approaches to packing this data: linked list–based and linearized array–based
approaches.
Transparency is a well-known effect that requires data from hidden surfaces. It
is used here to demonstrate and compare different LFB techniques. To render trans-
parency, an LFB is constructed, and the fragments at each pixel are sorted. Fig-
ure 20.1 shows an example of fragment layers after sor ting where each layer contains
fragments of the same depth index. Note that surfaces a re discretized and there is
no fragment connectivity information. The sorted fragments a re then blended in
back-to-front order. Unlike polygon-sorting approaches to transparency, the LFB
can resolve intersecting geometry and complex arrangements such as in Figure 20.2.
Previous approaches to capturing LFB data involve multiple rendering passes or
suffer from read-modify-write problems, discussed in Section 20.2. OpenGL atomic
279
20
280 III Bending the Pipeline
Layer 0
Layer 1
Layer 2
Layer 3
View Direction
Figure 20.1. Fragment layers resulting from sorting fragments by depth.
operations allow the LFB to be accurately computed in a single rendering pass. The
basic, brute force LFB technique for single-pass construction is to allocate a 3D array,
storing a fixed number of layers in z for each pixel x, y. A per-pixel atomic counter
is incremented to write fragments into the correct l ayer. Typical scenes have varying
depth complexities, i.e., per-pixel fragment counts, so while the brute force LFB is
fast, the fixed z dimension commonly wastes memory or overflows. The following
are two general approaches to packing the data, solving this issue:
1. Dynamic linked list construction.
2. Array based linearization.
Both aim to pack the data with minimal overhead; however, there are some significant
differences. Exploring these differences and comparing performance is the primary
focusofthischapter.
Figure 20.2. Cy clically overlapping geometry.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required