# Calculate intensity of spot light

I am working on a raytracer for school but I am having trouble implementing spotlights. The task says the intensity should fall off proportionally to the cosine lobe raised to a given exponent. The other given properties are the position, the direction, the opening angle (1/2), the exponent and the initial intensity. I tried this

const auto spotFactor = dot(-light.direction, direction); // light.direction is the direction from the hit point to the light
if (spotFactor >= angle)
{
return intensity * std::pow(spotFactor, exp);
}
return Color(0, 0, 0);


But that doesn't seem to work. Can someone help?

• Maybe output spotFactor first and see if you get what you expect (lambert shading), a common mistake is one of the direction (view or light) is the wrong sign. – PaulHK Dec 2 at 1:59