Page 23: Sky Boxes

Spring 2026 Sample Solution

One use of an environment map is a Sky Box. A sky box basically places a picture as the background, using an environment map instead of a solid color.

The idea of a sky box (and environment maps in general) is that the environment is infinitely far away (so all regular objects are in front of it). This means that moving doesn’t change what you see (if you move, the environment is still infinitely far away). Direction does matter: if you turn your head, you see different things.

A Sky Box is not just a big box (or Sphere) around the objects in the world. It needs to do special things to be “infinitely far away”.

  1. A SkyBox moves with the camera (so you can never get close to/pass through the wall). Think about it: if something is “infinitely far away” then moving towards it doesn’t make it get any closer.
  2. A SkyBox is drawn with its depth values to be infinitely far away, so any object drawn is closer than it. Think about it: if something is “infinitely far away” everything that is finite is closer.
  3. A SkyBox isn’t too huge (because then it might be beyond the far plane of the camera), but it works as if it is infinitely far because it is drawn first and #2. Think about it: “infinitely far” is beyond the “far” distance of the camera, so it wouldn’t be drawn unless we did something special.

Fake Sky Boxes

Implementing the three things listed above can be tricky. A standard approach is to make a “fake sky box”. It makes a big box (or sphere) to surround the world, and places the environment map as a texture on its surface.

This is bad for a number of reasons: the camera can move to get close to the box, which can break the illusion; it isn’t infinitely far away, so objects can move beyond it; there can be problems with it interfering with the far cutoff of the camera; etc.

Fortunately, three.js builds in correct sky boxes.

Sky Boxes in Three.js

Using a sky box in three.js is easy. Create an environment map, and assign it to the background of the Scene object. It can take any type of environment map, include a CubeTexture or an equirectangular projection map. For the CS559 Framework, we can refer to it with world.scene, given world is of class GrWorld.

Of course, confirming that the built-in SkyBoxes are really SkyBoxes is hard because it’s not well documented. I went and looked at the source code to confirm it.

Scene objects have two different slots that we can assign environments to: scene.background and scene.environment.

In Three.js, both scene.background and scene.environment are used to apply textures (usually 360-degree HDR environments) to your scene, but they serve completely different purposes in the rendering pipeline.

The short answer is: background is what the camera sees, while environment is what the 3D objects feel (in terms of light and reflection). The background creates the skybox. The environment serves as the source of reflections (for environment mapping, which we will discuss soon), and physically-based lighting (again, coming soon).

The Not-Really-A-SkyBox Exercise

Enough things on the web use the term “Sky Box” (but aren’t really “Sky Boxes”) that we will let you make “A Big Box with a texture on it that surrounds your world” for this exercise. Just make sure you realize why this isn’t really a sky box (which will make for a good exam question).

This is strange because real SkyBoxes are built-in (maybe it’s a newer feature?) and really easy.

In the past, we had students implement fake skyboxes, which is why this was called the “Not-Really-A-SkyBox Exercise”. Now, you just need to make a real skybox - which is easy. This is more about checking that you can find reasonable environment maps.

What you must do:

  1. Put some objects onto the ground plane. You can use stuff from other exercises, or just some primitives.
  2. Find (or create) a cubic texture appropriate for a SkyBox and use it.

Don’t forget to add the texture to the repo and answer the type-in box about where you got the environment!

The code goes into 05-23-01.js .

05-23-01   rubric Kinds of boxes:
view - look at the box and experiment with it
examine - look at the code for the box
edit - change the box's content
rubric - several steps are suggested in the rubric page - form elements on page in rubric
   05-23-01.html   05-23-01.js
Kind Kind of rubric items:
standard - expected from all students
advanced - used to get a better grade
creative - an opportunity to do something creative
levels - rubric item graded by selected achievement level
optional - not required, but encouraged
Description
standard correct skybox

A Hint: Finding Environment Maps

To make an environment map, you need to make a full 360 picture - one that covers all directions. Taking these with a camera can be tricky (even if you have a special lens, you have to worry about having your feet in the picture). You can try painting one. Or you can find them on the web.

In the past, we had a long section about format conversions. But now, three.js can take most common formats. If you find an equirectangular projection? Three.js can use it. If you find a high dynamic range image? No problem (three.js can even use it for lighting).

There is a slight catch. Creators often make massive environment map textures. Please don’t put these into your repository. We need to keep the file sizes small (we have to download a whole class’ assignments, and if everyone gave gigabytes of imagery and models, we would have a problem). Most places where you find environment maps provide them in various sizes. For example, at ambientcg.com, they offer the maps in sizes ranging from small (1K) to huge (16K). These numbers are the resolution (width in pixels) - the file sizes grow rapidly (the 1K image is 1.9MB, the 4K image is 26MB, the 16K image is 373MB). The small sizes are sufficient for what we are doing.

So, part of this exercise is for you to explore the web to find interesting things, and then to figure out how to identify the right format and appropriate data. If you go to ambientcg.com, you need to make good choices. Even when you find an environment you like, you need to choose the right data, and the right files in that data (hint: you probably need the .exr file). If they don’t provide an appropriate size, you will need to reduce the size.

Environment maps for backgrounds.

We saw how we can use an environment map to provide a background for our 3D graphics, and you practiced programming with environment maps.

Before we go on, now might be a good time to make a checkpoint and write out the .json for your localstore.

Next: Page  24 - Environment Mapping (Reflectance)