Simulating refraction with cube maps
Objects that are transparent cause the light rays that pass through them to bend slightly at the interface between the object and the surrounding environment. This effect is called refraction . When rendering transparent objects, we simulate that effect by using an environment map, and mapping the environment onto the object is such a way as to mimic the way that light would pass through the object. In other words, we can trace the rays from the viewer, through the object (bending in the process), and along to the environment. Then we can use that ray intersection as the color for the object.
As in the previous recipe, we'll do this using a cube map for the environment. We'll trace rays from the viewer position, through the object, and finally intersect with the cube map.
The process of refraction is described by Snell's law, which defines the relationship between the angle of incidence and the angle of refraction.
Snell's law describes the angle of incidence...