I'm developing a lighting system for my voxel game, and I have to send multiple (alot, say up to 200) lights to my shader program. Those lights contain the following data:

  • Position (vec3)
  • Color (vec3)
  • Radius (float)
  • Strength (float)

What is the most efficient way to send alof of those light structs to my shaders? I would like it to work with lower versions of OpenGL, like 2.1.

  • \$\begingroup\$ One thing that comes to mind is that you can pack the floats together with the vec3s to make vec4s. E.g. each light would be a vec4 of (position, radius) and a vec4 of (color, strength). GPUs like uniform data to be aligned on 16-byte (4-float) boundaries. \$\endgroup\$ Commented Jun 7, 2013 at 20:09
  • \$\begingroup\$ Hmm interesting. But doesn't GLSL have an array-size limit of about 12? \$\endgroup\$
    – Basaa
    Commented Jun 7, 2013 at 20:12
  • \$\begingroup\$ @Basaa: "But doesn't GLSL have an array-size limit of about 12?" No. \$\endgroup\$ Commented Jun 7, 2013 at 22:22

1 Answer 1


The most efficient way to do that would be to not do that.

If you have a scene where you want 200 lights to affect an object, you can't use forward rendering anymore. Also, as a practical matter, I'm fairly sure that quite a lot of GL 2.x hardware couldn't handle a uniform array of 400 vec4s. And even if you could, your shader would probably choke attempting to do lighting over 200 lights in one pass.

The performance simply isn't there for such a computation. Every pixel of overdraw will hurt by 200x. That's going to kill you in the end. So you need to use some form of deferred rendering.

And in deferred rendering, you wouldn't really render by sending 200 lights to a single shader.

  • 2
    \$\begingroup\$ MAX_VERTEX_UNIFORM_COMPONENTS_ARB returns 512 for many not-too-old cards, so yeah, the limit is fairly low. A non-2.1 feature like UBOs/TBOs would be needed to work around this. \$\endgroup\$ Commented Jun 7, 2013 at 22:30

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .