I'm attempting to implement shadow mapping in an OpenGL deferred shading system.

I know how to handle a single shadow map in the lighting stage, but I want my rendering system to be able to support multiple shadow maps.

At present, My lighting shader is capable of supporting up to 128 point and spotlights in a single pass.

I'd like to know how to modify the shader to handle an indeterminate number of shadow maps of each type (ortho for directional, cube for pointlights, projection for spotlights).

Normally, when I define a sampler in GLSL, i simply use :

uniform sampler2D shadowMap;

But I think it would be cumbersome to define up to 256 individual sampler uniforms, if it were even possible (which I am far from convinced about).

Is there a way to define an array of samplers which I can iterate through on a 1:1 ratio for each light, and if so, how would I do this?

For instance, I know that I can use UBO's to send the data for many lights to the shader, so can I do the same to populate an array of samplers, like so:



uniform sampler2D
  • \$\begingroup\$ This question looks a bit odd. Combining lots of lights into a single pass is more commonly done in forward rendering, where you're trying to limit the number of passes you need to make over each piece of geometry. For deferred rendering, it's normally fill rate we're trying to control, by tightly bounding the region of the frame and depth range that each light draws into. \$\endgroup\$ – DMGregory Apr 9 '17 at 18:58
  • \$\begingroup\$ My understanding is that deferred shading is specifically for multiple lights, as rendering geometry is cheap, but lighting is expensive, and bounding the amount of geometry that requires lighting calculations, allowing more lights to be processed. Either way, I'm not concerned with best practices at this time, and only interested in the possible methods which could be employed to achieve what I described. \$\endgroup\$ – Ian Young Apr 9 '17 at 19:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.