CPSC 424 Computer Graphics Fall 2025

CPSC 424 Lab 9: More three.js

Due: Tue 11/11 at the start of lab

three.js provides a high-level scene graph for designing WebGL scenes. This is the second of two labs using three.js. It deals with features of three.js that support more sophisticated scenes and effects: ways of building mesh objects, cubemaps, skyboxes, reflection, refraction, shadows, and (optionally) bump maps, dynamic cubemaps, and/or custom shaders.

Successful completion of this lab means that you can use three.js to:

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/lab9 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/lab9 — if not, fix it!


Preliminaries

Setup

Make sure that all of the directories are named exactly as specified and end up at the same (top) 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.

Provided Code and Files

lab9.html is a template for a three.js program.

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. Chapter 5 covers three.js.

Technical Notes

three.js Notes

Math

JavaScript has the constant Math.PI for π. Trigonometric functions like sin and cos are Math.sin and Math.cos.

Parametric Surfaces

3D Curves

2D Curves


Exercises

Use the provided lab9.html as the starting point for this lab. This is the same skeleton provided for lab 8 — it sets up the structure for a three.js program with a trackball rotator (so the mouse can spin the camera around) as discussed in class. Note that running the program will result in a blank page and an error message in the console until a scene and camera have been created. (After that you should at least see a dark gray canvas.)

General requirements:

Specific requirements:

Ideally, position elements so that it isn't obvious that the reflections and transparency don't include the other objects in the scene, though this isn't required. Optionally (extra credit), explore and use a CubeCamera to generate a dynamic cubemap for the skybox to address some of these limitations. CubeCamera is mentioned in section 5.3.5 and the API includes a code example to help get you started.

Other extra credit options include bump mapping (not covered in the slides or the textbook, but there is an example posted) and custom shaders (in the slides plus posted examples). Try implementing non-photorealistic rendering like Gooch or cel shading!