If you make a mesh of vertices, which is supposed to approximate a single smooth surface, how do you create a "reasonable" surface normal vector at each vertex in your mesh?
The key is to realize that when a vertex is shared by several different faces, its normal should be more aligned with the normals of the larger faces, and less aligned with the normals of the smaller faces. For example, suppose we approximate a rounded cube by bezeling the corners:
Here's how to do it:
A→B and B→CFor each pair of successive edges e1 and e2, take the cross product e1 × e2. Add the result of this cross product to the normal of every vertex that adjoins the face (for example, in this case you would add to the normals of vertices A,B,C,D).
B→C and C→D
C→D and D→A
D→A and A→B
Note that the above algorithm only works if you've defined your mesh faces so that the vertices of each face go around in a counterclockwise direction, when you're looking at the mesh from the outside. Otherwise, your normals will end up facing into the surface, rather than out of it.
It is always a good practice to define mesh faces so that their vertices are sequenced in a counterclockwise direction. Many algorithms in computer graphics rely on the use of this convention.