CS 354 Computer Graphics
Project #3 Lighting and Shading
Assigned - November 1
Due - November 18 (Midnight)
Project 3 will build upon the programs from Project 1 and 2. You are to implement lighting and shading models with at least three light sources, using the OpenGL lighting and shading facilities as well as basic texture mapping capabilities.
Your modified 3D object browser should provide the users with interactive access to the capabilities of OpenGL lighting support. The lights should be point sources which could be directional light or positional light. Your program should support at least these two light types. You can fix the positions of the lights or interactively control the positions of the lights (for extra credit). In addition, you should be able to change all light color parameters (RGB values for GL_AMBIENT, GL_DIFFUSE and GL_SPECULAR) for any light using your GUI. Besides, your program should set the Gouraud shading mode to get smooth-shaded object displays.
You should also provide interactive control over the material properties of the object. Ambient, diffuse and specular reflectances, emission and shininess of the surface, at the entire object level, should be modifiable from your GUI. Your program interface should have a "Light On/Off" submenu to enable any light or turn it off. Program interface should also have a "RESET" submenu to set the 3D object to its original state. The translation, rotation and zoom in/out features specified in the earlier projects should also work in this assignment.
In addition your program should now handle simplified PPM texture map nodes in VRML files. These texture map nodes will specify a PPM file to be read in and used as a texture map, using standard OpenGL texture map capabilities. A PPM file is a portable pixmap. See the course web page for more documentation. Attached at the end of this document is a sample C code fragment that can read a PPM file into an array which can be passed to the glTexImage2D routine. The new VRML models with texture map nodes should be made available to you in the course web page.
Chapter 5 in "OpenGL Programming Guide" has lots of information about lighting facilities in OpenGL.
We will assume students are familiar with Xwindows or whatever alternative GUI programming environment they plan to use.
Neider, Davis and Woo, "OpenGL Programming Guide" Third Edition, Addison-Wesley
Questions Related to Project (10% of project score)
1. Explain the computational differences between Gouraud shading and Phong shading of polygons .
2. How would you program Phong polygon shading in OpenGL.
3. Read and explain Texture mipmapping .
What to turn in
This has been explained clearly in the course home page (http://www.cs.utexas.edu/users/rkolluri).
You will get 5 extra points for interactive control over the positions of the point light sources which could also be a spotlight.
char *readppm(char *fname)
int width, height;
fp = fopen(fname);
if (fp == NULL)
fscanf(fp,"P6"); /*scan in magic header code for PPM file */
fscanf(fp,"%d %d\n", &width, &height); /* read in height and width*/
res = (char *)malloc(width*height*3*sizeof(char));
if (res != NULL)
for (i = 0; i < width; i++)
for (j = 0; j < height; j++)
for (k = 0; k < 3; k++) /* copy r g b into array */
res[k + (i + j * width) * 3] = (char)val;