Sign in to follow this  

problem with GLSL attenuation (resolved)

This topic is 4592 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

[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 this post


Link to post
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 this post


Link to post
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 this post


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

Share this post


Link to post
Share on other sites

This topic is 4592 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this