

This way we can sample the cubemap using the cube's actual position vectors as long as the cube is centered on the origin. If we imagine we have a cube shape that we attach such a cubemap to, this direction vector would be similar to the (interpolated) local vertex position of the cube. As long as a direction is supplied, OpenGL retrieves the corresponding texels that the direction hits (eventually) and returns the properly sampled texture value. The magnitude of the direction vector doesn't matter. Sampling a texture value from the cube map with an orange direction vector looks a bit like this:

Imagine we have a 1x1x1 unit cube with the origin of a direction vector residing at its center. You may be wondering what the point is of such a cube? Why bother combining 6 individual textures into a single entity instead of just using 6 individual textures? Well, cube maps have the useful property that they can be indexed/sampled using a direction vector.

We've been using 2D textures for a while now, but there are more texture types we haven't explored yet and in this chapter we'll discuss a texture type that is a combination of multiple textures mapped into one: a cube map.Ī cubemap is a texture that contains 6 individual 2D textures that each form one side of a cube: a textured cube.
