Shadow based on FPS

how to enabled/ disable shadow in respect to FPS ?
for example : When FPS is less than 30 i want to disable shadow and when its more then 30 i want to enable it

How are you currently determining the FPS?

function CalculateFPS() {

if(!lastCalledTime) {
lastCalledTime = Date.now();
fps = 0;
return;
}
delta = (Date.now() - lastCalledTime)/1000;
lastCalledTime = Date.now();
fps = 1/delta;
// console.log(fps)

}

and this function has been calling in the render

Have you tried adding an if statement like:

if ( fps > 30 ) renderer.shadowMap.enabled = true;
else renderer.shadowMap.enabled = false;

Sure but nothing change!

Looks like you also need to clear the light.shadow.map. Try:

if ( fps > 30 ) {

    renderer.shadowMap.enabled = true;

} else {

    renderer.shadowMap.enabled = false;
    light.shadow.map = null;

}

Sorry for late reply,
Thanks for your help, i have tried:

  if ( fps > 30 )
  {
    renderer.shadowMapEnabled = true;
  }
  else
  {
    renderer.shadowMapEnabled = false;
    renderer.clearTarget( light.shadowMap );
  }

and it worked perfect Thanks man

3 Likes
renderer.clearTarget( light.shadowMap );

That’s probably a better solution than mine :slightly_smiling_face:

1 Like