1
votes

I have a point-light shadow map program, but am a bit lost in how to control a multiple light scenario. How do I setup multiple lights, and does each light have its own 'depth texture'? If so, how are they combined for the final render of the scene (obviously, not all lights will be active all of the time)?

When thinking about this is does seem more logical to have separate (small) depth cube-maps, as opposed to one which is used for the entire scene (especially for a close quarters level as opposed to an open landscape), but implementing such a system just leaves me staring at the screen.

Thanks.

1

1 Answers

1
votes

There are a number of ways you can accomplish what you want. The method depends on your exact needs. If you're using OpenGL 2.1 or earlier, you can set up multiple lights by enabling multiple OpenGL lights:

glEnable(GL_LIGHTING);
glEnable(GL_LIGHT0);
glLightfv(GL_LIGHT0, <light 0 settings>);
glEnable(GL_LIGHT1);
glLightfv(GL_LIGHT1, <light 1 settings>);
...etc. with up to GL_MAX_LIGHTS lights

If you want more than GL_MAX_LIGHTS lights, or you're using OpenGL 3 or later, you'll need to pass the light data into your shader program as uniforms, for example.

When I've worked with shadows in the past, I've use a depth texture per light.

To combine them, you generally test each fragment against each light. If the fragment is visible to the light (i.e. not in shadow), then you add in the light's contribution. If the fragment is in shade (not visible to the light), then you don't add in that light's contribution.

If you need hundreds of lights or something like that, you can also look into Deferred Shading. (See also the Wikipedia entry on Deferred Shading.)