problem with GLSL attenuation (resolved)

Started by
5 comments, last by _the_phantom_ 18 years, 11 months ago
[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]
Advertisement
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.
enum Bool { True, False, FileNotFound };
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]
Quote:Original post by hplus0603
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.


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
*raises eyebrow*
one bump per day at the most is plenty....

This topic is closed to new replies.

Advertisement