Simulating a spotlight
The fixed function pipeline had the ability to define light sources as spotlights . In such a configuration, the light source was considered to be one that only radiated light within a cone, the apex of which was located at the light source. Additionally, the light was attenuated so that it was maximal along the axis of the cone and decreased towards the outside edges. This allowed us to create light sources that had a similar visual effect to a real spotlight.
The following image shows a teapot and a torus rendered with a single spotlight. Note the slight decrease in the intensity of the spotlight from the center towards the outside edge.
In this recipe, we'll use a shader to implement a spotlight effect similar to that produced by the fixed-function pipeline.
The spotlight's cone is defined by a spotlight direction (d in the preceding figure), a cutoff angle (c in the preceding figure), and a position (P in the preceding figure). The intensity of the spotlight is considered...