Game Development Reference
In-Depth Information
GLuint pDepthLayer[K]; // storing the depth layers
GLuint bufferFront , bufferFocus, bufferBack; // composition b
// do front buffer compositing
bindAndClearFbo( bufferFront );
for ( uint k = 0 ; k < kFocus ; ++ k ) {
blendLayer( pDepthLayer[k] );
blurBuffer( bufferFront, computeSigmaForLayer( k ) );
// do focus buffer compositing
bindAndClearFbo( bufferFocus );
blendLayer( pDepthLayer[kFocus] );
// do back buffer compositing
bindAndClearFbo( bufferBack );
for ( uint k = K-1 ; k > kFocus ; -- k ) {
blendLayer( pDepthLayer[k] );
blurBuffer( bufferBack, computeSigmaForLayer( k ) );
Listing 2.3. OpenGL pseudocode for blending and blurring the depth layers onto the
composition buffers: front, focus, and back.
In particular, depth layers are blended onto one of three so-called composi-
tion buffers for the front, back, and focus parts of the scene. ( I front , I back ,and
I focus ). While the latter is only filled with the in-focus depth layer ( L k focus ), the
other depth layers are composed iteratively onto the front and back composition
buffers, starting from the foremost and the furthest depth layer ( L 0 and L K 1 ),
respectively. The two composition buffers have to be used because otherwise it
is not possible to keep the correct depth ordering of the layers. Between each
composition iteration, the composition buffers are blurred with a Gaussian filter
H k , where the index k is the same as the recently composed depth layer L k .Com-
position is done by alpha blending, where the front composition buffer is blended
over the next depth layer and for the back composition buffer the depth layer
is blended over the composition buffer ( I front
I back , respectively).
L k
and L k
Pseudocode for this operation is shown in Listing 2.3.
As desired, stronger blurs can be achieved with smaller filter kernel sizes. For
example, a depth layer L 0
1 times with the Gaussian
kernels H 0 to H k focus 1 . Blurring recursively has a similar result to blurring with
a Gaussian kernel H k , where the filter width (in σ ) is the Euclidean distance of
all applied recursive filter sizes:
will be blurred k focus
k focus
σ i ,
σ k
i = k
Search Nedrilad ::

Custom Search