Game Development Reference
In-Depth Information
Vertex normals are based on the same idea, but rather than specifying
the normal per polygon, we specify them for each vertex that forms the
polygon (see Figure 5.2).
Figure 5.2: The vertex normals of a surface
Direct3D needs to know the vertex normals so that it can determine
the angle at which light strikes a surface, and since lighting calculations
are done per vertex, Direct3D needs to know the surface orientation
(normal) per vertex. Note that the vertex normal isn't necessarily the
same as the face normal. Sphere/circle approximations are good exam-
ples of objects where the vertex normals are not the same as the
triangle normals (see Figure 5.3).
Figure 5.3: An example where vertex normals are dif-
ferent from the face normal. The bolder vectors denote
the vertex normals, while the lighter vectors denote the
face normals.
To describe the vertex normal of a vertex, we must update our vertex
structure:
struct Vertex
{
float _x, _y, _z;
float _nx, _ny, _nz;
static const DWORD FVF;
}
const DWORD Vertex::FVF = D3DFVF_XYZ | D3DFVF_NORMAL;
Notice that we have removed the color member that was used in the
last chapter. This is because we are using lighting to compute the col-
ors of our vertices.
For simple objects such as cubes and spheres, we can see the ver-
tex normals by inspection. For more complex meshes, we need a more
mechanical method. Suppose a triangle is formed by the vertices p 0 , p 1 ,
Search WWH ::




Custom Search