I'm trying to achieve multiple lights shadows. Currently my program works using only 1 spotlight as a light source that produces shadows. Well... I want to involve multiple lights to give a more realistic effect to my scene.
However, I'm facing a scenario which is a little bit unclear for me:
The steps I follow to create shadows is
a) Create FBO
b) Render scene from light's perspective using a depth texture attached to my FBO
c) Render the scene normally, using my texture from my FBO as a shadowmap texture in order to be able to sample it and creating finally shadows.
The steps I follow to create multiple shadows is
a) Create FBO1 and FBO2
b) Render scene from 1st light's perspective using a depth texture attached to my FBO1
c) Render the scene normally, using my texture from my FBO1 as a shadowmap texture in order to be able to sample it and creating finally shadows.
d) Render scene from 2nd light's perspective using a depth texture attached to my FBO2
e) Render the scene normally, using my texture from my FBO2 as a shadowmap texture in order to be able to sample it and creating finally shadows.
Now, the step 1) is pretty clear, works fine. When I manage to implement step 2), something happens: the shadows rendered will be the shadows of my last light (depending the order I call rendering methods). So in this case I get shadows only from my 2nd light.
If I reverse the order of calls (this order: a -> d -> e -> b -> c) and render first in my second FBO and then in my first FBO I get the shadows from my first light source. So basically I conclude: my shadows are not working simultaneously.
Is this the correct approach? (I've seen a solution which uses in fragment shader an array of shadowMaps, an array of lightSpace coordinates so this involves multiple uniforms... what do you think about this?)
Thanks