Graphics Reference
In-Depth Information
Listing 32.2: A method that returns the impulse parts of a scattering model.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
void getBSDFImpulses (Vector3& w_i, Array<Impulse>& impulseArray) {
const Vector3& n = shading.normal;
Color3 F(0,0,0);
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);
if (material.glossyExponent == inf()) {
// Mirror
Impulse& imp
= impulseArray.next();
imp.w
= w_i.reflectAbout(n);
imp.magnitude
= F;
...
Listing 32.3: Further members of the SurfaceElement class.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
class SurfaceElement {
public:
...
struct Interpolated {
/ ** The interpolated vertex normal. * /
Vector3 normal;
Vector3 tangent;
Vector3 tangent2;
Point2 texCoord;
} interpolated;
/ ** Information about the true surface geometry. * /
struct Geometric {
/ ** For a triangle, this is the face normal. This is useful
for ray bumping * /
Vector3 normal;
/ ** Actual location on the surface (it may be changed by
displacement or bump mapping later. * /
Vector3 location;
} geometric;
...
The vectors tangent and tangent2 correspond to u and v above; when the
surface is modeled, these must be specified at every vertex. Using the derivative
of texture coordinates is one way to generate these; if we have texture coordinates
( u i , v i ) at vertex i , we can find a linear approximation for u across the interior of
the triangle, and from this determine a direction u in which u grows fastest. We can
then define v as n
u to get an orthonormal basis. Note, however, that this is a per-
triangle computation, and the computation of u is not guaranteed to be consistent
across triangles. Indeed, because of the mapmaker's dilemma (you can't flatten the
globe onto a single piece of paper preserving angles and distances), the consistent
assignment of texture coordinates across a whole surface is generally impossible.
It's important that any anisotropic BRDF be used only in areas where u and v are
defined consistently.
×
 
 
Search WWH ::




Custom Search