To avoid excessive extra-rendering, I am planning on enclosing each lamp in a bounding volume (i.e. an Axis Aligned Bounding Box) and checking for intersections with each models bounding volume. I admit I haven't read up much on this just yet, there's something called 'Cascaded Shadows' that I need to look into, but I wanted to get your input on the algorithm I came up with today.
Here's the psuedo-code. Should be pretty self explanatory:
Algorithm:
PositionModels()
PositionsLights()
/////////////////
// SHADOW PASS //
/////////////////
for light in AllLights
{
// determine which models are hit by the light
for model in AllModels:
{
if (collision(light.volume, model.volume)
{
light.modelsInView.add(model);
// give model access to light data, including its shadow map
model.shadowCasters.add(light);
}
}
// if any models were hit by the light
if (light.modelsInView.Count > 0)
{
prepareShadowRender(light);
// render all models in this light's view to the light's shadowmap
for model in light.modelsInView
{
model.render();
}
}
}
//////////////////
// FINAL RENDER //
//////////////////
for model in models:
{
for light in model.shadowCasters:
{
shaderSetupShadowMap(light)
}
model.render();
}
Obviously the relevant lists need to be cleared after each rendered. Further optimizations can obviously be made, such as caching shadows for stable objects. But I think the general structure is captured here, wouldn't you say?
Any input/feedback would be appreciated.