Jitter in shadow map while moving light

Hello, I have an issue with the shadow map that jitters when it moves.
The project is the same as discussed there :shaderMaterial and 300es imports in MRT - #37 by Mikael
So I have a an MRT as target rendering for the whole scene and the meshes of the scenery is made of thin instances.
My goal is to reduce the frustum to the part that are supposed to be viewed and then move it with the character. (so narrower then finer shadow map)
I’m not done with the maths of evaluating the ortho top, bottom,… yet that I already see that moving the light source or its angle makes the shadow jitter.
I’ve recorded it:

So I create a playground to try reproducing it:
https://playground.babylonjs.com/#8RU8Q3#51
but in vain, the jittering doesn’t appear and weirdly while the sphere’s instances cast shadow it seem that only one sphere in the middle renders, weird.

Dunno if you guys might have leads to what produces it so I can reproduce it in the playground and maybe fix it.

For info I’m using the 5.0.0-alpha-44 but I think it happened with the 4.2 too.

Thanks in advance!

You need to add some includes in your custom vertex shader to support instances / thin instances:
https://playground.babylonjs.com/#8RU8Q3#56

2 Likes

indeed thanks!
ok but in the example the textures are rendered on planes but my goal is that the main MRT is the target render so I use the pipeline effect to bring it back to the main buffer which is the way I render on my game thus I think that way might reproduce the jittering.
https://playground.babylonjs.com/#8RU8Q3#63
but I have an e is undefined and I don’t know where it comes from.

Couple things:

  1. When you construct your renderPass, you want zoneMaterialPass, not this.zoneMaterialPass. That’s why your post process is undefined.
  2. You reference the constant ZONE_RENDER_TEXTURE but you haven’t defined it anywhere.

Does that help?

1 Like

https://playground.babylonjs.com/#8RU8Q3#64
yes I forgot that this copy pasting, so I managed to reproduce the jittering effect!
Now we have the real bug I’m trying to fix.
you notice I’ve putted slow updated to put emphasis to that jitter, it shows more by flashing at the beginning of the animation.

1 Like

Yep, I definitely see the jittering. @Evgeni_Popov any ideas?

It’s an ordering problem because the MRT is generated before the shadow map is (re)generated for the new light position, so it’s using the old shadow map from the previous frame. Push the MRT in the camera.customRenderTargets array instead of scene.customRenderTargets:

https://playground.babylonjs.com/#8RU8Q3#66

That way, the MRT will be generated after the shadow map.

4 Likes

It works, nice thanks!
Is there any documentation on the rendering orders such as that one to have a deeper understanding?

1 Like

No, the best debugging tool to use here is Spector.js: Spector.js - Chrome Web Store

4 Likes

Holly… @Evgeni_Popov you are the best !!!

2 Likes