COMPUTER GRAPHICS forum

DOI: 10.1111/j.1467-8659.2012.02097.x

Volume 0 (2012), number 0 pp. 1–11

Efficiently Simulating the Bokeh of Polygonal Aperturesin a Post-Process Depth of Field Shader
L. McIntosh, B. E. Riecke and S. DiPaola
School of Interactive Arts and Technology, Simon Fraser University, Vancouver, Canada{lmcintos, ber1, sdipaola}@sfu.ca

Abstract
The effect of aperture shape on an image, known in photography as ‘bokeh’, is an important characteristic ofdepth of field in real-world cameras. However, most real-time depth of field techniques produce Gaussian bokehrather than the circular or polygonal bokeh that is almost universal in real-world cameras. ‘Scattering’ (i.e.
point-splatting) techniques provide a flexible way to model any aperture shape, but tend to have prohibitively slow
performance, and require geometry-shaders or significant engine changes to implement. This paper shows that
simple post-process ‘gathering’ depth of field shaders can be easily extended to simulate certain bokeh effects.
Specifically we show that it is possible to efficiently model the bokeh effects of square, hexagonal and octagonal
apertures using a novel separable filtering approach. Performance data from a video game engine test demonstrates
that our shaders attain much better frame rates than a naive non-separable approach.
Keywords: computer graphics, rendering, real-time, shaders, depth of field
ACM CCS: I.3.7[Computer Graphics]: Three-Dimensional Graphics and Realism: Colour; Shading; Shadowing
and Texture

1. Introduction[Mer97]. Lens effects like spherical and chromatic aberration
also contribute significantly to bokeh, but in this paper weconcern ourselves solely with the effect of aperture shape.

In real-world cameras, precise focus can only be achieved for
objects at a specific distance from the lens. Objects nearer toor farther from the lens than this distance are defocused andproduce progressively larger blurred spots known as Circles
of Confusion (CoC), on the camera’s image sensor. This effect, called ‘depth of field’, provides cues about scene depth
to viewers, and has become an important tool in cinematography where it is often used to draw attention to particularparts of a scene [Mon00].

This paper presents a novel approach that applies separable filtering to the problem of efficiently simulating thebokeh of various aperture shapes. Section 2 reviews somepreviously published depth of field techniques, Section 3
presents a ‘naive’ non-separable approach to bokeh as motivation, Section 4 presents our separable bokeh technique andSection 5 presents the results of a performance test that compares the efficiency of our approach to the naive one.

As video games increase in narrative and graphical sophistication, many are attempting to emulate this cinematic effectin real time. Unfortunately, most real-time depth of field implementations fail to fully consider the effect of ‘bokeh’ on
the image (see Figure 1). Bokeh refers to the appearanceof the CoC in the defocued areas of an image, and is mostclearly revealed by small bright defocused points of light.
Many aspects of a camera’s design contribute to bokeh, but
the most significant aspect is usually the shape of the aperturec 2012 The Authors
c 2012 The Eurographics
Computer Graphics Forum 
Association and Blackwell Publishing Ltd. Published byBlackwell Publishing, 9600 Garsington Road, Oxford OX4
2DQ, UK and 350 Main Street, Malden, MA 02148, USA.

2. Background and Related Work
Beginning with the work of Potmesil and Chakravarty[PC81], there has been substantial research into various techniques for adding depth of field effects to computer graphics.
Demers [Dem04], organizes depth of field techniques into
five categories:

12

L. McIntosh et al. / Efficiently Simulating Bokeh

