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?

  • $\begingroup$ 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. $\endgroup$ – PaulHK Dec 2 at 1:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.