• Advertisement
Sign in to follow this  

Quick Question About GLSL [SOLVED]

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

Do I have to use the built in GL Lights or can I specify my own lights arbitrarily? So rather than using the following...
// In Source Code
glEnable(GL_LIGHTING);
glEnable(GL_LIGHT0);
// In Vertex Shader etc.
Normalize(gl_LightSource[0].position.xyz);



Can I do this...
float const fvLightPosition = { 0, 0, 10 };
/* Code here to find variable in shader */
glUniform3f(LightPosition, 3, fvLightPosition);
// Shader code
Normalize(fvLightPosition.xyz);



I'm currently using the second method but getting nothing but blackness. Just want a verification before I go off chasing a dead end. [Edited by - Ehrys on April 2, 2008 12:58:15 AM]

Share this post


Link to post
Share on other sites
Advertisement
I suppose the light coordinates are probably turned into eye-space for you by GL. Multiplying your light's world position by the normal matrix should do the trick.

Share this post


Link to post
Share on other sites
Thanks for the reply

in the vertex shader I changed:
vec3 Light = normalize(fvLightPosition.xyz);
to
vec3 Light = normalize(gl_NormalMatrix * fvLightPosition.xyz);

but yielded the same results.

Note: I've tried with lighting enabled and disable just to be sure.

Share this post


Link to post
Share on other sites
Nevermind, tracked down to the problem. The glUniform3fv() command wasn't getting the variable programmed correctly.

Using glUniform3f(LightPosition, 0, 0, 10); the light works correctly.

Any reason why setting a float array wouldn't work?

Share this post


Link to post
Share on other sites
You have to use the function glUniform3fv to load the array. As always to pass an array to an OpenGL command you need to use the function that ends with a v.

Share this post


Link to post
Share on other sites
glUniform3fv(LightPosition, 3, fvLightPosition);

Says: "Yo I need to fill 3 float3's" 0_0

Try

glUniform3fv(LightPosition, 1, fvLightPosition);

Which says "fill 1 float3";

Share this post


Link to post
Share on other sites
Whoops, apatriarca that was a typo from when I copy typed it over (didn't copy paste as too much gunk in other places)

bzroom, thanks for the solution! Can't believe I didn't see that. I blame lack of sleep ;)

Share this post


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

  • Advertisement