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: fragment lighting

  1. #1
    Advanced Member Frequent Contributor
    Join Date
    Feb 2004
    Location
    Long Island, New York
    Posts
    570

    fragment lighting

    I think all of the glsl examples of fragment lighting I've seen use a fixed point light source.

    I need a fragment shader does performs lighting with a variably positioned light.
    My understanding of lighting calculations requires me to calculate the vector between the fragment position and light position.

    the problem is gl_FragCoord is in screen space while the lightSource[i] is in object space.

    anyone have any hints/pointers/code that can peform fragment lighting with a moving light?

    thanks.

  2. #2
    Advanced Member Frequent Contributor
    Join Date
    Oct 2000
    Location
    Belgium
    Posts
    807

    Re: fragment lighting

    The vector from the surface to the light can be linearly interpolated as long as you don't normalize it. Hence, you can calculate it in the vertex shader and normalize it in the fragment shader. Once you do this, you don't need to know the fragment position in the fragment shader anymore.

    If you really do need the position for something, just use the same trick: calculate it in the vertex shader and interpolate it.

    -- Tom

  3. #3
    Advanced Member Frequent Contributor
    Join Date
    Feb 2004
    Location
    Long Island, New York
    Posts
    570

    Re: fragment lighting

    The vector calculated in the Vertex Shader will be the vector from the light to that vertex.

    are you saying glsl automatically interpolates all varying variables on their way to the fragment shader?

    [EDIT]

    wow, look at that...the vector does get interpolated.
    this changes a lot. Can't believe i didn't know that.

    hoo-wa. thanks a lot Tom.

  4. #4
    Advanced Member Frequent Contributor yooyo's Avatar
    Join Date
    Apr 2003
    Location
    Belgrade, Serbia
    Posts
    872

    Re: fragment lighting

    Originally posted by Aeluned:
    The vector calculated in the Vertex Shader will be the vector from the light to that vertex.

    are you saying glsl automatically interpolates all varying variables on their way to the fragment shader?
    Yep.. all varying's are interpolated and perspective corrected.

    yooyo

Posting Permissions

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