Graphics Reference
In-Depth Information
Listing 32.1: Part of an implementation of Blinn-Phong reflectance.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
Color3 SurfaceElement::evaluateBSDFfinite(w_i, w_o) {
n = shading.normal;
cos_i = abs(w_i.dot(n));
Color3 S( Color3 ::zero());
Color3 F( Color3 ::zero());
if ((material.glossyExponent != 0) && (material.glossyReflect.nonZero())) {
// Glossy
// Half-vector
const Vector3 & w_h = (w_i + w_o).direction();
const float cos_h = max(0.0f, w_h.dot(n));
// Schlick Fresnel approximation:
F = computeF(material.glossyReflect, cos_i);
if (material.glossyExponent == finf())
S= Color3 ::zero()
} else {
S=F * (powf(cos_h, material.glossyExponent) * ...
}
}
...
The surface normal is used immediately to compute cos
θ i , an example of express-
ing one of the two input vectors in the local frame of reference. The half-vector
( direction() returns a unit vector) is computed from
v o , which are called
w_i and w_o in the code. The Schlick approximation of the Fresnel term is com-
puted and used to determine the glossy reflection. The remainder of the elided
code computes the diffuse reflection. Missing from this code are the evaluations
of the mirror-reflection term and of transmittance based on Snell's law, each of
which corresponds to an impulse in the scattering model. The splitting off of these
impulse terms makes the computation of the reflected light much simpler. Recall
that what we've been expressing as an integral, namely,
v i and
L ( P ,
v i ) f s (
v i ,
v o )
v i ·
n d
v o ,
(32.3)
v o S + ( P )
is really shorthand for a linear operator being applied to L , one that is defined in
part by a convolution integrand like the one above, and in part by impulse terms
like mirror reflectance, where for a particular value of
v i , the integrand is nonzero
only for a specific direction
v o ; the value of the “integral” is some constant (the
impulse coefficient) times L ( P ,
v i ) .
Trying to approximate terms like mirror reflectance by Monte Carlo integra-
tion is hopeless: We'll never pick the ideal outgoing direction at random. Fortu-
nately, these terms are easy to evaluate directly, so no approximation is needed.
The SurfaceElement class therefore provides a method (see Listing 32.2) that
returns all the impulses needed to evaluate the reflected radiance (in this case,
the mirror-reflection impulse and the transmission impulse, although if we were
rendering a birefringent material, there would be two transmissive impulses, so
returning an array of impulses is natural).
G3D is designed around triangle meshes. The SurfaceElement class therefore
contains some mesh-related items as well (see Listing 32.3).
 
Search WWH ::




Custom Search