Calculate distance at which light intensity = X

Started by
1 comment, last by reaperrar 11 years, 7 months ago
I'm using this formula to calculate light intensity from a point light at any given point in 3D space:

CA = Const attenuation
LA = Linear attenuation
QA = Quadratic attenuation
D = Distance from the point light to point
I = Intensity

I = 1 / (CA + LA * D + QA * (D*D))

I'd like to know at what distance the lights intensity is at 1% (so I have a kind of max range). So...
*If I know the value of all variables except D
*If I know both QA and LA > 0 & CA >= 0

1 / 0.01 = CA + LA * D + QA * (D*D)
1 / 0.01 - CA = LA * D + QA * (D*D)
0 = (1 / 0.01 - CA) - LA * D + QA * (D*D)

It seems as though I should be able to solve for D using the quadratic equation?
a = QA
b = LA
c = -(1 / 0.01 - CA)
x = D
ax^2+bx+c=0

I've made a few attempts with no success... am I on the right track?
Advertisement
Okay, I'll have a go:

L = 1/ (QA * D^2 + LA * D + CA)
L * (QA * D^2 + LA * D + CA) = 1
QA * D^2 + LA * D + CA = 1 / L
QA * D^2 + LA * D + (CA - 1 / L) = 0

So:
a = QA
b = LA
c = CA - 1/L

It sounds like you're on the right track.

Then:
D = (-b +/- sqrt(b^2 - 4ac)) / 2a
D = (-LA +/- sqrt(LA^2 - 4*QA*(CA - 1/L))) / (2 * QA)
D = (-LA +/- sqrt(LA^2 - 4*QA*CA + (4*QA)/L))) / (2 * QA)

Is your problem with the algebra, or the numbers you get out of it? Give us some sample numbers to try it out. Tell us what answer you get and why you think that answer is wrong.
My code looks like this (Switched c around):

[source lang="cpp"]float fIntensityAtMaxDistance = 0.01f;
float fA = m_poLight->GetQuadraticAttenuation();
float fB = m_poLight->GetLinearAttenuation();
float fC = m_poLight->GetConstantAttenuation() - 1.0f / fIntensityAtMaxDistance;

float fDisc = fB * fB - 4.0f * fA * fC;

float fSqrtDisc = sqrt(fDisc);

//EDIT
float f1 = (-fB + fSqrtDisc) / (2 * fA);
float f2 = (-fB - fSqrtDisc) / (2 * fA);[/source]
[s]The answers I'm getting for both f1 and f2 are tiny (0.0000147f) when the range of the light extends up to 2000.0f or so : /[/s]
Forgot brakets on denominator xD

This topic is closed to new replies.

Advertisement