Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

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.

share|improve this question
    
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. –  Nathan Reed Jun 7 '13 at 20:09
    
Hmm interesting. But doesn't GLSL have an array-size limit of about 12? –  Basaa Jun 7 '13 at 20:12
    
@Basaa: "But doesn't GLSL have an array-size limit of about 12?" No. –  Nicol Bolas Jun 7 '13 at 22:22

1 Answer 1

up vote 5 down vote accepted

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.

share|improve this answer
2  
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. –  Sean Middleditch Jun 7 '13 at 22:30

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.