In general, ray tracing and accumulation-buffer techniques
remain too computationally expensive to be executed withacceptable results in real time. Compositing techniques arefeasible for real-time applications and are becoming increasingly popular in the computer graphics literature [KLO06,
KS07, LKC08, LES09, LES10]. These approaches can produce quite realistic results, with proper partial occlusion andother difficult issues addressed. The layered rendering required by these techniques can require significant changes
to existing graphics engines to implement, however, and forlower end hardware they remain computationally expensive.
For these reasons, depth of field techniques for real-time
applications remain largely centred around z-buffer (postprocess) techniques.
Forward-mapped (scattering) z-buffer techniques—
sometimes called ‘point splatting’ techniques—work by distributing each pixel’s colour to neighbouring pixels. A colour
map and a depth map (i.e. z-buffer) are produced for thescene, and the diameter of the CoC is calculated for eachpixel based on the depth map and some focus parameters.
Finally, each pixel is blended into the frame buffer as a circle (or any desired aperture shape) with a diameter equal to
the CoC. Typically this is accomplished by rendering textured sprites, centred at the location of each original pixel.
Using a textured sprite has the advantage that any desired
aperture shape can be modelled by simply changing the texture used. Depth-sorting can be used to ensure each sprite
only affects pixels that are farther from the camera than itself(to prevent blurry backgrounds from affecting focused foregrounds). Unfortunately, such forward-mapped techniques
are not very amenable to execution in real time as they require a large number of sprites to be rendered every frame. In
addition, they require the costly depth-sorting of these sprites[LKC08].

