CSCE 441: Computer Graphics

Fall 2017


Assignment 4: Polygon Rasterization [150 points]

Due 11/1/2017

Purpose:
This assignment is designed to help you understand the complete polygon rasterization process. In particular, you will implement simple projection into 2D screen space, lighting/shading calculations and hidden surface removal.

Description:
In this assignment you will write a program that reads in a common 3D model format and displays the surface on the screen using 3 different shading models. We will assume that you have a working 2D scan converter from Assignment 2. If not, you may use this simple scan converter I wrote. You will NOT be using OpenGL to perform polygon rasterization, lighting calculations, transformations or hidden surface removal. For the purposes of this assignment, you do not need to worry about any of the view transformations. That is, you can assume that no transformations are required, and you can perform your lighting calculations directly on the 3D positions. We will assume that the viewer is infinitely far away (orthographic projection) at [0, 0, -infinity]. Therefore, to project the polygons onto the screen, you simply need to remove the z-coordinate. You can assume that the projected x,y position of the vertices of the triangle will be in the bounding box [-1,-1] (lower left), [1,1] (upper right). You will need to transform these coordinates into window coordinates ([0,0], [w,h]). Furthermore, you do not need to worry about clipping or performing perspectively correct interpolation (viewer at infinity) either. Note that because we limit the primitives to triangles, your scan-conversion process can be simpler than a general polygon scan-conversion routine.

The scene itself will be specified with an ambient light amount of [.5, .5, .5] and an infinitely far away light source, which is emanating light in the [-1, -1, 1] direction and has an intensity of [1, 1, 1]. Finally, the object should have an ambient reflection coefficient of [.1, 0, 0], a diffuse reflection coefficient of [.7, 0, 0], a specular reflection coefficient of [.5, .5, .5] and a specular exponent of 5. The surface will be specified using a simplified version of the OBJ file format. The file is a text-based, format where each line either starts with a
  • "#": a comment meaning that the rest of the line should be ignored,
  • "v": a vertex followed by 3 floats (separated by spaces) indicating the x, y, z positions of that vertex. These vertices are considered ordered and have an index equal to the order in which they appear... starting at 1.
  • "f": a face followed by 3 positive integers (separated by spaces) indicating the indices of this face from the vertex list
You should calculate normals at the vertices of the mesh for Gouraud and Phong shading by averaging the normals of all of the faces touching that vertex. You may compute a simple average or an area-weighted sum for these normals. If (v1,v2,v3) are the vertices of the polygon, the direction of the normal is give by (v3-v1)X(v2-v1). You do not have to use spherical interpolation for phong shading and may use simple linear interpolation of normals.

Here are some example surfaces for you to try out: cube, sphere, cow, cube2. Cube2 should show obvious differences between the 3 shading algorithms.

Here is what they should look like with a few of the rendering methods: box flat, sphere flat, sphere Gouraud, cow flat, cow Gouraud, cube2 phong.

You should write a program that:
  • Takes a single command-line argument indicating the name of the OBJ file to rasterize.
  • Draws the model on the screen with hidden surface removal using flat shading to start with or when the user presses "1", Gouraud shading when the user presses "2", and phong shading when the user presses "3".
Grading:
[10] Correctly loading obj file
[10] Correct calculation of normals
[10] Projection of vertices and transformation into window coordinates
[20] Correct lighting calculations
[20] Flat shading
[30] Gouraud shading
[30] Phong Shading
[20] Z-buffer for hidden surface removal