• Advertisement
Sign in to follow this  

GLSL Lighting

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

I've found some relatively good resources on GLSL lighting. In fact, I've even found some sample programs that will do point, directional, or spot lighting. What I can't seem to find is a good implementation. Loading the shader programs into hardware isn't a problem, but I'm just not entirely sure how to go about actually setting the locations of the light sources. I would suspect that it involves glProgramParameter, but I don't really want to sit around and send random values to the card until something light-related happens. Suggestions? Links to GLSL lighting tutorials that address this are also appreciated.

Share this post


Link to post
Share on other sites
Advertisement
http://www.lighthouse3d.com/opengl/glsl/

HTH, it has all three types and per pixel also.

Share this post


Link to post
Share on other sites
You have to decide if you want to use the built-in-uniforms for your lights (gl_LightSource and the others). If this is what you want to use, then you need to make calls to glLightf in your program. I don't recommend this and I wish they hadn't included this in GLSL.

If you want to use your own uniforms, then you declare a uniform in your shader like so
uniform vec4 LightPosition;

then you get the location with
lightlocation=glGetUniformLocation(shaderProgram, "LightPosition");

and whenever you want to update the position, call

//Make sure shader is bound with a call to glUseProgram first
glUniform4fv(lightlocation, ....);

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement