[Q] - GLSL lighting...how?

Ok, total newbie here.

I have a really simple (and I mean really simple) test code (using GLUT only, no shaders yet) where I draw a teapot and have a light rotating around it. In fact, here’s the code snippet of my main display routine:

glEnable (GL_LIGHTING);
glEnable (GL_LIGHT0);
glLightfv(GL_LIGHT0, GL_POSITION, light_pos);
glPointSize (5.0);
glColor3f (1.0, 1.0, 1.0);
glBegin (GL_POINTS);
glVertex3f (light_pos[0], light_pos[1], light_pos[2]);
glEnd ();
glColor3f (.5., .5., .5);
glutSolidTeapot(10.0);
glDisable (GL_LIGHTING);

So, what I see is my little white dot rotating around my teapot, where my light is acting like a point light. My eye position (via gluLookAt()) is on the positive Z looking down negative Z. So, when the light goes behind the teapot, the side of the teapot I’m viewing goes dark (as expected).

I don’t set any light or material properties. What you see above are the only light-related routines that I call.

Now, I tried using the vertex/fragment shader code from http://www.clockworkcoders.com/oglsl/ for per-vertex lighting and what I get is not what I expect.

In order to duplicate using shaders what I did without using shaders, do I have to setup all the light and material properties? According to the code from clockworkcoders.com, it looks like a bunch of these are set in DefaultLighting().

I’m confused how to simulate the lighting I did with the fixed-pipeline (the code was really simple) when using GLSL.

What I see is the teapot already lit with what appears to be a directional light? Is this what I’m seeing?

Ok, I’ve taken a look at the cloth demo at http://esprit.campus.luth.se/~humus/.

In looking the code when drawing the sphere and cloth, it appears there are two paths that each function takes. If GLSL is supported, all that set is the shader program. If GLSL isn’t supported, then calls to enable GL_LIGHTING, setting the
light position via glLight* call, and
setting the materials are made.

This is apparently different than the other site’s code where calls to glLight* and glMaterial* is always made.

So, my question is, when trying to do lighting with strictly with GLSL, do you (or do you not) use the glLight* and glMaterial* APIs?

GLSL has access to the built-in state via the reserved gl_ variables. You use the glLight and glMaterial as before, but do the calculations with them yourself in the shaders.
Standard OpenGL lighting is straightforward if you look at the OpenGL specs formulas.

On the other hand, there’s no need to do the exact same calculations, so you could get away with uniforms you fill with whatever your lighting calculations need and forget about the glLight and glMaterial calls.

It’s all about programmability.

[This message has been edited by Relic (edited 03-04-2004).]

If you are using ATI driver, gl_LightSource[i].position isn’t implemented correctly yet.

–Martin

This topic was automatically closed 183 days after the last reply. New replies are no longer allowed.