Written Questions Due: Thursday, Oct 31st by 12:30/2:00 PM (in class)

Program Due: Tuesday, Oct 31st by 11:59 PM Late assignments will be penalized 20 points per day.

0. Getting Started

Download CS370_Assign03.zip, saving it into the assignment directory.

Double-click on CS370_Assign03.zip and extract the contents of the archive into a subdirectory called CS370_Assign03

Navigate into the CS370_Assign03 directory and double-click on CS370_Assign03.sln (the file with the little Visual Studio icon with the 13 on it).

If the header files are not already open in the main window, open the header files by expanding the Header Files item in the Solution Explorer window and double-clicking lighting.h and materials.h.

If the source file is not already open in the main window, open the source file by expanding the Source Files item in the Solution Explorer window and double-clicking Limelight.cpp.

1. Written Questions

  1. Whenever large polygons are rendered with lighting in OpenGL, instead of having relatively uniform shading they are bright in one area and dimmer in others. Explain why this occurs and how this problem can be avoided. Furthermore, why are the light sources applied to every object instead of considering whether or not the light is blocked from one object to another, i.e. our lights do not cast shadows?
  2. For specular reflections, the equation in the Phong model involves the angle between the reflection vector and the viewer vector, i.e. rv. To avoid this computation, if v is in the same plane as l, n, and r we can compute the halfway vector (the vector that is halfway between l and v, see hint below) as

    h = (l + v)/(|l + v|)

    Show that the angle ψ between n and h is half the angle φ between r and v. In otherwords, show

    2 ψ = φ

    Note that this means that since we already have the vectors n, l, and v from the application, we can approximate the specular term without computing r but instead just compute h and find nh.

  3. (10 points) Derive the shadow matrix given by

    image

    and show how this matrix combined with the two light position translations produces the shadow coordinates

    image

Hints:

  1. Recall that the angle of incidence (θ between l and n) equals the angle of reflection (θ between n and r) and the vector h is halfway between l and v.

    image

  2. Recall that the shadow matrix is found by considering the light source to be translated to the origin by an amount (-xl, -yl, -zl) as shown in the figures below.

    image

    Therefore if we look down the z-axis for the translated polygon (right hand figure) we have the following

    image

    where x’ = x - xl and y’ = y - yl are the translated object coordinates, -yl is the translated position of the shadow (which originally was on the x-z plane), and xp0 is the translated shadow coordinate. Use similar triangles to determine the projection equations for xp0 and zp0. (Note that yp0 = -yl).

    Use these equations to find the shadow matrix by letting xs = x’, ys = y’, zs = z’, and the translated homogeneous component of the shadow vertices ws = y’ / (-yl).

    Then finally apply the translation back to the original position by adding (xl, yl, zl) to the projected shadow coordinates (and recalling that xs = x - xl, ys = y - yl, and zs = z - zl).

2. Programming assignment

Write a program that draws a 3D stage scene with three “actors” and several lights using OpenGL. A sample executable is available in the skeleton zip file. The scene should include:

Hints:

You may use GLUT objects for the various “actors”, but the stage must be made manually (with recursive subdivision).

Consider how to properly pan and tilt the light sources, in particular the position should remain fixed but the direction will need to be adjusted.

Create different light sources. Utility functions are provide in lighting.h to set the different types of light sources.

Create various interesting materials for the objects.

DEVELOP INCREMENTALLY. For example, draw the geometry with solid colors, then attempt to add each spotlight individually. Once the lights are rendering properly, then work on adding shadows.

Grading Criteria

The program MUST compile to receive any credit (so develop incrementally).

For up to 70% credit: Draw the basic scene with a recursively subdivided stage, static objects, fixed spotlights, but no shadows.

For up to 75% credit: Draw the basic scene with a recursively subdivided stage, animated objects, fixed spotlights, but no shadows.

For up to 80% credit: Draw the basic scene with a recursively subdivided stage, animated objects, movable spotlights, but no shadows.

For up to 85% credit: Draw the basic scene with a recursively subdivided stage, animated objects, movable spotlights, and fixed shadows.

For up to 90% credit: Draw the basic scene with a recursively subdivided stage, animated objects, movable spotlights, and moving shadows.

For above 90% credit: Be creative! For example, enhance the geometry of the scene, use additional animations, have the lights toggle on/off, allow the colors of the lights to change, and/or provide enhanced shader lighting. Remember that the program should still have reasonable performance on the lab machines.

Compiling and running the program

Once you have completed typing in the code, you can build and run the program in one of two ways:

(On Linux/OSX: In a terminal window, navigate to the directory containing the source file and simply type make. To run the program type ./Limelight.exe)

The output should look similar to below (note colors and shapes do not need to be exactly identical but should demonstrate an understanding of the concepts)

image

To quit the program simply close the window.

Submitting to Marmoset

To submit your completed assignment, open a cygwin terminal window, navigate to the working directory and type:

make submit

Then enter your Marmoset id and password. You should see a confirmation that the file was submitted successfully.

Login to Marmoset - https://cs.ycp.edu/marmoset

You are responsible for making sure that your submission contains the correct file(s).