Tutorial 6: Lighting Calculations

Exercises:

In this tutorial:

Example code

Wave with ambient and diffuse lighting

Note that in order to perform lighting calculations, a math library is needed. For this tute we will be using the glm math library, which is a C++ library. This means you will now need to compile your code using g++ instead of gcc. Your existing C code should not need to be changed.

Specularity

Wave with added specularity

Note: the sinewave program now includes specular lighting, but this is kept here for interest and background

Currently the program does not use fixed functionality OpenGL lighting, instead it computes ambient/diffuse per-vertex lighting on the CPU in the function computeLighting(...) which is then given as the value to glColor. We will modify this function to add a specular calculation using the Blinn-Phong method. Note that these calculations should only be done if the dot product value (dp) from the diffuse calculation is greater than 0 - signifying that the surface is front and not back facing.

Per-Vertex Lighting using Shaders

Extra: Per-Pixel Lighting (Optional)

Wave with per-pixel lighting

Extra: Phong Lighting (Optional)

Resources