Graphics Reference
In-Depth Information
v
o
)
at each point
P
of the surface.
Because the BSDF may vary with wavelength, we include a fourth parameter:
f
s
(
P
,
Surfaces in the scene have a BSDF
f
s
(
P
,
v
i
,
may represent an actual wavelength,
or it may (as in most implementations) represent a band of wavelengths, where the
bands are typically denoted by the symbols
R
,
G
, and
B
. The same applies to
Φ
L
and
Φ
: Each depends on wavelength. For all three, the omission of the wavelength
parameter indicates summation. For instance,
λ
,
v
i
,
v
o
)
, with the understanding that
λ
v
o
):=
λ
f
s
(
P
,
v
i
,
f
s
(
P
,
λ
,
v
i
,
v
o
)
.
(31.99)
Photon mapping has, in addition to the scene description, two main parame-
ters:
N
, the total number of photons to be “shot” from the light sources, and
K
,
the number of photons to be used in estimating the outgoing radiance at any point.
The value
N
is used only in the construction of the photon map; the value
K
only
in the radiance estimation. A third parameter,
maxBounce
, limits the number of
bounces that a photon can take during the photon-tracing phase of the algorithm.
The photon map itself is a
k
-d tree storing photons, using the position of the
photon as the key. Listing 31.7 shows how the photon map is constructed.
Listing 31.7: Constructing a photon map via photon tracing.
1
Input:
N
, the number of photons to emit,
maxBounce
, how many times a photon may be reflected
a scene consisting of surfaces and lights.
Output: a
k
-d tree containing many photons.
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
define buildPhotonMap(scene,
N
, maxBounce):
map =
new empty photon map
repeat
N
times:
ph = emitPhoton(scene,
N
)
insertPhoton(ph, scene, map, maxBounce)
return map
define emitPhoton(scene,
N
):
from all luminaires in the scene, pick
L
with probability
p
=
λ
Φ
L
(
λ
)
/
λ
Φ(
λ
)
.
ph =
a photon whose initial position
P
is chosen uniformly
randomly from the surface of
L
,
whose direction
v
i
is chosen proportional to the cosine-weighted radiance at
P
in
direction
v
i
,
and with power
Φ
i
=Φ
L
/
(
Np
)
.
v
i
,
define insertPhoton(ph = (
P
,
Φ
i
), scene, map, maxBounce)
repeat at most
maxBounce
times:
ray trace from
ph.
P
in direction
ph.
v
i
to find point
Q
.
ph.
P
=Q
store ph in
map
foreach wavelength band
λ
:
=
f
s
(
Q
,
λ
,
v
i
,
v
o
)
v
o
·
n
d
v
o
, probability of scattering.
p
λ
p
=
average of
p
λ
λ
.
over all wavelength bands
if uniform(0, 1) >
p
// photon is absorbed
exit loop
else
v
o
=
sample of outgoing direction in proportion to
f
s
(
Q
,
v
i
,
·
)
v
i
=
−
v
o
foreach wavelength band
ph.
λ
:
ph.
Φ
i
(
λ
)
*
=
p
λ
/
p