# teaching machines

## CS 455 Lecture 8 – Calculating Normals

February 19, 2015 by . Filed under cs455, lectures, spring 2015.

### Agenda

• what ?s
• finding Playdoh normals
• finding normals of a model

Here’s what you know:

• The positions of five vertices.
• Connectivity information (e.g., vertices 0, 1, and 2 form a face).
• Vector operations: you can add 3D quantities, subtract them, take their dot product (which tells you the cosine of the angle between them), their cross product (which produces a vector perpendicular to its two operand vectors), make them have unit length, etc.

Now, do this:

1. Take a canister of Playdoh.
2. Create three triangles made of five vertices.
3. Model how one might determine the normals.

### TODO

Let’s generalizing our shading routine to work with an models, not just spheres. Complete the following steps as a lab exercise, and email me a screenshot of your shaded model.

First, sync and pull the changes down from Bitbucket.

1. Add an out parameter for the vertex normals, a list of Vector4s.
2. Allocate adequate space for these normals, and zero them out.
3. On reading a face, mentally label the vertices A, B, and C.
4. Find two vectors tangent to the face (like B – A and C – A).
5. Calculate the face’s normal as the cross product of these two vectors. Normalize.
6. Add the face’s normal on to the normal of each of its three vertices.
7. When all geometry has been process, renormalize the vertex normals.

In the Initialize routine:

1. Upload the normals as another vertex attribute. &normals gives you a pointer the first normal’s x-component.
2. Load in suzanne.obj or some other non-sphere model.