Can you dynamic GLSL uniform arrays

Every scene can contain a different number of lights, and details of these need to go to the shader, and I am using an array for this. Problem is the shader requires a specification of the number of items in the array therefore you have to oversize the array and make sure you send in no more lights than specified. Is there a better work around?

As of yet, there is nothing that resembles dynamic arrays in GLSL.

If you’re doing your lighting in a deferred manner, using a uniform buffer for light sources and binding the range containing the current light’s properties works quite well.

If you’re doing it forward-style the common approach is to limit the number of light sources that can illuminate an object anyway. Say this amount would be 5, then statically sizing the array and passing the actual number of influencing lights to the shader isn’t that big a deal.

thanks thokra

That’s what I’m doing, for both forward and deferred shading. Separate arrays per light property, and in standard uniforms as well (not UBOs).

This topic was automatically closed 183 days after the last reply. New replies are no longer allowed.