Due midnight 25 November 2008 (before Thanksgiving break)
For this assignment you will implement Gouraud shading for polygons with ambient and point light sources. The end result will be a complete 3D z-buffer rendering system with lighting and shading. If you decide to implement Phong shading as an extension, you may skip the Gouraud shading step and just go straight to Phong shading.
To implement shading, you will create two new functions Polygon_shadeFill and Module_shade by first copying and then modifying Polygon_drawFill and Module_draw, respectively. That way you will always have a working system for testing the geometry of your scenes. The definitions for the functions are given in the complete graphics spec.
We'll also finally implement the Color class, which consists of three floats (r, g, b) and is described fully in the graphics spec. The light source objects and functions will complete the new functions.
The major steps are as follows.
- Create the light source data type and supporting functions
- Create the Vector functions, if you haven't already done so.
- Create the Color_calcShading function that calculates the appearance of a surface given the relevant parameters.
- Create the new Polygon_shadeFill algorithm and test it on a hand-created polygon to see if the colors interpolate cleanly. Give all the vertices the same z value to avoid problems with perspective project. Calculate the colors using an ambient and a point light source and the shading function defined in the prior step.
- Add the functions to the Module class for handling body and surface colors and the surface reflection coefficient. These additions will also involve changes to the Element_init function.
- Create the Module_shade function by first copying the Module_draw function and then modifying it to handle the body reflection, surface reflection, surface coefficient cases. These will behave just like the way color is currently handled.
- Test your system on this simple image of a single cube. Here are the shading outputs for the point light source when the program is run with no arguments and the case where the program gets an argument of 30.
- You can also test your system using the cubismShade.c program. The result should be similar to last week, but with variations in shading as the cubes rotate.
- Run the example program test.ply using the command:
Implement Gouraud shading for polygons, which means you need to calculate shading at the vertices of the polygon. The simplest way to do this is to place the light sources in world coordinates and make the color calculations after multiplying the polygon by the LTM and GTM matrices. Therefore, your polygon case will end up looking something like the following.
case ObjPolygon: Copy the polygon data to a temporary polygon P Transform P by the LTM Transform P by the GTM Calculate the color at each vertex using P Transform P by the VTM Homogenize the X and Y coordinates Call Polygon_shadeFill with P and the vertex colors
./testply starfury.ply 135
Note that you will need the three files below. The first is the test program, the second goes in your library and enables your system to read in .ply files, and the third is the .ply file itself. Note, you may have to modify the read function depending upon the specific fields in your polygon structure. Also, the program makes a system call to convert, so if your system does not have the ImageMagick package installed, either install it or reduce the size of the image from 2000x2000 to 500x500 using a different image reduction tool.
Feel free to create your own .ply models. Several of the Stanford models are available in that format. To obtain the models, you can peruse the Stanford 3D Scanning Repository. Also, 3D modeling programs like Blender3D (which is freely downloadable), can save models in the .ply format.
- Implement Phong shading instead of Gouraud shading. This requires interpolating the surface normals and surface locations (in world coordinates) across the polygon.
- Make an example that would be a useful demonstration of the shading concepts.
- Build a full scanline rendering system that executes all polygons in one pass.
- Build an A-buffer system instead of a z-buffer system so you can do transparency (and shadows).
- Make interesting models, like planets and spheres.
- Make cool pictures and animation sequences.
- Handle aliasing issues at boundaries by using the centroid value of polygons to determine which of two polygons of similar depth is really in front.
All writeups should suggest the format of a lab report. They do not have to be long, but need to provide enough information that I have some idea you knew what you were doing.
- Abstract: 200 word description (at most) of what you did and a picture to go along with it.
- Description of the task, in your own words. Be brief, but write it as though explaining it to a fellow student not in the course.
- Description of how you solved the task, including any key equations or algorithms. You should also include algorithms or descriptions of what you did for any extensions. Include pictures here.
- More pictures. Please put a caption on each picture explaining something about it. If you have nothing else, give it a name and indicate whose picture it is.
- Summary of what you learned.
Put your code files in your handin folder. Send the prof an email with the URL for your writeup (wiki or standard web page) when it's done. In either case, please edit the assignment handin page on the wiki so there is a link to your assignment.