teaching machines

CS 455 Lecture 8 – Calculating Normals

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

Agenda

Think About This

Here’s what you know:

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.

In the OBJ reader routine:

  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[0][0] gives you a pointer the first normal’s x-component.
  2. Load in suzanne.obj or some other non-sphere model.

In the vertex shader:

  1. Declare the normal as a second vertex attribute.

Haiku

Why did u cross v?
To get to the other side?
No, that’s reflection

So why did they cross?
To get where neither could get
In and of themselves