Game Development Reference
In-Depth Information
uniform float anchor[4]; // anchor points array
// fragment counter and input buffer textures
uniform layout(size1x32) uimage2D abufferCounterImg;
uniform layout(size4x32) image2DArray inputBufferImg;
void main( void ){
int C= int (imageLoad(abufferCounterImg, coord.xy).r);
vec4 finalColor = vec4(0, 0, 0, 0);
for ( int c = 0; c < C; ++ c) {
vec4 val = imageLoad(inputBufferImg , vec3(coord.xy, c));
vec4 color = vec4(val.rgb,1.0);
float depth = val.z; // depth is stored in alpha channel
// check if fragment is within z_{k-2} and z_{k+1},
// or z_{k} if (c!=0)
if (anchor[3] <= depth && depth < anchor[(c==0)?0:1]) {
float w = 1.0; // weight
// z_{k} < z
if (anchor[1] < depth) {
w = (anchor[0] - depth) / (anchor[0] - anchor[1]);
}
// z < z_{k-1}
else if (depth < anchor[2]) {
w = (depth - anchor[3]) / (anchor[2] - anchor[3]);
}
// alpha blending
finalColor += (1.0f - finalColor.a) * color * w;
}}}
Listing 2.2. Pseudocode for matting fragments into a depth layer with a shader (Equa-
tion (2.2)). The anchor points are computed on the CPU and handed in as a uniform
array. Depending on which input buffer is processed, either ω or ω is used.
2.5.2 Anchor Points
The layer matting relies on anchor points, which are spaced according to the filter
size of the blurring method, similar to [Kraus and Strengert 07]. This means that
the positions of the layer boundaries for a depth layer L k are determined by
the filter size (approximating d k , the CoC for this layer) of the chosen blurring
method. Since all fragments in the depth layer will be uniformly blurred, the
anchor points should be evenly spaced with respect to the filter sizes. Therefore,
we use the average CoC of a depth layer and its adjacent layer:
d k + d k +1
2
d k
=
.
If we neglect the absolute value computation in Equation (2.1), we can invert the
formula and calculate approximate depth values based on the filter size:
f 2
z focus ·
( d k )=
z k = d 1
d k · N · ( z focus f ) .
(2.5)
coc
f 2 +
 
 
Search Nedrilad ::




Custom Search