Workbook 6: Efficiency, Hardware and Shaders

Spring 2026 Sample Solution

This is a sample solution for the Workbook. You are welcome to refer to it to learn one way to do the assignment but only after you have turned in your own assignment

So far, we’ve programmed graphics using high-level APIs. In this workbook, we’ll look under the hood a bit. This is important because it will help us understand why we do things the way we do. This will help you understand the motivations for the techniques we choose (e.g., why we use environment mapping for reflections). It will help you understand why we need tricks to create shadows. It will help you understand why we prefer to use texture maps. Additionally, it will help you understand how to program the graphics hardware.

Workbook Operations

The workbook uses both type-in forms that rely on browser local storage and “page boxes” that are files that must be checked in to GitHub.

Right now, please put your name on the workbook and press the “checkpoint” button so that we know that you have at least seen this workbook.

This workbook contains type-ins that are part of the assignment. Some of these have specific rubric checkboxes at the end of the page.

The checkboxes for boxes and rubric elements are to help students keep track of their work. The Last Page (rubric) page has a list of all boxes and rubric items.

Remember to save your local storage to the JSON file periodically in case something goes wrong. You should also make a checkpoint periodically.

Remember to commit your work as you edit files in for_students (you should not need to edit files outside of that directory). Remember to push your work to GitHub - at least at the end, or periodically after you commit, to make a backup. When you have completed the workbook, remember to use the submit button on the last page to signal us that your workbook is ready for grading.

We only grade the main branch. It must be pushed to GitHub. You must also use the “submit” button.

You will probably add files to the workbook (especially textures). Remember to add them to the repository, so they will be committed and pushed.

This workbook is set to be released on Sunday, November 15, 2026. It is due on Sunday, November 29, 2026, with late assignments accepted until Sunday, November 29.

This workbook is more “learn about stuff” than “try things by programming”.

Overview

This workbook has three distinct parts:

  • Part 1: Foundations - We’ll learn the basic algorithms actually used to do the drawing. We’ll see how the graphics hardware implements these quickly, but how that efficiency comes at a cost: we can only do things a particular way.
  • Part 2: Hacks - The limitations of the paradigm that the graphics hardware implements mean that we need to use special tricks to achieve certain effects like shadows or dynamic reflections.
  • Part 3: Shaders - The flexibility of modern graphics hardware means we can program it directly. However, this is only possible within the paradigm that the hardware implements.

Overall, we have the following learning goals:

  1. Understand the fundamental challenges of discrete representations (aliasing).
  2. Understand the key algorithsm used in interactive graphics and this leads to the pipeline model.
  3. Understand the affordances and limitations of the pipeline model in terms of performance and visual effects
  4. Understand and apply methods such as dynamic textures and shadow maps in order to create visual effects within the rasterization model
  5. Understand the basic organization of graphics hardware, and how programmability fits into it.
  6. Learn how the shader programming paradigm leads to specific, real implementations.
  7. Write shaders in shading languages and apply them with system interfaces.
  8. Apply key shader strategies for anti-aliasing and similar problems
  9. Appreciate shader composition approaches as a way to build complex shaders

Part 1 (foundations) is a bit more content learning than practice learning. You may never need to implement triangle rasterization (the process of converting triangles into pixels): the graphics hardware (or at least the API) implements it for you. However, if you don’t understand it, parts 2 and 3 won’t make sense.

Part 2 (hacks) gives you techniques for shadows and dynamic reflections that can work with current graphics hardware. Fortunately, the methods are implemented within three.js. However, if you don’t understand the methods, you won’t understand their limitations and why they sometimes break.

Part 3 (shaders) will give you the opportunity to program the graphics hardware. This can be a way to achieve some cool effects. However, it can be tricky, because you need to work within the weird programming paradigm (see #1).

A Bit on Shader Programming…

In order to do shader programming, we need to pick some shader language that is well-supported on the platform that we use. We also want something simple that exposes the concepts in a way that fosters learning.

We will explain this in more detail when we introduce shading languages.

Unfortunately, the practice of what graphics programmers are actually doing is diverging from what is pedagogically clean for class. Old shader languages were widely supported and exposed the hardware. In practice, graphics and game programmers needed more convenient systems that let them do complicated things. So, the old, simple languages are going away.

In this workbook, we will ask you to do some shader programming in GLSL - the shading language used for WebGL. However, the world is moving away from this. Three.js only supports GLSL in legacy mode (which we will use for that part of the workbook).

We will also show you TSL (the Three.js shading language). Unfortunately, it is new and not very well documented. Furthermore, it is specific to three.js. However, it is similar to the kinds of shading languages provided by other, high-level graphics APIs.

I will try to make the workbook self-contained. That means there is a lot of content.

Even when we used the textbook, the textbook chapters did not cover these topics well. We relied on lectures.

For shader programming, we relied on ancient resource materials. GLSL never had great documentation. We relied on ancient books from even older languages.

Be aware that many resources talk about using GLSL with OpenGL. The version of GLSL used in WebGL (OpenGL ES) is slightly different from the “real” OpenGL GLSL. In particular, WebGL only supports GLSL-ES (and not always the most recent version). Check the WebGL Reference Card to see what is supported. The GLSL ES shading language (used in WebGL) is a subset of regular OpenGL GLSL. Generally, things just work, but sometimes, things are missing.

Also, a lot of the resources for GLSL with OpenGL talk about the interface between C++ and GLSL, which is quite complicated. In WebGL, the JavaScript to GLSL interface is somewhat better. But for class, we will let THREE.js take care of it for us.

Get Started on Page  1  (Recap: Appearance by Shading and Texturing)!