Problems with portals and shadows

I’m continuing to struggle with issues around lighting and portals. What I am seeing right now is the wrong shadows - that is, when I’m outside the cave, the shadows cast on the ground are from objects inside the cave, and when I’m inside the cave, the shadows on the cave floor are from objects outside.

The cave interior is a separate Scene from the exterior with its own directional light. My rendering loop looks like this:

for each portal:
  -- adjust directional light position
  -- render the portal scene into a render target

main scene:
  -- adjust directional light position
  -- render the main scene

This means if there’s one portal in the main scene, then I’m rendering two scenes, each with it’s own call to renderer.render(), with each RAF.

If there’s no portal in the scene, the shadows appear correct.

My hypothesis is that somehow the shadow maps are lagging or not getting updated in time, that is each scene is getting rendered with the shadow map data from the previous render. I have not messed around with the shadow map’s autoUpdate, it is set to the default (true).

Does it make any change if you call renderer.clearDepth() manually before each rendering (that’s N+1 times in a rendering loop)?

I was already doing that (and the stencil buffer too).

I don’t know if there’s any relationship or connection between the main depth buffer and the shadow map depth buffer.

1 Like