OpenGL provides a mechanism to generate s and t texture coordinates at vertices based on the current normal and the direction to the eye point. The generated coordinates are then used to index a sphere map image which has been bound as a texture.
The vector from the eye point to the vertex is denoted as ,
normalized to
. Since the computation is performed in eye
coordinates, the eye is located at the origin and
is equal to the
location of the vertex. The current normal
is transformed to eye
coordinates, becoming
. The reflected vector
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: