Cg Programming/Unity/Curved Glass

This tutorial covers refraction mapping and its implementation with cube maps.

It is a variation of, which should be read first.

Refraction Mapping
In, we reflected view rays and then performed texture lookups in a cube map in the reflected direction. Here, we refract view rays at a curved, transparent surface and then perform the lookups with the refracted direction. The effect will ignore the second refraction when the ray leaves the transparent object again; however, many people hardly notice the differences since such refractions are usually not part of our daily life.

Instead of the  function, we are using the   function; thus, the fragment shader could be: Note that  takes a third argument, which is the refractive index of the outside medium (e.g. 1.0 for air) divided by the refractive index of the object (e.g. 1.5 for some kinds of glass). Also note that the first argument has to be normalized, which isn't necessary for.

Complete Shader Code
With the adapted fragment shader, the complete shader code becomes:

Summary
Congratulations. This is the end of another tutorial. We have seen:
 * How to adapt reflection mapping to refraction mapping using the  instruction.