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?