There are quite a few materials that are nearly diffuse reflectors such as rough
wood, newspaper, concrete, and mouse pad. However, a considerable number of
surfaces are shiny or glossy. We call these specular materials. Examples include
polish metals, plastics, polish wood, glass, glazed ceramics, and enamel paint.
These materials look different when you view them different angles, so we need
to take into account the direction from the surface to the eye. One standard way
of simulating specular materials is called the Blinn-Phong Reflection Model
named after its inventors, Jim Blinn and Bui Tuong Phong. The full model has a
number of terms in it for self-shadowing and for a shininess factor called the
Fresnel coefficent. But the simplest and most common form is this. Specular
equals the maximum of N dot H or 0, whichever is larger, raised to a power. N is
the surface normal, same as with diffuse material. H is called the half angle
vector. Say, you're given a surface, a light source direction, and a viewer
direction. How would you point a mirror so that the light reflected directly
toward the viewer? The answer is the half angle vector, which is the vector
halfway between these two directions, so that these two angles are equal. If the
surface normal and the half angle are identical, then the surface is perfectly
aligned to reflect light to the eye. So, N dot H would be 1, and all light is
reflective. As the normal and the half angle diversion direction, N dot H
becomes smaller. Once the angle between these vectors is 90 degrees, the
contribution goes to 0. The maximum function here limits the inputs so that this
value is never negative. We want to avoid it being negative because we're about
to raise it to a power. The S factor here is the shininess or specular power,
and has a range from 1 to infinity, though anything above 100 is not too much
different. When you raise a fraction to a power, the result is smaller, and
smaller still the higher the power. For example, 0.5 squared is 0.25, cubed, is
0.125, and so on. By raising this term to a higher power, the object appears
shinier. We can see this in the graph of N dot H versus the specular intensity.
As the cosine power rises, the slope becomes tighter and tighter and gets
sharper. What the half angle represents is the distribution of microfacets on a
surface. A microfacet is a way of thinking how a material reflects light. For
example, a fairly smooth surface may look like this. Light coming in from one
direction will bounce off the surface mostly in the reflection direction. A
rougher surface will a lower shininess has a distribution of facets more like
this and the light will still go in the reflection direction, but with a much
wider dispersal. At this point, it's best for you to try out the specular power
function and see how it responds. An example program that follows, you control
the ambient, diffuse, and specular contributions. Try playing with the shininess
and other controls to see their effects.