Skinned Surfaces

text only
 
progress indicator progress indicator progress indicator progress indicator

Finding Surface Normal Vectors

Each point on a surface has a normal vector that is perpendicular to the surface at that point. These vectors are nearly as important as the position because they really define how the surface will interact with any other entity in the game world. For instance, the normal vector defines how light will be reflected, refracted, or absorbed. The normal vector also tells you the angle of the surface at that point. This can be useful for terrain because you want objects to be correctly aligned as they move over rolling hills. In this book, I will use the normal vector for lighting calculations, both because it is extremely common and because lighting helps you see the shape of the surface. When a surface is a flat plane, it is very easy to conceptualize and compute the normal vector. On a curved surface, it is slightly harder to do both, but as you will see, you already have all the tools you need to do this.

If you have ever computed the normal vectors for vertices in a triangular mesh, you know that you can find a triangle's normal vector by taking the cross product of two of the edges. This process is shown in Figure 7.4. The cross product is discussed in Appendix B, "A Quick Look at Vectors."


Figure 7.4: Finding the normal vector of a triangle.

For any two vectors, the cross product will give you a resulting vector that is perpendicular to both ( assuming the first two are not parallel). Therefore, you can use the cross product to find the normal vector at any point on a surface if you know two vectors lie on the surface at that point. As luck would have it, you have two such vectors in the form of a tangent (slope) in the u direction and a tangent in the v direction. These two tangents are effectively the slopes as seen in previous chapters. Now, instead of dP/dt, you have dP/du and dP/dv. The cross product of these two vectors will give you the normal vector, but first you need to find the derivatives of Equation 7.1 with respect to u and v.

Appendix A ends with a very brief overview of partial derivatives. You might want to review that section if you haven't already. When you apply the concepts from Appendix A to Equation 7.1, you get the partial derivatives with respect to u and v as shown in Equation 7.2.

As usual, these equations are actually computed for each (x, y, z) component. Figure 7.5 shows the tangents on a surface. Notice that they are simply the slopes in the u and v directions. The grid is aligned such that u and v align with x and z so that the tangents are easier to visualize, but this is not a requirement. In Chapter 9, "NURBS Surfaces," you will see an example where the grid itself is more irregular.


Figure 7.5: Tangents on a surface.
(7.2) Derivatives with respect to u and v. 

Equation 7.2 will give you two tangent vectors, but you still need to take the cross product if you want the normal vector. Equation 7.3 shows the final equation for the normal vector at any point on a Bezier surface.

(7.3) Computing the normal vector. 

Figure 7.6 shows the resulting normal vector.


Figure 7.6: Normal on a surface.

Although Equations 7.2 and 7.3 focus on Bezier surfaces, the basic process of computing the normal vector for a surface will apply to all the surfaces shown in the coming chapters. As you have seen with curves, the basis functions change, but the underlying concepts remain the same. Equation 7.3 applies to all surfaces. Once you have computed the normal, you can apply basic lighting equations.

Note 

When computing the normal vectors for vertices on a polygonal surface, it's best to average the normals of all the faces that share a particular vertex. In the case of parametric surfaces, you compute the normal vectors directly. There is no need to average them from polygons because you already have the mathematical definition of the surface.

progress indicator progress indicator progress indicator progress indicator


Focus on Curves and Surfaces
Focus On Curves and Surfaces (Focus on Game Development)
ISBN: 159200007X
EAN: 2147483647
Year: 2003
Pages: 104
Authors: Kelly Dempski

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net