Graphics Reference
In-Depth Information
Substituting Equation 29.7 into Equation 29.4, we get the form of the render-
ing equation that's most useful in practice:
v
o
)=
L
e
(
P
,
v
o
)+
L
ref
(
P
,
L
(
P
,
v
o
)
(29.8)
v
o
)+
v
i
∈
S
+
(
p
)
=
L
e
(
P
,
L
(
R
(
P
,
v
i
)
,
−
v
i
)
f
r
(
P
,
v
i
,
v
o
)(
v
i
·
n
P
)
d
v
i
.
(29.9)
This equation expresses the
surface radiance
function defined on all surfaces in
the scene, in terms of the known luminaires (
L
e
), and an integral of the known
BRDFs of all surface points (
f
r
), the ray-casting function
R
, and the surface radi-
ance itself.
The rendering equation is very nice and self-contained, but how do you
do
any-
thing with it? Let's take a quick look ahead at code from Chapter 32 to see. The
large-scale structure of a basic path tracer is:
1
2
3
4
foreach pixel (i, j)
C
= location of pixel on image plane
r = ray from eye to
C
image[i, j] = pathTrace(r, true)
Listing 29.1 shows the central
pathTrace
procedure for such a path tracer.
Given a ray (i.e., a point
U
and a direction
) this procedure traces a ray into the
scene and hits at some point
P
, and then estimates either
L
(
P
,
v
)
or
L
ref
(
P
,
)
,
depending on the boolean
isEyeRay
. The point
P
is represented by the variable
surfel
(for “surface element”) in the program.
−
v
−
v
Listing 29.1: The core procedure in a path tracer.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
Radiance3 App::pathTrace(const Ray& ray, bool isEyeRay) {
Radiance3 radiance = Radiance3::zero();
SurfaceElement surfel;
float dist = inf();
if (m_world->intersect(ray, dist, surfel)) {
if (isEyeRay)
radiance += surfel.material.emit;
radiance+= estimateDirectLightFromPointLights(surfel, ray);
radiance+= estimateDirectLightFromAreaLights(surfel, ray);
radiance+= estimateIndirectLight(surfel, ray, isEyeRay);
}
return radiance;
}
As you can see, the outgoing radiance at
P
is the sum of the emitted light
(
surfel.material.emit
) and the light reflected at
P
, estimated in the last three
procedures. The first estimates the light arriving directly from point sources that's
reflected at
P
; the second the light directly from area luminaires that's reflected