Game Development Reference
In-Depth Information
coherent uniform layout(size4x32) image2DArray abufferImg;
coherent uniform layout(size1x32) uimage2D abufferCounterImg
void main( void ){
// atomic increment of the counter
int c= int (imageAtomicInc(abufferCounterImg, coord.xy));
val.w = coord.z; // depth used for sorting
// store fragment into A-buffer
imageStore(abufferImg, ivec3(coord.xy, c), val);
}
Listing 2.1. Pseudocode for the fragment shader rendering fragments into the A-buffer.
First the fragment counter C is increased to the value c . Then the shading color of the
processed fragment is written into the 3D texture at position A c .
scenes. For each depth layer, there are splitting depths (called anchor points )
that specify which layer fragments will be sorted into. The decomposition is
done by multiplying the fragments with a matting function ( ω k
and ω k ), where
the matting function differs for each depth layer L k :
L k = I 0 ·
ω k ( Z 0 )
I 1 ·
ω k ( Z 1 )
I C 1 ·
ω k ( Z C 1 ) .
...
(2.2)
The notation A
B denotes alpha-blending of A over B . In Figure 2.3 , a schemat-
ics of this algorithm is shown for an example layer L k . Equation (2.2) is applied
K times to produce K depth layers. (See Figure 2.5. )
2.5.1 Matting Functions
The matting function ω k ( Figure 2.4 (a) ) was introduced in [Kraus and Strengert
07] and guarantees a smooth transition of objects between layers. The special
matting function ω k ( Figure 2.4 (b) ) retains a hard cut at the back layer bound-
aries to avoid situations where background fragments would be blended over
foreground layers. The formulas are
ω k ( z )= z k z
for
z k <z<z k +1 ,
z k z k +1
(2.3)
ω k ( z )
t er
ise,
and
z z k 2
z k 1 z k 2
for
z k 2 <z<z k 1 ,
ω k ( z )=
(2.4)
1
for
z k 1
z
z k ,
0
otherwise,