Figure 1: These high dynamic range (HDR) photographs
have been processed by our separable bokeh technique
to simulate depth of field (a constant scene depth was
assumed). (a) Demonstrates the bokeh of a hexagonal
aperture, (b) and (c) simulate the bokeh of octagonal apertures. (HDR photos courtesy of Mark Fairchild:
http://www.cis.rit.edu/fairchild/).

• Distributing traced rays across the surface of a lens• Rendering from multiple cameras (accumulation-buffer)• Rendering and compositing multiple layers• Forward-mapped (scattering) z-buffer techniques• Reverse-mapped (gathering) z-buffer techniques

Reverse-mapped (gathering) z-buffer techniques are similar in concept to forward-mapped techniques, but with one
significant difference. Rather than each pixel spreading its
colour value to neighbouring pixels (by way of renderinga sprite), each pixel explicitly samples the colour values of
its neighbours to determine its own value. This category oftechniques is generally much better suited to execution on
current graphics hardware, as it avoids the costly processingof millions of sprites and takes advantage of fast hardware
texture lookups. For this reason, many modern video games
implementing depth of field use a technique from this category (for example, Call of Duty 4: Modern Warfare (Infinity
Ward, 2007) uses one [Ham07]). In general, realistic bokeh
effects (like circular or polygonal apertures) are not efficiently modelled with reverse-mapped z-buffer techniques.
Our approach, and a similar one developed concurrently at
DICE [WB11] (published while this paper was in review),
appear to be the first attempts to do so.
Riguer et al. [RTI03] and Scheuermann [Sch04] provide good introductions to the conventional reverse-mappedc 2012 The Authors
c 2012 The Eurographics Association and Blackwell Publishing Ltd.
Computer Graphics Forum 

L. McIntosh et al. / Efficiently Simulating Bokeh

Figure 2: In this comparison, intensity leakage or ‘pixel
bleeding’ is visible in (a) around the focused foregroundobject. However, in (b) where an intensity leakage solution[RTI03] has been applied, the effect is greatly reduced.
z-buffer techniques that do not consider bokeh. Riguer et al.
describe two separate reverse-mapped z-buffer techniques,
and Scheuermann essentially combines them into a hybrid
technique that overcomes some limitations of both. Using
Scheuermann’s technique, one starts by rendering a CoC
map into the alpha channel of the colour map. This colour
map is then downsampled to 1/4th of its original dimensions(1/16th the number of pixels), and a two-pass separable Gaussian blur is applied to it. In a final pass, the desired CoC isread from the alpha channel of the original colour map, and afilter with an 8-sample stochastic kernel (of the CoC size) isused to sample from both the original and the downsampledcolour maps. These two samples are then linearly interpolated
based on the CoC size. The result of this interpolation is thatsamples with a large CoC effectively come from the blurred
colour map, although samples with a small CoC effectively
come from the original colour map. The interpolated samples
are then combined in a weighted average to determine thefinal value of each pixel.
2.1. Common post-processing artefacts
Scheuermann’s depth of field technique, along with many
similar reverse-mapped z-buffer techniques, suffers from anumber of graphical artefacts that reduce the realism of
the final image. Our technique specifically addresses one ofthese—lack of realistic bokeh—but we briefly discuss them
all as our technique exhibits many of them.
The first artefact—and one that Riguer et al. [RTI03]
specifically attempt to solve in their technique—is called
intensity leakage (or pixel bleeding). Focused foregroundobjects appear to ‘leak’ onto blurry backgrounds (seeFigure2 ), because the blurry pixels in the background havelarge CoC diameters and sample some part of their value
from pixels of the focused foreground object. Riguer et al.
and Scheuermann address this problem by carefully weighting each of the samples in the average. Samples that have a3

Figure 3: In this image, produced by our separable bokeh
technique, the defocused foreground object’s silhouette is
too sharp against the focused tree branch behind it. Somefading occurs inside the silhouette (b), but the silhouette will
not realistically spread out over its borders onto the tree
branch (a).

significantly smaller CoC (those that are more focused) andare closer to the camera than the centre sample are weighted
much lower than normal. Our technique includes thissolution.
Another artefact inherent to post-processing depth of fieldtechniques is a lack of partial occlusion. In images produced by real cameras, the edges of blurry foreground objects
spread out smoothly and appear semi-transparent over top of
focused objects behind them. In the images produced by mostpost-process gathering depth of field techniques however,blurry foreground objects remain opaque, revealing no details behind them. Solutions to this problem typically involve
rendering multiple layers. In general, post-process gathering techniques, including ours, do not attempt to solve thisproblem. In most applications the issue can be side-steppedby simply preventing foreground objects from coming too
near the camera (and thus from becoming excessively blurry,
revealing the artefact).
Another artefact is the appearance of sharp silhouettes on
defocused foreground objects against focused backgrounds(see Figure3). This occurs because pixels from the focused background have small CoC and will not sample
from the defocused foreground, and thus the defocused
foreground will not appear to spread out over the focusedbackground. Hammon [Ham07] proposes a simple solution
to this which involves blurring the CoC map itself in a
specific way. Our technique does not specifically address
this problem, though Hammon’s solution could easily be
integrated.
The last common artefact, and the one we specifically attempt to address, is a lack of realistic bokeh—especiallyin high dynamic range (HDR) rendering where small brightdefocused points of light tend to reveal the bokeh of the simulated camera. In real-world cameras, circular and polygonal
apertures are nearly universal. However, in reverse-mappedc 2012 The Authors
c 2012 The Eurographics Association and Blackwell Publishing Ltd.
Computer Graphics Forum 4

L. McIntosh et al. / Efficiently Simulating Bokeh

produced by different parallelogram-shaped apertures withan intersection-like (or union-like) operation. For instance,
an octagonal aperture is simulated by combining the results of
two square apertures, one aperture rotated 45 degrees fromthe other. A more thorough explanation of the techniquefollows. Please refer to the Appendix for a complete code
listing.

4.1. Rendering the CoC map
Figure 4: (a) Shows a 2D 127-sample kernel that could be
used to produce a hexagonal bokeh effect. (b) Shows a 2D
120-sample kernel that could be used to produce an octagonal bokeh effect. As we demonstrate, this approach suffersfrom poor performance because of the large number of samples necessary.
z-buffer techniques the bokeh is most often Gaussian (asin [KLO06], [KS07] and [ZCP07]). In contrast, our separable technique efficiently approximates the bokeh of simple
polygonal apertures—specifically, we demonstrate square,hexagonal and octagonal apertures, though many others are
possible. Note that we do not attempt to model complex lenseffects such as chromatic or spherical aberrations. For discussion of a ray tracing technique that can model these sortof bokeh effects see Wu et al.[WZH*10].
3. A Naive Approach
Before we describe our separable bokeh technique, we firstdescribe a naive approach as motivation. The most obvious
approach to creating bokeh effects in a gathering depth offield shader might be to filter the colour map with a carefully
designed variable-size 2D kernel, similar to the 8-sample
stochastic filter used by Scheuermann. Using many samples,and carefully arranging their positions in the kernel, various
aperture shapes could be modelled. For example, to approximate the bokeh of hexagonal and octagonal apertures, 2D
kernels like those in Figure4 could be used. This approachproduces the desired bokeh effect, and has the advantage thatany conceivable aperture shape can be approximated. Indeed,
it would appear to be a perfect solution. As we will show,
however, the performance of such a shader is poor, and attempting to increase performance using fewer samples leads
inevitably to sampling artefacts.

Similar to the work by Scheuermann [Sch04], our separable
bokeh technique starts by rendering a CoC map into thealpha channel of the colour map. Storing the CoC map in thealpha channel of the colour map allows for blurring the CoC
map itself alongside the colour map (we explain the need forthis in Section 4.4). A 16-bit render target is used to hold
HDR lighting information (allowing for bright defocusedhighlights) in the RGB channels, as well as precise CoC datain the alpha channel. The CoC for each pixel is calculated by
the following formula (from the well known thin-lens model),where c is the diameter of the CoC, A is the diameter of theaperture, f is the focal length, S1 is the focal distance and S2
is the given pixel’s scene depth, (as read from a depth map):c =A·|S2 − S1 |f.
·
S2
S1 − fFor storage in the alpha channel, the CoC diameter is thendivided by the height of the virtual ‘image sensor’. Any value
can be used, but for realism we chose 0.024 m (24 mm) in
our shaders—a value taken from the real-world 35 mm full
frame format. We consider this length to represent the maximum CoC diameter that could reasonably be captured byour simulated camera. This division ensures more effective
usage of our full 16-bit render target, and makes the calculations in later passes more efficient as the CoC diameter is
now expressed as a percentage of the image size (the native
format for texture coordinates in Direct3D and OpenGL).
Finally, the return value is clamped between zero and an artificially imposed maximum percentage. This is done to prevent excessively large CoC from causing notable sampling
artefacts.

4.2. Parallelogram-shaped apertures

4. A Separable Approach

Because all our aperture shapes are based on parallelograms,
we begin with a discussion of them.

Our technique leverages the efficiency of separable filters toachieve its performance gains. In a nutshell, we begin witha modified ‘box-blur’ filter, which can simulate the effectof any parallelogram-shaped aperture (for instance, a square
aperture). To simulate more complex aperture shapes likehexagons and octagons, we then combine two or more images

Simulating a parallelogram-shaped aperture is mostly astraightforward application of a ‘box-blur’ filter. A 1D uniform kernel is applied in each pass, between passes the kernel
is rotated, and the output of the first pass is provided as input
to the second pass to create a cumulative effect. The majordifferences from a separable box-blur filter are:c 2012 The Authors
c 2012 The Eurographics Association and Blackwell Publishing Ltd.
Computer Graphics Forum 

L. McIntosh et al. / Efficiently Simulating Bokeh

5

Figure 5: In this series, a single bright test point is spread
into a square over two passes. It shows, (a) the original
image, (b) the result of the first pass and (c) the final result of
the second pass. Arrows indicate the direction of the linear
kernel applied in each pass to produce the next image.

Figure 6: In this series, a single bright test point is spread
into a diamond over two passes. It shows, (a) the original
image, (b) the result of the first pass and (c) the final resultof the second pass.

• We choose the rotation of the kernel in each pass
to aid the construction of the desired polygonal
shape.

4.4. Multi-pass filtering• We use a uniform kernel (i.e. the samples are weighted
evenly) but we ignore those samples that would contribute to intensity leakage.
• We vary the kernel width per-pixel based on the CoC map
read from the alpha channel.
• We make no effort to align sample coordinates to pixel
boundaries or centres.

4.3. Creating sample offsets
To create the sampling offsets, the desired number of samples
per pass must first be decided. Using too few samples may
result in sampling artefacts—especially in areas of the image
with large CoC. Using too many samples will adversely affectperformance. Through experimentation we found that a nicecompromise is about 13 samples per pass, resulting in an
effective 169 samples (13 × 13) after the second pass. Any
number may be used, however.
The offsets are evenly spaced along a straight line 1 unit
in length, and are centred about the origin (0,0). By choosing different orientations for the line, various parallelograms
can be achieved. For instance, a square is made by using
an angle of 0 degrees on the first pass, and 90 degrees on
the second pass (see Figure 5). A ‘diamond’ with acute angles of 45 degrees is made by using an angle of 0 degrees
on the first pass, and 45 degrees on the second pass (seeFigure 6).
To increase shader performance, the sampling offsets foreach filtering pass are pre-calculated once in the application code. The offsets are then passed into the shader via
registers upon each pass. Before using these offsets, they
are multiplied in the shader by the desired CoC diameter at
the given pixel to achieve the correct kernel width for thatpixel.

Each filtering pass is started by reading the colour map at thecurrent pixel (including the alpha channel storing the CoC
map). The depth map is also read at the current pixel.
Next, the sampling is done in a loop. For each sample, thetexture coordinates are calculated by multiplying the sample offset (calculated earlier) with the desired CoC diameter
stored in the alpha channel of the colour map. This offset isthen added to the current pixel coordinates to get the final
sample coordinates. The colour map and the depth map areboth read at these coordinates, and the results are stored inlocal variables.
Still inside the loop, we apply the intensity leakage solution. The sample depth is compared to the current pixel
depth, and the sample CoC is compared to the current pixel
CoC. If the sample depth is less than the current pixel depth(i.e. it is closer to the camera) and the sample pixel CoC isless than the current pixel CoC (i.e. it is more focused), thenusing the sample would contribute to intensity leakage andthe sample is ignored.
For valid samples, their colour and alpha values are added
to a running total, and a counter is incremented to accumulate
the number of valid samples found.
When all the samples have been made, the loop exits andthe samples are averaged by dividing the running total by the
number of valid samples found. This average is then returnedby the shader.
One should note that we blur both the colour map, andthe CoC map (stored in the alpha channel of the colour map)during each filtering pass. Though not based in any real
physical process, we have found that blurring the CoC map
in this way helps to reduce sharp edges that otherwise sometimes occur in defocused areas at depth-discontinuities (seeFigure 7 ). We believe this acts as a less rigorous version of themore sophisticated CoC map blurring that Hammon [Ham07]
performs.

c 2012 The Authors
c 2012 The Eurographics Association and Blackwell Publishing Ltd.
Computer Graphics Forum 6

L. McIntosh et al. / Efficiently Simulating Bokeh

Figure 7: This figure compares the effect of blurring (a) andnot blurring (b) the CoC map alongside the colour map ineach filtering pass. Note the sharp edges in (b) along theedges of the tree branches.
Unlike the work by Riguer et al. [RTI03] and Scheuermann[Sch04], we do not create a downsampled copy of our colour
map. Instead, all filtering operations are performed on the
full-size colour map. This reduces artefacts, reduces the total
number of passes required (along with the associated performance overhead) and simplifies the implementation.
Throughout the multi-pass filtering, we use linear texture
filtering and clamped texture addressing. Linear filtering(although technically incorrect at depth discontinuities) provides smoother, less pixelated results than nearest-neighbour
filtering. Clamped addressing provides reasonable sample
extrapolation for pixels near the edges of the image.
4.5. Complex aperture shapes
To simulate more complex aperture shapes, (like hexagons
and octagons), we combine two or more images produced bydifferent parallelogram-shaped apertures. Conceptually, thecombination can be thought of as a boolean operation, as inconstructive solid geometry. For example, a hexagon can becreated by taking the boolean intersection of two carefully
chosen parallelograms (see Figure 8a). The area common
to both shapes is kept, although other areas are discarded.
Similarly, an octagon can be created by taking the booleanintersection of two squares (see Figure 8b). A star polygon
can be created by taking the boolean union of two squares(see Figure 8c). With a little creativity a variety of shapes
can be realized as the boolean intersections and unions ofparallelograms, but for the sake of simplicity, we have chosen
to limit our discussion to just hexagons and octagons.
Unfortunately for our purposes, performing a properboolean intersection or union is out of the question. We are,after all, not actually dealing with individual polygons, butrather thousands of pixels representing thousands of overlapping CoC. It is thus impossible for us to consider any

Figure 8: Hexagons (a), octagons (b) and star polygons(c) can all be created by taking the boolean intersections orunions of various parallelograms. With a little creativity, agreat variety of shapes can be realized this way.
two polygons in isolation. There are however, two functions
which when supplied with our images as arguments, will accomplish sufficiently similar effects: they are Min(x, y) andMax(x, y).
The Min(x, y) function returns the lesser (i.e. least bright)of x and y at every pixel, and thus approximates a booleanintersection by preserving bright pixels only in the areas
where bright CoC coincide in both images. The Max(x, y)function returns the greater (i.e. most bright) of x and y
at every pixel, and thus approximates a boolean union bypreserving bright pixels wherever they exist in either image(see Figure 9).
The complete filtering workflow for our separable hexagon
and octagon implementations is thus as shown in Figure 10.
Note that we have eliminated a pass from the hexagon implementation by reusing the results of the first pass to produce
both parallelograms. This optimization can be used any time
two parallelograms share a side in common. Another optimization (not shown for clarity), is that we perform the final
Min(x, y) or Max(x, y) operation as an extra step in the lastfiltering pass, rather than make a dedicated pass for it. This
saves the overhead of setting up another pass for such a trivial
operation.
The bokeh effects achieved though this simple technique
can be surprisingly good. For instance, see Figure 1 where
hexagonal and octagonal bokeh are clearly visible. Also seec 2012 The Authors
c 2012 The Eurographics Association and Blackwell Publishing Ltd.
Computer Graphics Forum 

L. McIntosh et al. / Efficiently Simulating Bokeh

,

Min

7

=

(a)
⎛
⎜
⎜
Min ⎜
⎜
⎝

⎞

(b)

⎛
⎜
⎜
Max ⎜
⎜
⎝

⎟
⎟
⎟=
⎟
⎠

,

⎞
⎟
⎟
⎟=
⎟
⎠

,

(c)
Figure 9: The Min(x, y) function approximates a booleanintersection. We use it to model the effect of hexagonal(a) and octagonal (b) apertures. The Max(x, y) function
approximates a boolean union. It could be used to model theeffect of a star-shaped aperture (c).

Figure 10: The filtering workflow for our separable hexagon(a) and octagon (b) implementations.

Figure 11 that demonstrates our hexagonal technique on afull 3D scene, with a wide range of CoC sizes.
Regarding the design of these separable filters for arbitrary aperture shapes, we have not been able to discern any
particularly helpful rules that would make the construction
process more formulaic, and this remains a potential areafor future research. We can say that both convex and concave shapes are possible though (see Figure 9). We also
note that the technique seems to lend itself best to polygons with fewer sides (as more sides inevitably require
more parallelograms to make), and to polygons with evennumbers of sides (though odd-sided shapes are certainly
possible). Finally, we note that the artefacts produced by
Max(x, y) (see Figure 13) tend to be less notable in practicethan those of Min(x, y) (see Figure 12), and it may therefore be best to construct shapes as boolean unions whenpossible.

Figure 11: A hexagonal bokeh effect, produced by our separable depth of field technique, is visible in the tree canopyof this 3D HDR scene.

4.6. Artefacts
Our separable bokeh technique is not without its flaws.
Min(x, y) causes artefacts where an area that was intended
to be discarded (such as the corner of a square in our octagon shader) in one image, happens to coincide with anothersuch area in the other image. The result is that seemingly‘from nowhere’, bright defocused highlights of the wrong

shape appear (see Figure 12). In addition, Min(x, y) generally causes a small decrease in image intensity (brightness)in the defocused areas of an image. Max(x, y) causes artefacts where two bright defocused highlights should overlap in the final image, but do not overlap in either input
image. The result is that the highlights, although appearingc 2012 The Authors
c 2012 The Eurographics Association and Blackwell Publishing Ltd.
Computer Graphics Forum 8

L. McIntosh et al. / Efficiently Simulating Bokeh
Table 1: The FPS attained by each shader technique at different
numbers of effective samples. The naive shader fails to compile at
256, 400 and 576 samples, so these measurements could not be
performed.

Figure 12: In this test, two bright points are carefully
placed to expose the bokeh artefacts caused by our usageof Min(x, y). The effect is more exaggerated in our hexagonal implementation (a) than in our octagonal implementation(b) because of the more pronounced corners on the parallelograms used.

Effective samples

16

64

144

256

400

576

Separable hexagon
Separable octagon
Naive

105
93
106

80
65
47

62
51
24

52
41

46
35

40
30

viewers will naturally be drawn. See Figure 1(c) for an example of the artefacts caused by overlapping parallelogram
corners in practice (look for the small imperfections in theoctagonal bokeh produced by the tightly spaced lights along
the bridge deck).
5. Performance Tests

Figure 13: In this test, two bright points are carefully
placed to expose the bokeh artefacts caused by our usage ofMax(x, y). (a) Shows the result of our separable bokeh technique. For comparison, (b) shows the correct result where
intensities are added in the overlapping areas.
to overlap, do not properly add their intensities in overlapping areas (see Figure 13). In addition, Max(x, y) generally
causes a small increase in image intensity (brightness) in the
defocused areas of an image. Finally, like all gathering depthof field shaders, our approach naturally suffers from sampling artefacts in image areas with large CoC. Our techniquetends to produce even, higher frequency noise (see Figures 12
and 13) though, which is generally less perceptible to humanviewers. Dynamically adjusting the number of samples usedbased on the CoC diameter of each pixel might eliminate
sampling artefacts for large diameters, although remaining
efficient for small ones. Modern GPUs now support the dynamic branching necessary to implement this, and this could
be an interesting direction for future improvement.
Our test images have been carefully designed to expose
these artefacts. In practice though, we think these artefacts
are slight enough as to go largely unnoticed in most scenes.
This is especially true given that these artefacts are all absent
from the focused areas of images where the attention of

To determine the relative performance of our separable technique, we implemented the aforementioned hexagon and octagon versions of it in High Level Shader Language and integrated them into the Torque Game Engine Advanced (TGEA)
1.8.0 video game engine (see //www.garagegames.com/). In
addition, we implemented the naive non-separable techniquein the same manner. We then proceeded to measure the performance in frames per second (FPS) of each technique atseveral different ‘effective sample counts’ (16, 64, 144, 256,
400 and 576). In the case of the naive technique, the numberof effective samples is simply equal to the number of actual
sample operations performed. In the case of our separable
techniques, we take the number of effective samples to be
the number of samples performed per pass squared. This
would be exactly correct in the case of a single parallelogram. In the case of our hexagons and octagons the situationis less clear because of the combination of multiple parallelograms using the Min(x, y) operator. We feel this offersa good approximation to the effective number of samples in
our technique however.
A static test scene (of about 8000 polygons) was rendered
at 800 × 800 with no multi-sample anti-aliasing. FPS wasaveraged automatically over a 10 s period using the FRAPS
benchmarking tool (see //www.fraps.com/). All tests were
performed on a 2.66GHz Intel Core 2 Duo CPU, with 2GB
RAM and a GeForce 8600 GT 256MB video card, running
Windows 7 (64-bit). Vertex and pixel shaders were compiled against Shader Model 3.0 profiles, (vs_3_0 and ps_3_0,
respectively).
5.1. Results and discussion
As expected, our performance tests in TGEA (see Table 1)
reveal that our separable hexagon shader performs the fastest,
followed by our separable octagon shader and finally thenaive shader, across virtually the whole range of effectivec 2012 The Authors
c 2012 The Eurographics Association and Blackwell Publishing Ltd.
Computer Graphics Forum 

L. McIntosh et al. / Efficiently Simulating Bokeh

samples. One will note that the naive shader fails to compile
for larger numbers of samples due to the size restrictions of
Shader Model 3.0.
Our performance tests in TGEA demonstrate that our separable bokeh technique has a clear performance advantage
over the naive approach. This is not surprising, considering
the difference in the number of sample operations performed.
For example, to achieve 144 effective samples, our separable hexagon shader performs just 36 sample operations per
pixel (12 per pass × 3 passes). Similarly, our octagon shader
performs 48 sample operations per pixel (12 per pass × 4
passes). The naive approach, however, must perform the full
144 sample operations per pixel to achieve a similar quality
and its performance therefore suffers immensely. By leveraging the efficiency of separable filters, our approach attains
much better frame rates at similar quality.
6. Conclusion
In this paper, we presented a novel ‘gathering’ depth of fieldshader technique for real-time applications. By leveraging
separable filters, our technique can efficiently simulate thebokeh effects of polygonal apertures like squares, hexagons
and octagons, among others. The approach introduces someminor bokeh artefacts, but they are confined to the defocused areas of an image, and we feel they would largely gounnoticed by casual viewers. Performance data from a video
game engine test indicates that our separable bokeh technique
attains much better frame rates than a naive non-separable
approach, at comparable image quality.
6.1. Future work
It would be interesting to compare the performance and image quality of other depth of field techniques that consider
bokeh—specifically point-splatting techniques—to our separable bokeh technique. We foresee that perhaps applications
could use point-splatting for better quality on higher end
hardware, with our separable bokeh functioning as a competent fall back technique on lower end hardware. In addition, it would be interesting to investigate the possibility of
approximating lens effects like chromatic aberration in our
approach.
References[Dem04] DEMERS J.: Depth of field: A survey of techniques.
In GPU Gems: Programming Techniques, Tips and Tricks
for Real-Time Graphics. R. Fernando (Ed.). AddisonWesley Professional, Reading, MA (2004), pp. 375–390.
[Ham07] HAMMON E.: Practical post-process depth of field.
In GPU Gems 3. H. Nguyen (Ed.). Addison-Wesley Professional, Reading, MA (2007), pp. 583–605.
[KLO06] KASS M., LEFOHN A., OWENS J.: Interactive depthof field using simulated diffusion on a GPU. //graph-9

ics.pixar.com/library/DepthOfField/paper.pdf. Accessed
1 November 2011.
[KS07] KRAUS M., STRENGERT M.: Depth-of-field rendering
by pyramidal image processing. Computer Graphics Forum 26, 3 (September 2007), 645–654.
[LES09] LEE S., EISEMANN E., SEIDEL H.: Depth-of-field rendering with multiview synthesis. ACM Transactions on
Graphics 28, 5 (December 2009), 6 pages.
[LES10] LEE S., EISEMANN E., SEIDEL H.: Real-time lens blureffects and focus control. ACM Transactions on Graphics
29, 4 (July 2010), 7 pages.
[LKC08] LEE S., KIM G. J., CHOI S.: Real-time depth-offield rendering using point splatting on per-pixel layers.
Computer Graphics Forum 27, 7 (2008), 1955–1962.
[Mer97] MERKLINGER H. M.: A Technical View of Bokeh.
Photo Techniques (1997). //www.trenholm.org/hmmerk/
ATVB.pdf. Accessed 1 November 2011.
[Mon00] MONACO J.: How to Read a Film: The World ofMovies, Media, Multimedia: Language, History, Theory(3rd edition). Oxford University Press, New York, USA,2000.
[PC81] POTMESIL M., CHAKRAVARTY I.: A lens and aperture
camera model for synthetic image generation. In Proceedings of the 8th Annual Conference on Computer Graphics and Interactive Techniques (Dallas, TX, USA, 1981),
ACM, pp. 297–305.
[RTI03] RIGUER G., TATARCHUK N., ISIDORO J.: Real-time
depth of field simulation. In ShaderX2: Shader Programming Tips and Tricks with DirectX 9.0. Wordware
Publishing, Inc., Plano, TX, October 2003. //tog.acm.org/
resources/shaderx/Tips_and_Tricks_with_DirectX_9.pdf.
Accessed 1 November 2011.
[Sch04] SCHEUERMANN T.: Advanced Depth of Field, 2004.
//developer.amd.com/media/gpu_assets/Scheuermann_
DepthOfField.pdf. Accessed 1 November 2011.
[WB11] WHITE J., BARRÉ-BRISEBOIS C.: More performance!
five rendering ideas from Battlefield 3 and Need For
Speed: The Run, August 2011. //publications.dice.se/. Accessed 20 January 2012.
[WZH*10] WU J., ZHENG C., HU X., WANG Y., ZHANG
L.: Realistic rendering of bokeh effect based on opticalaberrations. The Visual Computer 26, 6-8 (April 2010),
555–563.
[ZCP07] ZHOU T., CHEN J. X., PULLEN M.: Accurate depth offield simulation in real time. Computer Graphics Forum26, 1 (2007), 15–23.


c 2012 The Authors
c 2012 The Eurographics Association and Blackwell Publishing Ltd.
Computer Graphics Forum 10

L. McIntosh et al. / Efficiently Simulating Bokeh

Appendix: Code Listing

Listing 1: CoC Map Pixel Shader (HLSL)c 2012 The Authors
c 2012 The Eurographics Association and Blackwell Publishing Ltd.
Computer Graphics Forum 

L. McIntosh et al. / Efficiently Simulating Bokeh

11

Listing 2: Creating the sample offsets (HLSL)c 2012 The Authors
c 2012 The Eurographics Association and Blackwell Publishing Ltd.
Computer Graphics Forum 12

L. McIntosh et al. / Efficiently Simulating Bokeh

Listing 3: Depth of Field Pixel Shader (HLSL)

Listing 4: Depth of Field Final Pixel Shader (HLSL)c 2012 The Authors
c 2012 The Eurographics Association and Blackwell Publishing Ltd.
Computer Graphics Forum