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 9 of 9

Thread: Light states variables

  1. #1
    Junior Member Newbie
    Join Date
    Apr 2004
    Location
    Argentina
    Posts
    28

    Light states variables

    Hi,

    Is there a way to know from a vertex/fragment shader which lights are on or off, and what is the state of OpenGL lighting?

  2. #2
    Junior Member Regular Contributor
    Join Date
    May 2003
    Location
    Germany
    Posts
    229

    Re: Light states variables

    I guess you're looking for those :
    Code :
    struct gl_LightSourceParameters
     {
      vec4 ambient;
      vec4 diffuse;
      vec4 specular;
      vec4 position;
      vec4 halfVector;
      vec3 spotDirection;
      float spotExponent;
      float spotCutoff;
      float spotCosCutoff;
      float constantAttenuation;
      float linearAttenuation;
      float quadraticAttenuation;
     };
     gl_LightSourceParameters gl_LightSource[gl_MaxLights];
    Don't know about the enabled/disabled state of a lightsource, but it shouldn't be too hard to tell the shader from your app what lights are on.

  3. #3
    Intern Contributor
    Join Date
    Sep 2001
    Location
    Marlboro MA
    Posts
    90

    Re: Light states variables

    Originally posted by AdrianPi:
    Hi,

    Is there a way to know from a vertex/fragment shader which lights are on or off, and what is the state of OpenGL lighting?
    What is the state of OpenGL lighting? Yes.

    Which light is enabled? Not directly. You can declare your own:

    Code :
    uniform bool myLightEnable[8];
    And then load it with:

    Code :
    int myLightLocation = glGetUniformLocationARB( programObj, "myLightEnable");
    glUniform1fvARB( myLightLocation, 8, pFloats );
    -mr. bill

  4. #4
    Intern Contributor
    Join Date
    Jan 2004
    Posts
    75

    Re: Light states variables

    Or you can just set the intensity of disabled lights to zero.

  5. #5
    Junior Member Newbie
    Join Date
    Apr 2004
    Location
    Argentina
    Posts
    28

    Re: Light states variables

    Thanks MrBill, but how do I know the lighting state from glsl?
    You just said "yes", but not "how"

  6. #6
    Senior Member OpenGL Guru
    Join Date
    Mar 2001
    Posts
    3,576

    Re: Light states variables

    Maybe you didn't notice the rather large gl_LightSourceParameters struct that PanzerSchreck posted. Or the array of these structures that he also mentioned. Maybe you should take a look at these, seeing as how they encapsulate OpenGL's lighting state.

  7. #7
    Junior Member Newbie
    Join Date
    Apr 2004
    Location
    Argentina
    Posts
    28

    Re: Light states variables

    Ys I saw that Korval, but I'm talking about the global lighting state, the one we set with glEnable(GL_LIGHTING)

  8. #8
    Junior Member Newbie
    Join Date
    Apr 2004
    Location
    Argentina
    Posts
    28

    Re: Light states variables

    Yes, I saw that, but I'm talking about the global lighting state, the one we set with glEnable(GL_LIGHTING)

  9. #9
    Intern Contributor
    Join Date
    Sep 2001
    Location
    Marlboro MA
    Posts
    90

    Re: Light states variables

    Originally posted by AdrianPi:
    Yes, I saw that, but I'm talking about the global lighting state, the one we set with glEnable(GL_LIGHTING)
    Code :
    // There *ARE* much *faster* ways to do this!
    // For teaching purposes only....
    GLfloat Floats[8];
    GLfloat *pFloats = &Floats[0];
    for (int i=0; i<8; i++)
    {
       Floats[i] = glIsEnabled( GL_LIGHT0+i );
    }
    int myLightLocation = glGetUniformLocationARB( programObj, "myLightEnable");
    glUniform1fvARB( myLightLocation, 8, pFloats );
    -mr. bill

Posting Permissions

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