Graphics Reference
In-Depth Information
Listing 32.14: Tracing photons, which is rather similar to tracing rays or paths.
1
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
35
36
37
38
39
40
41
42
43
44
45
46
47
void App::photonTrace(const EPhoton& ep, Array<IPhoton>& ips) {
ips.fastClear();
photonTraceHelper(ep, ips, 0);
}
/ **
Recursively trace an EPhoton through the scene, accumulating
IPhotons at each diffuse bounce
* /
void App::photonTraceHelper(const EPhoton& ep, Array<IPhoton>& ips, int bounces) {
// Trace an EPhoton (assumed to be bumped if necessary)
// through the scene. At each intersection,
// * store an IPhoton in "ips"
// * scatter or die.
// * if scatter, "bump" the outgoing ray to get an EPhoton
// to use in recursive trace.
if (bounces > m_maxBounces) {
return;
}
SurfaceElement surfel;
float dist = inf();
Ray ray(ep.position(), ep.direction());
if (m_world->intersect(ray, dist, surfel)) {
if (bounces > 0) { // don't store direct light!
ips.append(IPhoton(surfel.geometric.location, -ray.direction(), ep.power()));
}
// Recursive rays
Vector3 w_i = -ray.direction();
Vector3 w_o;
Color3 coeff;
float eta_o(0.0f);
Color3 extinction_o(0.0f);
float ignore(0.0f);
if (surfel.scatter(w_i, w_o, coeff, eta_o, extinction_o, rnd, ignore)) {
// managed to bounce, so push it onwards
Ray r(surfel.geometric.location, w_o);
r = r.bumpedRay(0.0001f * sign(surfel.geometric.normal.dot( w_o)),
surfel.geometric.normal);
EPhoton ep2(r, ep.power() * coeff);
photonTraceHelper(ep2, ips, bounces+1);
}
}
}
different from the probability that one arriving in direction
v o scatters in direction
v i . Our surface really needs to provide two different scattering methods, one for
each situation. In our code, we've used the same method for both. That's wrong,
but it's also very common practice, in part because the effects of making the code
right are (a) generally small, and (b) generally not something we're perceptually
sensitive to. You might want to spend a little while trying to imagine a scene in
which the distinction between the two scattering rules matters.
One difference between photon propagation and radiance propagation is that at
the interface between media with different refractive indices, the radiance changes
 
 
Search WWH ::




Custom Search