Lab 5: Lighting & Shading
CS 445: Computer Graphics, Fall 2017


Due Date: be ready to demo at the beginning of lab Friday, Oct 13

Goals

As in previous labs, find a partner you have not yet worked with.

This lab is going to test your understanding of the code. If there are sections you don't understand, please take time to discuss them with your partner, the other students, or the instructor.

Resources

Questions

Go over the material discussed in class and read the above references. You should be able to answer the following questions.

Part 1: Lighting and Shaders

The color we see when we look at an object is the result of the interaction between the object's base color and the surrounding lighting. The base color of the surface may be obtained in several different ways, such as by using vertex colors (Lab 2), uniform colors (Labs 3-5), or colors calculated directly in the shader (Lab 6). In this lab, we continue to use uniform colors except that the color will be modulated by the lighting.

In class, we will go over the Phong Lighting model. The lighting parameters (e.g. ambient colors, diffuse colors, ...) are set in the javascript application code and sent to the shader using uniform variables. The Phong lighting calculation using these parameters is done in the shader. It can be done either in the vertex (referred to as Gouraud Shading) or the fragment shader (referred to as Phong Shading). Phong Shading is preferred for reasons which will be discussed in class and shown below.

Start with your Lab 4 code (make a copy of the entire Lab 4 folder, renaming it, e.g. to be Lab5Lighting (or whatever). Be sure to retain your original Lab 4 code. Make the following changes to your code.

Once you have done all of the above, try running the code. Chances are you will get a lot of errors. Be patient, ask questions, and work though the errors one at a time. It can be frustrating because it isn't always obvious where the problems are. Sometimes no errors are generated yet you still don't see anything showing up on the canvas. At this point, methodically go through all the steps above to make sure you didn't skip something or interpret something incorrectly. It will take time.

Once you have the code working, do the following:

To Hand In

By the beginning of lab on the due date above, be ready to demonstrate your finished program using the Phong shaders. Present a scene that:

Then submit your code to WISE: