Graphics Reference
In-Depth Information
Figure 3.7. Examples of bokeh shape textures.
decided to go with a simple case, so kernel size equaled 1, with a buffer downscaled
by a factor of 2. The result was quite good in performance and quality. Using the
filter kernel, calculate the luminance for each pixel and simply spawn a texture
sprite (see Figure 3.7) at the pixel screen space position if the luminance pixel is
higher than a certain threshold. This luminance threshold value can be editable
by the artist so they can adjust at which luminance value the pixel will produce
a bokeh sprite when the pixel is out of focus. Performing the threshold test on
each pixel will give you a list of pixels that will spawn a bokeh sprite. The last
step is to calculate a proper scale for the bokeh sprite. The scale typically has a
maximum size, which is also editable by artists. In this step, the depth value of
the pixel is used to determine how much the pixel is out of focus. This represents
the circle of confusion mentioned earlier and at its maximum value it represents
a fully open aperture.
In short you need to calculate how much the pixel is out of focus and apply
apixelscaletothe1
1 bokeh sprite that you will spawn. The more the pixel
is out of focus (remember that in the DOF explanation a pixel is gradually out
of focus), the bigger the sprite will be on screen. If the scale value is 20 pixels,
the bokeh sprite spawned at a pixel fully out of focus will be 20
×
×
20 pixels. (See
Figure 3.8.)
At the end of this process you end up with a list of sprites containing
x screen-space position of the pixel,
y screen-space position of the pixel,
z linear value of the pixel needed to depth test the bokeh sprite in the pixel
shader,
UV coordinates of the bokeh texture,
CoC value of the pixel needed to adjust the blending amount to preserve
energy conservation,
color value of the pixel.
Search WWH ::




Custom Search