Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 4 of 4

Thread: [Q] - GLSL lighting...how?

  1. #1
    Junior Member Newbie
    Join Date
    Mar 2004
    Location
    San Diego, CA, USA
    Posts
    6

    [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?

  2. #2
    Junior Member Newbie
    Join Date
    Mar 2004
    Location
    San Diego, CA, USA
    Posts
    6

    Re: [Q] - GLSL lighting...how?

    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?

  3. #3
    Senior Member OpenGL Guru Relic's Avatar
    Join Date
    Apr 2000
    Posts
    2,453

    Re: [Q] - GLSL lighting...how?

    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).]

  4. #4
    Junior Member Newbie
    Join Date
    Nov 2003
    Location
    Switzerland
    Posts
    12

    Re: [Q] - GLSL lighting...how?

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

    --Martin

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •