Game Development Reference
Third, foreground objects have to be able to blur fairly far (up to 10% of
the screen width) without compromising performance. The na ıve approaches of
scattering each pixel as a disk and the inverse of performing the equivalent gather
operation are too slow—those methods require O( r 2 ) operations for blur radius
r and thrash the texture/L1 cache.
The DoF post-process in our engine is fast and produces good-quality near-
and far-field blurring with little perceptible color bleeding. It reads a color buffer
with a specially encoded alpha channel and produces a convincing DoF effect in
three “full-screen” 2D passes over various size buffers. It uses 1.9 ms of GPU
time running at 720p on the Xbox 360. On a PC it uses 1.0 ms of GPU time
running at 1080p on a GeForce GTX 680.
We developed our DoF effect from Gillham's ShaderX 5 one [Gillham 07].
Like his and other similar techniques [Riguer et al. 03, Scheuermann 04, Ham-
mon 07, Kaplanyan 10, Kasyan et al. 11], we work with low-resolution buffers
when they are blurry and lerp between blurred and sharp versions of the screen.
The elements of our improvements to previous methods are
treating near field separately to produce blurry silhouettes on the near field,
inpainting behind blurry near-field objects,
a selective background blur kernel,
using CoC instead of depth to resolve occlusion and blur simultaneously,
processing multiple blurs in parallel with dual render targets.
Figure 1.3 shows the structure of our algorithm. The input is a color buffer with
the (scaled and biased) signed CoC radius stored in the alpha channel. Two
passes blur horizontally and then vertically in a typical separated blur pattern,
and a final pass composites the blurred image over the sharp input. Each blur
pass processes two textures: one that represents the focus and far field, and one
that represents objects in the near field (with an alpha channel for coverage).
The radius in the alpha channel of the color input buffer is signed, meaning that
radius r at each pixel is on the range [-maximum blur, +maximum blur]. Far-
field objects have a negative radius, near-field objects have a positive one, and
0 . 5 <r< 0 . 5 in the focus field. Under a physically correct CoC model, this
signed radius naturally arises. There, it models the fact that the silhouette of the
aperture appears inverted in the far field. That inversion is irrelevant for the disc