I have a 2D lighting shader with two passes, the first one draws a shadow from the closest light to the sprite and the rest of the lights will reduce the visibility of the shadow if their light shines on it, the second draws the sprite applying deferred and specular lighting. For some objects in the scene no shadow is drawn (tiles for example), or specular lighting shouldn't be applied.
However I'm unsure of how to efficiently use this shader for potentially tens of lights in the scene. As far as I can see I have 3 options.
- For each light, draw each sprite.
- In the shader have an array of lights of size MAX_LIGHTS and a variable numLights for current number of lights and use a for loop to iterate over the lights in the pixel shader (my current solution, the problem is that as MAX_LIGHTS increases it takes up shader logic slots)
- Draw all normalmaps to a rendertarget and all the regular textures to a rendertarget, then for each light draw the scene using these maps. The problem is dealing with the shadows, since each shadow might have a different closest light. I could draw the scene first and then the shadows, but the shadows aren't the top layer and they aren't opaque, so I can't use z index.
Have I forgotten anything? Which would be most efficient?