Sign in to follow this  

radius and brightness, how to attenuate?

Recommended Posts

Hi. After stuying the OpenGL lighting attenuation formula, and with help on the OpenGL forum I found out how it works. Now there's another problem, I want to calculate the 3 attenuation values: CONSTANT, LINEAR and QUADRATICAL, from 3 user input values: RADIUS, BRIGHTNESS NEAR POSITION, BRIGHTNESS HALFWAY. Radius is the distance from where the brightness should be 0,0. Brightness is the maximum brightness near the light's position. Brightness halfway is the brightness halfway the position and max. radius. This is the correct openGL formula: 1.0 / (constant+linear*d + quadratic*d*d) Now for example I want a positional lightsource with: - radius = 10 - brightness = 10 - brightness halfway = 5 Can someone explain too me how I can make a working formula to calculate this? (I tried lots of things using excel, but it just doesn't work) Thanks in advance.

Share this post

Link to post
Share on other sites
The attenuation factor will never reach zero. It approaches zero as d approaches infinity. So technically, every light always have an infinite radius, it just reaches an low enough value at some point to not have any effect the scene.

Share this post

Link to post
Share on other sites
As Brother Bob said.

Solve that
constant+linear*d + quadratic*d*d = brightest_light_component*256
for d
(accurate for non-HDR)

In general case, you can use,
constant+linear*d + quadratic*d*d = brightest_light_component/minimal_brightness_you_care_about;
where minimal_brightness_you_care_about may be 1/256 or 1/128, etc.

Share this post

Link to post
Share on other sites
If you have 3 brightness values (b0, b1, b2) at 3 distances (d0, d1, d2), you basically have a system of three equations with three unknowns (c0, c1, c2):

b0 = 1/( c0 + c1d0 + c2d02 )
b1 = 1/( c0 + c1d1 + c2d12 )
b2 = 1/( c0 + c1d2 + c2d22 )
c0 + c1d0 + c2d02 = 1/b0
c0 + c1d1 + c2d12 = 1/b1
c0 + c1d2 + c2d22 = 1/b2
or in matrix form:
| 1 d0 d02 | | c0 |   | 1/b0 |
| 1 d1 d12 | | c1 | = | 1/b1 |
| 1 d2 d22 | | c2 | | 1/b2 |

Solve by standard methods.

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this