i
i
i
i
i
i
i
i
314 13. More Ray Tracing
To be most faithful to a real camera, we should make the lens a disk. However,
we will get very similar effects with a square lens (Figure 13.17). So we choose
the side-length of the lens and take random samples on it. The origin of the
view rays will be these perturbed positions rather than the eye position. Again, a
shuffling routine is used to prevent correlation with the pixel sample positions. An
example using 25 samples per pixel and a large disk lens is shown in Figure 13.16.
Figure 13.17. To create
depth-of-field effects, the
eye is randomly selected
from a square region.
13.4.4 Glossy Reflection
Some surfaces, such as brushed metal, are somewhere between an ideal mirror
and a diffuse surface. Some discernible image is visible in the reflection but it
is blurred. We can simulate this by randomly perturbing ideal specular reflection
rays as shown in Figure 13.18.
Only two details need to be worked out: how to choose the vector r
and what
to do when the resulting perturbed ray is below the surface from which the ray is
reflected. The latter detail is usually settled by returning a zero color when the
ray is below the surface.
Figure 13.18. The re-
flection ray is perturbed to
a random vector r
.
To choose r
, we again sample a random square. This square is perpendicular
to r and has width a which controls the degree of blur. We can set up the square’s
orientation by creating an orthonormal basis with w = r using the techniques in
Section 2.4.6. Then, we create a random point in the 2D square with side length
a centered at the origin. If we have 2D sample points (ξ, ξ
) ∈ [0, 1]
2
, then the
analogous point on the desired square is
u = −
a
2
+ ξa,
v = −
a
2
+ ξ
a.
Because the square over which we will perturb is parallel to both the u and v
vectors, the ray r
is just
r
= r + uu + vv.
Note that r
is not necessarily a unit vector and should be normalized if your code
requires that for ray directions.
13.4.5 Motion Blur
We can add a blurred appearance to objects as shown in Figure 13.19. This is
called motion blur and is the result of the image being formed over a non-zero