Lab 5: Lighting & Shaders
CS 445: Computer Graphics, Fall 2012


Due Dates:
Part 1: 5pm, Thursday, Nov 1
Part 2: 5pm, Tuesday, Nov 6

Goals

Resources

Part 1: Questions

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

The Car

You are already familiar with the Phong lighting model which you implemented in your ray tracer. In this part of the lab, you are to understand the Phong lighting model as implemented in the shaders. There are two common ways of doing this:

The base color of the surface may be obtained in several different ways. We will discuss each of them:

Start with the car navigation program you used from the last lab. Your job is the modify it so that it can handle lighting. Here are the changes you need to make:


Car with Gouraud Lighting


Car with Phong Lighting

No later 5pm on Thurs, Nov 1, demonstrate this part of the lab (no need to submit this part of the code via WISE Assignments).

Part 2: Fractal Landscape

This part of the lab will take some work so please get started early!

Download the zipped file containing the files FractalLandHeights.cpp and FractalLandHeights.h, which will generate a height map, i.e. a 2-dimensional grid of values that represent heights (the y-value) on a square grid (x and z). Read the comments at the top of FractalLandHeights.cpp to see what it does and how the heights are stored.

You need to create a new class e.g. called FractalLandShape (along the lines of the Cube or Disk) which takes the heights and generates a list of triangles (vertices) and normals. You need to think about how to calculate the normals efficiently. Note, the normal at a vertex needs to be the average of the normals of the surrounding triangles. Work it out first with pencil and paper.

The colors can either be implemented in your FractalLandShape class as a colors array or you can choose to implement the color as a color map in the shader (your choice). Either way, you will need to write a color map function which takes a y-value and returns a color. GLSL has some nice smoothing functions which you can use if you do it in the shader (preferably fragment over vertex, for the same reason Phong Lighting is better done in the fragment shader).

In main.cpp, create a new FractalLandShape object and render it. Include a light source which you can move around (along x, y, z). Include a cube that sits at the light location. Moving the light will help you test whether your normals and light location are set properly.

No later 5pm on Tues, Nov 6, demonstrate your program in lab and submit this code via WISE Assignments.