This light-emitter I have already implemented in the assignment 1. Therefore I simple copied the text from there.
To be able to perform the calculations for the spotlight, more parameters can be set in the xml-file. Namely the direction, the total-width angle and the falloff-angle. The parameters are defined as in the book (see picture "Figure 12.4 for illustrations).
directiontotalWidthfalloffStartThe biggest problem I faced was to calculate the correct angle between the light-ray and the given direction of the spotlight. Even thought it is easy to achieve with the functionality provided by the framework and math-library, I mixed up between the units, resulting in funny illumination-models.
Another learning I had to make on the hard way was to not reuse the same intersection-object for recursive rays as from the primary-ray. This resulted in wrong intersection-calculations for more than one light-source. Even though the effect looked quite fascinating, I do not think that it could have any useful application. (see comparisons below.)
Below I have some renderings with different light settings. (I don't have a scene-file for each rendering, basically I just commented some lights out or changed the angles accordingly).