Graphics Reference
In-Depth Information
Listing 32.6: Reflecting illumination from area lights.
1
Radiance3 App::estimateDirectLightFromAreaLights(const SurfaceElement& surfel,
const Ray& ray){
Radiance3 L_o(0.0f);
// Estimate radiance back along ray due to
// direct illumination from AreaLights
if (m_areaLights) {
for (int L = 0; L < m_world->lightArray2.size(); ++L) {
AreaLight::Ref light = m_world->lightArray2[L];
SurfaceElement lightsurfel = light->samplePoint(rnd);
Point3 Q = lightsurfel.geometric.location;
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
if (m_world->lineOfSight(surfel.geometric.location +
surfel.geometric.normal * 0.0001f,
Q + 0.0001f * lightsurfel.geometric.normal)) {
Vector3 w_i = Q - surfel.geometric.location;
const float distance2 = w_i.squaredLength();
w_i /= sqrt(distance2);
L_o += (surfel.evaluateBSDF(w_i, -ray.direction()) *
(light->power()/pif()) * max(0.0f, w_i.dot(surfel.shading.normal))
* max(0.0f, -w_i.dot(lightsurfel.geometric.normal)/distance2));
debugAssert(L_o.isFinite());
}
}
if (m_direct_s) {
// now add in impulse-reflected light, too.
SmallArray<SurfaceElement::Impulse, 3> impulseArray;
surfel.getBSDFImpulses(-ray.direction(), impulseArray);
for(inti=0;i<impulseArray.size(); ++i) {
const SurfaceElement::Impulse& impulse = impulseArray[i];
Ray secondaryRay = Ray::fromOriginAndDirection(
surfel.geometric.location, impulse.w).bumpedRay(0.0001f);
SurfaceElement surfel2;
float dist = inf();
if (m_world->intersect(secondaryRay, dist, surfel2)) {
// this point could be an emitter...
if (m_emit) {
radiance += surfel2.material.emit * impulse.magnitude;
}
}
}
}
}
return L_o;
}
In each case—the impulse and the finite-part reflection of area lights, and the
finite-part reflection of point lights—we picked some direction
v i and multi-
plied some measure of light arriving at P in direction
v i by some factor based
on the BSDF: either the impulse magnitude or the finite part of the BSDF. It's
possible to restructure the code so that the measure of light in each case cor-
responds to the biradiance described in Chapter 14, which helps explain how
the first ray tracers, which didn't really use physical units, actually managed to
produce good-looking pictures.
At this point we've computed the emissive term of the rendering equation, and
the reflected term, at least for light arriving at P directly from luminaires. We now
 
 
Search WWH ::




Custom Search