View Full Version : Array size limit
05-20-2011, 02:14 PM
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?
05-20-2011, 02:35 PM
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.
05-21-2011, 02:06 AM
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.
05-21-2011, 02:14 AM
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.
05-21-2011, 01:05 PM
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?
05-21-2011, 01:45 PM
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"? :)
05-22-2011, 02:27 AM
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.
05-22-2011, 02:55 AM
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.
05-22-2011, 04:54 AM
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.
Powered by vBulletin® Version 4.2.0 Copyright © 2013 vBulletin Solutions, Inc. All rights reserved.