Practical 1: Shadow Mapping and GLSL programming

Summary of the Practical

The goal is to implement the shadow mapping algorithm using GLSL.

The program loads an object and displays it. The user interface lets you manipulate the object and the light source, and the shader takes care of local illumination. Your goal is to add shadow mapping to this shader, using what you learned in class.

Hardware and software requirements

Instructions

First, download and uncompress the practical. Then, compile it. The directory contains a shadowMap.pro file, which you should use to create a Makefile (if this seems strange to you, spend some time reading a Qt tutorial)

The program should compile straight out of the box (you might have to edit the .pro file to adapt it to your configuration). It takes an (optional) argument which is the name of the model. It displays this model, with no shadow. There are other models in the model directory. Try moving the light source and the object: L sets the manipulated frame for the light source, O sets it for the object. Then right-click + drag moves the manipulated frame.

The program loads the shader in shader/shadow directory. All the functions you have to edit are in editing this shader, but you should look at the code of Viewer.cpp first.

  1. First, identify the lines that load the shader and the lines where we send it its parameters.
  2. Then, identify where we create the shadowMap itself, and how we pass it as a parameter to the shader.
  3. What other parameters are we sending to the shader?
  4. Finally, open the sources of the shader, and modify the vertex shader so that it passes the right value to SM_tex_coord. Remember, in order to compute the right value for SM_tex_coord, you need to convert the vertex position from object coordinates to light coordinates (the best way is probably to go through camera coordinates). Then, you need to convert the light coordinates (in [-1,1]^3) into texture coordinates (in [0,1]^3), through a simple scaling.
  5. Once you've set up the vertex program so it computes the right value for SM_tex_coord, you can uncomment the lines in the fragment program that use this value. You should now see your shadow map. Make a screenshot.
  6. Check that your program is correct by moving the object and the light source, and verify that the shadow and lighting are behaving correctly (it is a fairly common mistake to forget about the object modelling matrix). Make a screenshot.
  7. Your shadow map probably shows heavy Z-fighting in lit areas. Add some bias (in the fragment shader this time) to remove the Z-fighting. Play with the values of the bias (with an object touching the ground), test different formulas. Make a screenshot.
  8. Try different values of the shadow map resolution (smaller, larger).
Once you're finished, send me an with: the source code for both shaders (vertex and fragment), as well as the screenshots.