i
i
i
i
i
i
i
i
24.3. Accurate Direct Lighting 629
A direction with this density can be chosen according to Equation (24.3). This
allows some cancellation of cosine terms in our estimate:
L
s
(k
o
) ≈ L
e
(k
o
)+RL
f
(k
i
).
In pseudocode such a path tracer for Lambertian surfaces would operate just
like the ray tracers described in Chapter 4, but the raycolor function would be
modified:
RGB raycolor(ray a + tb, int depth)
if (ray hits at some point c ) then
RGB c = L
e
(−b)
if (depth < maxdepth) then
compute random direction d
return c + R raycolor(c + sd,depth+1)
else
return background color
This will result in a very noisy image unless either large luminaires or very large
numbers of samples are used. Note the color of the luminaires must be well above
one (sometimes thousands or tens of thousands) to make the surfaces have final
colors near one, because only those rays that hit a luminaire by chance will make
a contribution, and most rays will contribute only a color near zero. To generate
the random direction d, we use the same technique as we do in particle tracing
(see Equation (24.2)).
In the general case we might want to use spectral colors or use a more general
BRDF. In practice, we should have the material class contain member functions
to compute a random direction as well as compute the p associated with that
direction. This way materials can be added transparently to an implementation.
24.3 Accurate Direct Lighting
This section presents a more physically-based method of direct lighting than
Chapter 10. These methods will be useful in making global illumination algo-
rithms more efficient. The key idea is to send shadow rays to the luminaires as
described in Chapter 4, but to do so with careful bookkeeping based on the trans-
port equation from the previous chapter. The global illumination algorithms can
be adjusted to make sure they compute the direct component exactly once. For
example, in particle tracing, particles coming directly from the luminaire would
not be logged, so the particles would only encode indirect lighting. This makes