CPSC 424 Computer Graphics Fall 2025

CPSC 424 Lab 4: Shading

Due: Tue 9/30 at the start of lab

This lab adds shading to the programmable pipeline structure from lab 3.

Successful completion of this lab means that you:

Collaboration and Use of AI

This is an individual lab. You may get technical help from others, but the effort and ideas that go into producing solutions should be yours.

You may use AI as outlined in the Use of AI policy — Copilot's inline coding suggestions, explain, fix, review and comment features but not code generation from English prompts. Also:

Handin

Hand in your work by copying your ~/cs424/lab4 folder into your handin folder (/classes/cs424/handin/username, where username is your username).

Check that the result is that your files are contained in /classes/cs424/handin/username/lab4 — if not, fix it!


Preliminaries

Setup

Make sure that your lab4 directory is named exactly like that and is at the same level in your workspace directory. This is important so that the relative path names used to access common files remain the same so your program doesn't break when you hand it in.

Live Preview Fixed!

Live Preview now appears to be working on all Linux platforms! (VDI, Demarest 002, Lansing 310) Please let me know if you encounter issues.

Reference

Your best reference sources are the slides from class (which pull out and organize the key points), the examples from class (which put all the pieces together), and the textbook.


Exercises

Lighting Demo

The provided lighting-demo.html file adds basic lighting to the graphics pipeline. The lighting model implemented is similar to what was discussed in class — it includes diffuse and specular terms, supports point and directional lights, and does per-vertex lighting. There is one addition, which is a shader parameter for the light color instead of using a hardcoded white light.

Lambert Shading

The Lambert illumination model captures diffuse reflection and is appropriate for matte surfaces. The lighting model includes the ambient and diffuse terms discussed in class (no specular term) and is combined with flat or Gouraud shading (per-vertex lighting with interpolated colors).

Handling ambient light: Rather than including a global ambient term as in the lighting model discussed in class, implement an "ambient contribution" from each light source (as it works in OpenGL 1.1). Also take the material's ambient color to be the same as its diffuse color. This means that the ambient term will be md ai Is (where ai is the fraction of the light's intensity that goes towards the overall ambient light in the scene, a value 0-1) instead of ma Ia from class.

Phong Shading

The Phong illumination model captures specular reflection and is appropriate for shiny surfaces. The lighting model includes all three of the terms discussed in class (ambient, diffuse, and specular) and is typically combined with the Phong interpolation method (per-pixel lighting with interpolated normals).

The ambient term will be handled the same way as in the previous exercise.

Cel Shading

Cel shading was discussed in class on Monday (9/23); see the posted slides.

This style of shading looks best with a black outline around the edges of the object. How to achieve this was discussed in class — the strategy is to first draw the back faces slightly larger, then draw the front faces normal sized. For smooth surfaces approximated by a polygon mesh, "slightly larger" can be achieved by displacing the vertex coordinates a small amount along their normals. In particular, to achieve the silhouette effect:

Gooch (Cool-to-Warm) Shading

Gooch shading was discussed in class on Monday (9/23); see the posted slides.