Six images arranged as a box

Skyboxes & cube maps

A cube map is a texture you index with a direction rather than a coordinate pair. Hand it a vector, it works out which of six faces that vector points at and samples there. Use the direction you are looking and you have a skybox; use the direction light bounces off a surface and you have a reflection. Same texture, same lookup, two different vectors.

The view
Drag to look around

The cube map, unfolded 6 × 128²

The yellow marker is the face and texel the centre of the view lands on. Rotate and watch it cross a face boundary — that is the only moment the hardware changes which image it is reading.

Controls scene
72°
0.00
Direction at view centre
Major axis
Face selected
Face coordinate (s,t)
The lookup, in code live

    
Skybox or cube map? the difference

The data is identical — six images on the faces of a notional cube. What differs is what you do with it.

A skybox is drawn as background. It is sampled with the view direction, ignores the depth buffer, and never moves with the camera's position — only its orientation — which is what makes it read as infinitely far away. Walk towards a mountain in a skybox and it never gets closer.

A cube map used for reflection is sampled per pixel of an object with the reflected view vector. It can be captured live from the object's own position each frame, which is why a reflective car can show the scene changing around it while a skybox cannot.

Why a cube and not a sphere. A sphere map would need only one image, but it cannot be sampled without trigonometry and it wastes resolution appallingly at the poles — the same problem the equirectangular sphere unwrap has. Six flat squares need only a comparison to find the largest component and one divide to get the coordinates, which is cheap enough to build directly into the texture unit. The price is that the corners of each face are stretched about 1.7 times more than the centres, which nobody notices and everybody accepts.