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: Multiple lights with vertex shaders

  1. #1
    Junior Member Newbie
    Join Date
    Jun 2003
    Posts
    7

    Multiple lights with vertex shaders

    Quick question for you guys - say I've got a vertex program that's relativly complex and I want to compute values for up to eight lights that may be contribute to vertex lighting. I don't want to duplicate the same code eight times in the vertex program (and if fact that would run up on the instruction limit anyway for a typical 1.0 shader) - and of course we don't have branching or the equivilant of for loops or anything, so what do I do? How do you guys handle multiple enabled lights for a single vertex program?

  2. #2
    Intern Contributor
    Join Date
    May 2003
    Location
    Cologne / Germany
    Posts
    58

    Re: Multiple lights with vertex shaders

    Hmm, i think you should try to do it multipass. Make as many lights as possible in the first pass and then make the rest in the second (or third if the hardware is older). Is your shading model so complicated or why don't you want to duplicate the code ?

    cu
    Tom

  3. #3
    Junior Member Newbie
    Join Date
    Jun 2003
    Posts
    7

    Re: Multiple lights with vertex shaders

    The lighting model is exceptionally complicated - I'm right at the limit of the number of instructions in a 1.0 shader as it is..

  4. #4
    Senior Member OpenGL Guru
    Join Date
    Mar 2001
    Posts
    2,704

    Re: Multiple lights with vertex shaders

    It is not possible to duplicate the full OpenGL 1.1 lighting model in a version 1 vertex shader. Especially not if you do double-sided, etc.

    One thing I've heard done is to bake all your ambient/diffuse lights into a single second-order spherical harmonic for irradiance, and compute that per-vertex. Then add specular using traditional computation; this might fit for 8 lights.
    "If you can't afford to do something right,
    you'd better make sure you can afford to do it wrong!"

Posting Permissions

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