I followed a tutorial on how to build a spotlight using DirectX. This tutorial uses a point light equation plus a line of code to limit the light to the shape of a cone. I have everything working, but the equation for constraining the light uses a constant exponent to control the broadness of the light, which is all well and good if I was just tweaking the value for looks alone, but I also want to know the precise size of the cone in order to do culling on the CPU side. Here's the equation:
float lightAmnt = dot(lightToSurfaceVector, inputNormal); // point light lightAmnt /= attenuationA + attenuationB * distance + attenuationC * distanceSquared; // falloff // exponentConstant to control broadness lightAmnt *= pow(max(dot(-lightToSurfaceVector, lightDir), 0.0f), exponentConstant); // spotlight
what I'd like to do is create an angle theta for the cone on the CPU, and then create the exponentConstant based on that and the range aka cone height, but I don't know how that math would work. And I realize there are other spotlight equations, but I like this one because the attenuation works identically between point and spot lights. Can anybody lend a hand?
link to the tutorial: https://www.braynzarsoft.net/viewtutorial/q16390-21-spotlights