0
votes

I'm currently trying to extend my current basic shadow mapping system to allow objects to have shadows cast from multiple lights. At the moment I have generated both shadow maps correctly but the problem is getting them both to be rendered on the scene.

My draw function currently goes like this:

for (int iLight = 0; iLight < mNumLights; iLight++)
{
    mShadowMap[iLight]->SetNullRenderTarget(md3dImmediateContext);

    DrawSceneToShadowMap(iLight);

    RestoreRenderTarget();

    SetShadowMap(iLight);
    SetShadowTransform(iLight);

    DrawScene();

}

mSwapChain->Present(0, 0)

Only the second shadow map is used and drawn, what am I missing here?

1
I would guess that you're overriding with the second DrawScene your firstly drawn scene. You need some kind of combination of the shadowmaps. Either you could set them both in the shader for the scene and combine them in the shader (faster, because you draw your scene only once to the backbuffer) or you could try to blend the second drawcall with the Min-BlendFunction over the first scene (easier, but slower) - Gnietschow
Thanks for the reply, I'm trying to implement the blending method first. I've set the blend operation to MIN, but what about the source and destination blend and alpha settings? - Wikaman1
They should be one, because if you imagine your two scenes, you want to take always the darker value, there should be the shadow. Keep in mind to starting to apply the blendfunction only with second shadow-iteration. The first iteration should be rendered normally to the backbuffer. - Gnietschow
Getting some strange effects... the cubes in the scene are just becoming transparent. Here's the code I'm using if you want to have a look, I appreciate all the help anyway :) pastebin.com/U2CmqcGA - Wikaman1

1 Answers

0
votes

The two standard ways of combining shadow maps in a forward renderer are either to do multi-pass lighting with additive blending where each pass adds in the light contribution from a different light or single-pass lighting where the shader loops over lights in the scenes and accumulates their light contributions. MIN blending isn't really the right way to combine contributions from multiple lights in a multi-pass lighting approach. I'd suggest trying additive blending instead.