Jump to content
  • Advertisement


This topic is now archived and is closed to further replies.



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

If you intended to correct an error in the post then please contact us.

Recommended Posts

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

Share this post

Link to post
Share on other sites

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,
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:


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:

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....


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]

Share this post

Link to post
Share on other sites
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?


Share this post

Link to post
Share on other sites
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..

Share this post

Link to post
Share on other sites
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?

Share this post

Link to post
Share on other sites

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!