radius and brightness, how to attenuate?
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.
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.
As Brother Bob said.
Practically,
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.
Practically,
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.
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):
Solve by standard methods.
b0 = 1/( c0 + c1d0 + c2d02 )b1 = 1/( c0 + c1d1 + c2d12 )b2 = 1/( c0 + c1d2 + c2d22 )
or:c0 + c1d0 + c2d02 = 1/b0c0 + c1d1 + c2d12 = 1/b1c0 + 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.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement