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: Array size limit

  1. #1
    Junior Member Newbie
    Join Date
    May 2011
    Location
    United Kingdom
    Posts
    12

    Array size limit

    So I tried creating my own lighting system. I created a light class in C++ and a pointer array for the lights in my scene. The lights' variables are then to be passed to a bunch of arrays in my glsl shader, however, an array size of above 12 is not allowed. This means I cannot use more than 12 lights at once. How could I work around this?

  2. #2
    Senior Member OpenGL Guru
    Join Date
    May 2009
    Posts
    4,718

    Re: Array size limit

    array size of above 12 is not allowed
    According to what is an array size above 12 not allowed? Are you getting some GLSL compiler errors? What kind of hardware are you using?

    This means I cannot use more than 12 lights at once.
    In the general case, an array size above 12 is unnecessary. You should try to only use the closest X lights to the object when rendering that object. Or possibly try some kind of deferred renderer, but that will require more work.

  3. #3
    Junior Member Newbie
    Join Date
    May 2011
    Location
    United Kingdom
    Posts
    12

    Re: Array size limit

    Yes I am gettings GLSL compiler errors - "Not enough space for defined varyings." This doesn't appear if the array size is <= 12, and the shader works fine. But nevermind, I guess I'll have to create a bunch of software lights and then use an algorithm for each 3D object that assigns the 8 closest software lights to the 8 hardware accelerated lights.

  4. #4
    Senior Member OpenGL Guru
    Join Date
    May 2009
    Posts
    4,718

    Re: Array size limit

    Why are you sending light parameters as varyings? Light parameters do not vary over the surface of a triangle. The surface position varies. The surface diffuse color may vary. But the light's position, intensity, etc does not change.

    Light parameters should be uniforms, not varyings.

  5. #5
    Junior Member Newbie
    Join Date
    May 2011
    Location
    United Kingdom
    Posts
    12

    Re: Array size limit

    I didn't really think about that, I'm a newbie to GLSL. Would a uniform's array size limit be higher? It doesn't really matter though as I scrapped that idea anyway. However, when using more than 3 or 4 hardware accelerated lights the program starts to lag, how many hardware accelerated lights do most programs use at once?

  6. #6
    Advanced Member Frequent Contributor Aleksandar's Avatar
    Join Date
    Jul 2009
    Posts
    944

    Re: Array size limit

    Quote Originally Posted by Tom Chesters
    However, when using more than 3 or 4 hardware accelerated lights the program starts to lag, how many hardware accelerated lights do most programs use at once?
    What is a "hardware accelerated light"?

  7. #7
    Junior Member Newbie
    Join Date
    May 2011
    Location
    United Kingdom
    Posts
    12

    Re: Array size limit

    One of the 8 lights that opengl gives you, as opposed to my own 'light' class which stores the position, ambient, diffuse, and specular properties but doesnt do any of the actual light rendering.

  8. #8
    Advanced Member Frequent Contributor Aleksandar's Avatar
    Join Date
    Jul 2009
    Posts
    944

    Re: Array size limit

    And why do you think those lights, that are using built-in variables to transfer values to the shaders, are "hardware accelerated" and your own are not?
    The difference in the speed, if it really exists, may be because of some inefficiency in your code. In core profile, there is no more light-related built-in variables, and everything is running in a blazing speed. So, before continue your work, please read some tutorial about lighting in GLSL, or even better an Orange book 3rd Ed.

  9. #9
    Junior Member Newbie
    Join Date
    May 2011
    Location
    United Kingdom
    Posts
    12

    Re: Array size limit

    You're right my code was inefficient, but that doesn't matter as it no longer exists. I'm now using only four built-in lights in GLSL, however in c++ I have many of my own lights (which don't do anything on their own), and for each triangle rendered, the 4 closest of my own lights is assigned to the 4 built-in lights. That way I can have as many lights as I like in my scene, however only 4 are rendered at once for each triangle.

Posting Permissions

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