How can I force update while runtime?

I’m making 3d model viewer using babylon.js and I want to ensure high quality graphics that runs smoothly even on low end devices. So what I was trying to do was to set shadow map options heavy, then I update whenever I should update. I searched this for a while, and I found there is no method to force update the shadowmap. So I made this code like below.

var shadowGenerator = new …(4096,light);
shadowGenerator.getShadowMap().refreshRate = …RENDER_ONCE;

function update(){

//do things
shadowGenerator.getShadowMap().refreshRate = …RENDER_ONCE;

shadowGenerator.getShadowMap().refreshRate = …RENDER_ONEVERYFRAME;

And this caused to update shadowmap every frame and doesnt stop updating.

Hi SoHardToNameMyself!
Apologies but I’m not entirely sure what you’re trying to achieve with this? Is it to add meshes to the shadow map when they’re added to your scene?

I’m trying to render shadow map as less as I can so that the project would not be laggy

Ahh, then I’m afraid this is a bit out of my wheelhouse, have you tried both steps in this section? Perhaps the light.autoUpdateExtends property can be changed for the desired effect? Failing that, have you considered using something like Poisson Sampling instead of such a large shadow resolution?

I’m sorry but making light.autoUpdateExtends = false
didnt work…

I’m using high quality options with high resolution, so low resolution with high quality means nothing to me

I tested some cases and realized that shadowGenerator.getShadowMap().refreshRate = 0;
didnt worked. even only with render once option, it rendered shadowmap every frame.
And I didnt tell you that light was moving not the object.(if this helps you understanding)

Could you share a repro in the playground, it might be way simpler to try to troubleshoot your issue ?

RenderTargetTexture.refreshRate does work as expected:

This PG shows the depth map as generated by the shadow generator.

If you click “Render once”, you will see the depth map stops being updated and the last rendered one is used for all subsequent rendering, leading to wrong shadows when the light is rotating.

Click on the other buttons to see a refresh rate of “every frame”, “every 2 frames” and “every 10 frames”.

1 Like

Then how can I prevent shadow from rotating?

The light is rotating, so the shadow is rotating too…

If you don’t want the shadow to rotate, stop the light rotating :slight_smile:

If you still want the light to rotate for the other objects but not for the ones with shadows:

  • create a new light L with direction = last direction of the rotating light before you want it to stop for objects with shadows
  • exclude the objects with shadows from the rotating light
  • add the light L to the objects with shadows
  • exclude the objects without shadows from light L

When you click on “Render once”, the shadow stops moving (the ground is now lit with a static light) but the light is still rotating (you can see this on the sphere).

Click on any other button to make the shadow rotates again.