# Lighting attenuation

This topic is 5044 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Does a mathematical function exist to convert near/far plane of light to constant/linear/quadratic value?

##### Share on other sites
Um, you mean the distance formula coupled with

1/(ConstAtten + LinAtten * Distance + QuadAtten * Distance^2)?

##### Share on other sites
Exactly!

In 3DS file, light attenuation is given with inner and outer distance... So how to convert into opengl attenuation?

##### Share on other sites
Wow, that's weird...anyways, I would wager a guess that inner refers to quadratic, and outer refers to linear.

##### Share on other sites
I would guess that near and far refer to distances at which the light is K and 0, respectively, for some useful value of K (such as 255 or 1.0).

In the linear case, L(D) = a*D + b (L = light, D = distance)

K = a*near + b
0 = a*far + b

which solves to

a = K/(near-far)
b = -a*far

In the quadratic case L(D) = a/(D^2) + b*D (distance squared plus a linear term,;a reasonable guess)

K = a/(near^2) + b*near
0 = a/(far^2) + b*far

the solution is a litte more complex:

a = K/ [near * (1/near^3 + 1/far^3) ]
b = -a/(far^3)

Hope that gives you a good starting point.

Tom

##### Share on other sites
Hummm, in quadratic case it's not:

K = a*(near^2) + b*near
0 = a*(far^2) + b*far

rather than

K = a/(near^2) + b*near
0 = a/(far^2) + b*far

???

• ### What is your GameDev Story?

In 2019 we are celebrating 20 years of GameDev.net! Share your GameDev Story with us.

• 9
• 31
• 16
• 11
• 10
• ### Forum Statistics

• Total Topics
634122
• Total Posts
3015623
×