CS 455 Lecture 8 – Calculating Normals
Agenda
- what ?s
- finding Playdoh normals
- finding normals of a model
Think About This
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:
- Take a canister of Playdoh.
- Create three triangles made of five vertices.
- 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:
- Add an out parameter for the vertex normals, a list of Vector4s.
- Allocate adequate space for these normals, and zero them out.
- On reading a face, mentally label the vertices A, B, and C.
- Find two vectors tangent to the face (like B – A and C – A).
- Calculate the face’s normal as the cross product of these two vectors. Normalize.
- Add the face’s normal on to the normal of each of its three vertices.
- When all geometry has been process, renormalize the vertex normals.
In the Initialize routine:
- Upload the normals as another vertex attribute. &normals[0][0] gives you a pointer the first normal’s x-component.
- Load in suzanne.obj or some other non-sphere model.
In the vertex shader:
- Declare the normal as a second vertex attribute.
Haiku
Why did u cross v?
To get to the other side?
No, that’s reflection
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