Graphics Reference
In-Depth Information
probability p of a Lambertian scattering of the incoming light. If the random value
r is less than p , we produce a Lambertian-scattered ray; if not, we subtract that
probability from r and move on to the next kind of scattering.
Inline Exercise 32.6: Convince yourself that this approach has a probability p
of producing a Lambertian-scattered ray.
The actual scattering is fairly straightforward: The cosHemiRandom method
produces a vector with a cosine-weighted distribution in the hemisphere whose
pole is at n . The method also returns the index of refraction (both real and imagi-
nary parts) of the material on the n side of the intersection point, and a coefficient,
(called weight_o here) that is precisely the number we'll need to use when we do
Monte Carlo estimation of the reflected radiance. (The returned value density is
not the probability density, but a rather different value included for the benefit of
other algorithms, and we ignore it.)
The remainder of the scattering code is similar. Recall that the reflection
model we're using is a weighted sum of a Lambertian, a glossy component, and a
Listing 32.9: Further scattering code.
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
Color3 F(0, 0, 0);
bool Finit = false;
if (material.glossyReflect.nonZero()) {
// Cosine of the angle of incidence, for computing Fresnel term
const float cos_i = max(0.001f, w_i.dot(n));
F = computeF(material.glossyReflect, cos_i);
Finit = true;
const Color3& p_specular = F;
const float p_specularAvg = p_specular.average();
r -= p_specularAvg;
if (r < 0.0f) { // Glossy (non-mirror) case
if (material.glossyExponent != finf()) {
float intensity = (glossyScatter(w_i, material.glossyExponent,
random, w_o) / p_specularAvg);
if (intensity <= 0.0f) {
// Absorb
return false;
}
weight_o = p_specular * intensity;
density = ...
} else {
// Mirror
w_o = w_i.reflectAbout(n);
weight_o = p_specular * (1.0f / p_specularAvg);
density = ...
}
eta_o = material.etaReflect;
extinction_o = material.extinctionReflect;
return true;
}
}
 
Search WWH ::




Custom Search