# problem with GLSL attenuation (resolved)

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

## Recommended Posts

[EDIT : at the beginning it was a problem of black screen, i edited my first post when the problem has changed] Hi i am making a per pixel lighting with render monkey and i can't use attenuation otherwise my mesh isn't lighted :( [Edited by - TheSeb on May 16, 2005 10:56:12 AM]

##### Share on other sites
You really want to normalize the light vector -- and, ideally, the normal vector, too.

I would start by changing most of the GL variables to constants; i e, use vec4(0.2) instead of calculating the ambient light product; same thing for each other term. To make sure things were working right, maybe I'd even just output green, or the normal, as color in the first place. Then add back each step and see where you go wrong.

You calculate the light vector wrong, as distance() is always a positive value. I would calculate the light vector as:

  vec3 lightVector = vec3(gl_LightSource[0].position) - vec3(coordinate);  vec3 lightVectorNormalized = normalize( lightVector );

If you want an example of using GLSL in a real program, try my carworld demo.

##### Share on other sites
There is a thing which i have forgetten to say : before the black screen, it worked but the specular part look to be wrong, and at this time "coordinate" variable was replaced by gl_FragCoord.

[Edited by - TheSeb on May 15, 2005 5:35:03 PM]

##### Share on other sites
Quote:
 Original post by hplus0603You really want to normalize the light vector -- and, ideally, the normal vector, too.I would start by changing most of the GL variables to constants; i e, use vec4(0.2) instead of calculating the ambient light product; same thing for each other term. To make sure things were working right, maybe I'd even just output green, or the normal, as color in the first place. Then add back each step and see where you go wrong.You calculate the light vector wrong, as distance() is always a positive value. I would calculate the light vector as: vec3 lightVector = vec3(gl_LightSource[0].position) - vec3(coordinate); vec3 lightVectorNormalized = normalize( lightVector );If you want an example of using GLSL in a real program, try my carworld demo.

i have normalized the vectors, it didn't change something but after this i have removed attenuation and the model is lighted, however i don't see the specular part on the mesh and i would like that it works with attenuation, do you know how to do ?

up !

up

##### Share on other sites
*raises eyebrow*
one bump per day at the most is plenty....

1. 1
2. 2
Rutin
16
3. 3
4. 4
5. 5

• 26
• 11
• 9
• 9
• 11
• ### Forum Statistics

• Total Topics
633705
• Total Posts
3013464
×