Graphics Reference
In-Depth Information
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
Biradiance3
biradiance
(
const
Vector4
&Q,
const
Point3
&P)
const
{
assert(C == Q);
// Distance to the light, or zero
const float
r = ((Q.xyz() - P)
*
Q.w).length();
// Powers of r
const
Vector3
rVec(1.0f, r, r
*
r);
// Direction to the light
const
Vector3
& w_i = (Q.xyz() - P
*
Q.w).direction();
const bool
inSpot = (w_i.dot(axis) >= cos(spotHalfAngle));
// Apply radial and angular attenuation and mask by the spotlight cone.
return
Phi
*
float
(inSpot) / (rVec.dot(aVec)
*
4
*
PI);
}
Listing 14.17:
PointLight
methods for photon emission.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
Power3
PointLight::totalPower()
const
{
// the power actually emitted depends on the solid angle of the cone; it goes to
// infinity for a directional source
return
Phi
*
(1 - cos(spotHalfAngle)) / (2
*
C.w);
}
Color3
PointLight::emitPhoton(
Point3
&P,
Vector3
& w_o) {
// It doesn't make sense to emit photons from a directional light with unbounded
// extent because it would have infinite power and emit practically all photons
// outside the scene.
assert(C.w == 1.0);
// Rejection sample the spotlight cone
do {
w_o = randomDirection();
} while (spotAxis.dot(w_o) < cos(spotHalfAngle));
P = Q.xyz();
// only the ratios of r:g:b matter
const
Color3
& spectrum = Phi / Phi.sum();
return
spectrum;
}
Each of the approximations and representations presented in this chapter has its
place in graphics. Different constraints—on processor speed, bandwidth, data
availability, etc.—create contexts in which they made (or make) sense. And while
processors get faster, new constraints, like the limited power of mobile devices,
may revive some approximations for a time. You should therefore regard these
not only as currently or formerly useful tricks of the trade, but as things that are
potentially useful in the future as well, and which provide examples of how to
approximate things effectively within a limited resource budget.