Advertisement

GL_LINEAR_ATTENUATION

Started by May 01, 2003 11:07 AM
5 comments, last by soulspaceuk 21 years, 10 months ago
OK, having a problem with this.. glLightf(gllightname, GL_CONSTANT_ATTENUATION, 1); glLightf(gllightname, GL_LINEAR_ATTENUATION, 1/512); i want the light to have less effect on things further away.. but it seems to be doing quite the opposite! it''s making things brighter when they''re furher away! anyone know why? i have a function called setlights(x,y,z) which finds the nearest lights to the object about to be rendered, then puts them in.. it does this before drawing the object (and before calling the matrix translate & rotation for the object - but the objects position is taken into account) - the lights are shading the right side of the object, just they get brighter the further away i move the object.. thanks in advance! j
im not 100% familiar with GL_LINEAR_ATTENUATION but should 1/512 be 512?
Advertisement
i''ve tried that too...
but i''ve changed other things since then.. i''ll give it another go..
ok...

there are three parts to the lighting equation,

so bare with me here, this will hopfully make you realise why your lighting isn't working right....

light is calculated using the distance to the light at a vertex..

there are three components, where d is the distance;

finalLight = 1/( A + B * d + C * d^2)

in this equation, GL_CONSTANT_ATTENUATION represents A,
GL_LINEAR_ATTENUATION represents B
while GL_QUADRATIC_ATTENUATION represents C...

ok.. assuming you have a light falloff, where that distance is the distance you want where the amount of light will be equal to 1, then,
for linear falloff, you would set constant_attenuation to 0, linear_attenuation to 1/falloff, and quadratic_attenuation to 0.
you equation would then end up like:

light=falloff/d

for light that doesn't fall off at all, ie, is always bright, you would set all but constant_attenuation to 0.. so your equation would end up looking like:
light=n, where n is the constant_attenuation value. Hence, the light will never get darker...

for the most realistic light, you need quadratic attenuation, since light is projected as an area, it requires the distance to be squared if it's going to be roughly realisitc...
hence, you would get an equation something like:
light=falloff/(d^2)


does this make sense?

the equation you have, for your light is:

light=1 + 512/d

hence you will always have the lights colour added in there....



[EDIT]

on second thought... thats probably not your problem...
I'm not really thinking too well this morning.. but anyway..

whats your specular coefficient? it should be around ~96....



| - Project-X - my mega project.. close... - | - adDeath - | - email me - |

[edited by - RipTorn on May 1, 2003 5:45:56 PM]
A higher linear attenuation factor results in a faster decrease in light intensity as intensity is calculated as 1 / (constant attenuation + (distance * linear attenuation) + (distance² * quadratic attenuation)).

Are you certain that the lights are in the correct positions relative to the objects? Are the normals for the objects correct?

Enigma
ok, i''m pretty certain the light positions are in the correct places - i''ve moved everything around to different places & the correct sides of the object are lighting up when I put it in a different place.
but it still seems to be getting brighter as it gets further away..

i''m going to try a couple more things and then give up for a while..
Advertisement
ok, it seems i must call my setlights() routine *after* my matrix translate, but before the rotation.. that seems to have solved it.. i guess it was just changing the lighting values after the transform?

This topic is closed to new replies.

Advertisement