Skip to content

Latest commit

 

History

History

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

README.md

Lab 6 - Smooth vs Flat Shading

You may work individually on this assignment. To receive credit, demonstrate your completed program during lab or create a tag called lab06push your code (and tag) up to Bitbucket and submit the hash to D2L prior to class on the due date.

Flat and smooth shading are used to describe how the normals of a mesh are used to shade a model. When flat shading, each face of a mesh uses its true normal in lighting calculations which results in a very faceted look. When smooth shading, the normal at each vertex is an average normal of all the faces that are constructed using that vertex. When using the averaged normal in lighting calculations, the mesh appears curved, or smoothed.

In this lab, you’ll compute normals for both flat and smooth shading.

You are welcome to use the basic shapes provided in shape.h but are encouraged to load the obj files (it is more fun and useful for the EC for program 1). An obj file represents an indexed face set, which is a list of vertices followed by a list of faces. Each face is defined by three indices that reference the previously defined vertices to define a triangle. With either input (parameterized shapes or obj files), you will need to iterate over the data, compute normals, and organize the data into OpenGL buffers so that you can switch between a smooth shaded render and a flat shaded render by pressing the spacebar.

Recommended Reading

Part 1 - Normals for Flat Shading

Just like last lab, we’ll need normals in order to calculate our shading equations. This time we will not hard-code a list of normals into our shapes. Instead, we will calculate them based on the three points that make up each triangle.

It is your job to calculate the normal of each triangle. To do so, pick a single point of any given triangle and calculate the two vectors from that point to the other two points of the triangle. Take the cross product of those two points and normalize the result to get the normal. Once your normals are computed, you can can initialize a vertex array and buffer objects (or you may use the model object that I have provided).

Part 2 - Normals For Smooth Shading

To implement smooth shading on your model, you will need to calculate the normal of each vertex from all triangles in which the vertex is a member. First, you will have to identify all triangles in which the vertex is a member. Then using the same method as part 1, compute the normal of each triangle. Finally, take the average of the normals. Similar to the previous section, once you have computed the normals you can initialize the vertex array and buffer objects.

Part 2a (Extra Credit 20 points on a 100 point scale)

It is enough to store your triangles as an indexed mesh, but can receive extra credit for implementing a more sophisticated data structure (such as a doubly connected edge list).

Part 3 - (Extra Credit 10 points on a 100 point scale)

One can observe that for a mesh, the triangle representation in which each triangle is represented by data about three vertices repeats a lot of data. For example, if a vertex is part of 6 triangles we replicate all the data for the vertex 6 times. (Side question, I did not pick 6 randomly, why did I pick 6?)

Similar to OBJ files, element buffer objects is an OpenGL construct that allows us to represent a vertex once and then each triangle, is represented by an index into a vertex list. Convert the representation of the model to use element buffer objects. If you are using the provided code, you will also need to update code in the renderer class.

Things to notice

The only difference between smooth and flat shading is how the normal data of your mesh is specified. This means that we don't need to make any changes to our shaders. By just changing the configurations of the data that we upload to our position and normal buffers we can see a dramatic difference in how the model renders.