The specular highlights in this image use a very simple, but unrealistic, physical model. Specular highlights are caused by lights reflecting on a surface, but they can vary in width because either the light is large or small, or the surface is more or less rough.
The roughness of the surface contributes to the width of the highlight and that's what this model tries to capture. It works out how far the light source is away from being perfectly reflected and then attenuates it's colour accordingly. A good way of telling how parallel two vectors are (in this case a perfect reflection of the direction from the observer to the position on the sphere it was hit and the direction to the light) is to use the dot product between them (this works out the same as the cosine of the angle between them). A value of one means they're parallel, zero means that they are orthogonal and minus one means that they are parallel, but in opposite directions.
The roughness is calculated by raising the cosine of the angle to a power — the higher the power the smaller the highlight will appear and the harder the edge will look. The spheres use different powers ranging from ten to 100.
Note that the underlying colour of the sphere is completely ignored. This roughly corresponds to what you would expect from a specular reflection on something like a plastic. If the surface colour was used to 'shade' the specular highlight then the object would look metallic instead of plastic.
Because we can't use this lighting model for the entire sphere, we have to use it in addition to the Lambertian shading we started with. This adds some extra calculation, but only results in about a 6% increase in render times.
The code is at Scenes/early/simple-specular-highlight.cpp.