Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Page 1 of 2 12 LastLast
Results 1 to 10 of 12

Thread: Light position

  1. #1
    Junior Member Newbie
    Join Date
    Jul 2004
    Location
    Belfort - France
    Posts
    6

    Light position

    Hi,

    I'm trying to implement a simple lighting shader with GLSL but i'm lost !

    Before rendering the scene, I use glRotate() and glTranslate() to position the camera.
    The rendering objects are in world space and I use the camera to move in the world.
    I have a point light which is defined in world space.
    I then pass the light position with glUniform3fvARB(). But i can't get my lighting shader to work. I get suspect effect and i presume that light position is not handled the right way !

    How must i transform the world light position to eye-space ?

    PS: I used glLight() to pass light position in the shader in another project and all was working pretty good.

  2. #2
    Member Regular Contributor
    Join Date
    Apr 2002
    Location
    Austria
    Posts
    328

    Re: Light position

    You need to multiply your view-matrix with the light coordinate. You can get this matrix by using glGetFloatv(GL_MODELVIEW_MATRIX) right after gluLookAt(..).
    There is a theory which states that if ever anybody discovers exactly what the Universe is for and why it is here, it will instantly disappear and be replaced by something even more bizarre and inexplicable.

    There is another theory which states that this has already happened...

  3. #3
    Intern Newbie
    Join Date
    Jul 2004
    Location
    Germany
    Posts
    33

    Re: Light position

    The following seems to work for me:
    -glLoadIdentity()
    -set Light Position with glUniform
    -gluLookAt() (use this instead of glTranslate and glRotate for Camera!)
    -do what you want

    Don't forget to multiply gl_ModelViewMatrix with gl_Vertex and send this to the fragment shader as fragment position if you need this.

  4. #4
    Junior Member Newbie
    Join Date
    Jul 2004
    Location
    Belfort - France
    Posts
    6

    Re: Light position

    Thanks !

    I now understand better how OpenGL manage matrix and lights.

    I had to multiply light world position with the ModelView matrix right after my camera operations.

    - FenKz

  5. #5
    Junior Member Regular Contributor
    Join Date
    Dec 2002
    Location
    Silicon Valley
    Posts
    217

    Re: Light position

    Back up a second. If you set your modelview matrix with gluLookAt, and then specify a light position (in world space) with glLight, that light position will automagically be multiplied by the current modelview matrix before it gets sent to the shader. The shader will then receive the light position in view space.

    So you don't have to multiply your light position by your view matrix on your own; OpenGL will do it for you.

  6. #6
    Junior Member Newbie
    Join Date
    Jul 2004
    Location
    Belfort - France
    Posts
    6

    Re: Light position

    Yeah, i was using glLight() to position lights and so i didn't need to multiply with view matrix, but i got strange results on ATI cards with multiple lights.

    So, now, to be sure, i use glUniform3fvARB() to send light position and therefore i need to multiply myself.

  7. #7
    Junior Member Regular Contributor
    Join Date
    Dec 2002
    Location
    Silicon Valley
    Posts
    217

    Re: Light position

    If you think you found a bug, it would be good to report that to ATI. If your glLight positions really are getting messed up that would be a big problem for everybody.

  8. #8
    Junior Member Newbie
    Join Date
    Jul 2004
    Location
    Belfort - France
    Posts
    6

    Re: Light position

    Ok, i will try to repeat it and see what's going on.
    I thought that I was making an error, but yeah, it's maybe an ATI bug

  9. #9
    Junior Member Newbie
    Join Date
    Jun 2004
    Location
    Melbourne, Australia
    Posts
    5

    Re: Light position

    Actually I waws struggling with this same problem on a 6800 GT. Took me hours to work out it was buggy and just asking for the glLightPosition will mess up other totally unrelated variables. Its been reported to nVidia.

  10. #10
    Junior Member Newbie
    Join Date
    Sep 2004
    Posts
    1

    Re: Light position

    Hi!I wrote a simple program with per vertex lighting technique.I use Radeon 9600 Mobility and CATALYST 4.7 and 4.8.It's seems to be ok with single light.But when I use multiple lights(2 and 3 lights) it displays incorrectly.The same program runs correctly on nVidia 5900.So I think it is the driver's bug.Does anybody know how to report it to ATI?

Posting Permissions

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