Using the halfway vector for improved performance
As covered in the recipe Implementing per-vertex ambient, diffuse, and specular (ADS) shading in Chapter 2, the specular term in the ADS shading equation involves the dot product of the vector of pure reflection (r), and the direction towards the viewer (v).
In order to evaluate the above equation, we need to find the vector of pure reflection (r), which is the reflection of the vector towards the light source (s) about the normal vector (n).
Note
This equation is implemented by the GLSL function: reflect
.
The above equation requires a dot product, an addition, and a couple of multiplication operations. We can gain a slight improvement in the efficiency of the specular calculation by making use of the following observation. When v is aligned with r, the normal vector (n) must be halfway between v and s.
Let's define the halfway vector (h) as the vector that is halfway between v and s, where h is normalized after the addition:
The following picture...