OpenGL provides a mechanism to generate s and t texture coordinates at vertices based on the current normal and the direction to the eyepoint. The generated coordinates are then used to index a sphere map image which has been bound as a texture.
We denote the vector from the eye point to the vertex as u,
normalized to u'. Since the computation is performed in eye
coordinates, the eye is located at the origin and u is equal to the
location of the vertex. The current normal n is transformed to eye
coordinates, becoming n'. The reflected vector r can be computed
as:
We define:
Then the texture coordinates are calculated as:
This computation happens internally to OpenGL in the texture
coordinate generation step.
To use sphere mapping in OpenGL, the following steps are performed: