Shadow quality low with moving / "quivering" edges

I’m running into an issue with shadows where they start behaving strangely after some time.

Initial, everything-is-ok state:

However, after some time (a few minutes ~ 10+ minutes or so) of rendering, the shadows begin to become really choppy, and move around at the edges:

I’ve got no idea what’s causing this, maybe someone here with a lot of experience might have seen something like this before and could give me a pointer in the right direction.


In my scene, there’s a DirectionalLight as well as a HemisphericLight, neither of which change after initial creation/setup. I’ve got this following class abstracting all of my lights:

const SUN_LIGHT = 'sunLight';
const SUN_Y = 10;

const AMBIENT_LIGHT = 'ambientLight';
const AMBIENT_RELATIVE_INTENSITY = 0.7;

const DEFAULT_INTENSITY = 1;

export class WorldLight {

  private sun: BABYLON.DirectionalLight;
  private ambient: BABYLON.HemisphericLight;

  private intensity: number;

  constructor(
      mapConfig: MapConfig,
      scene: BABYLON.Scene,
  ) {
    const sunX = -mapConfig.width / 2;
    const sunZ = -mapConfig.depth / 2;

    this.sun = new BABYLON.DirectionalLight(SUN_LIGHT, new BABYLON.Vector3(0.33, -1, 0.33), scene);
    this.sun.position = new BABYLON.Vector3(sunX, SUN_Y, sunZ);

    this.ambient = new BABYLON.HemisphericLight(AMBIENT_LIGHT, new BABYLON.Vector3(0, 1, 0), scene);

    this.intensity = DEFAULT_INTENSITY;
    this.setIntensity();
  }

  setIntensity(intensity: number = DEFAULT_INTENSITY) {
    this.intensity = intensity;
    this.sun.intensity = intensity;
    this.ambient.intensity = intensity * AMBIENT_RELATIVE_INTENSITY;
  }

  get sunLight() {
    return this.sun;
  }
}

And this is how I use the shadow generator, nothing special here at all:

const shadows = new BABYLON.ShadowGenerator(size, worldLight.sunLight);
// ...
shadows.addShadowCaster(mesh);

Adding @Evgeni_Popov

Unfortunately, I don’t own a mac m1.

even without any caster mesh, do changing filtering/filtering quality and mapSize have an influence on framerate?

What is happening is probably the shadow frustrum size getting bigger as long as you grow the scene dynamically ???

Is it the same if you do nothing for ten minutes but rendering ?

@Cedric I think you replied to the wrong thread :slight_smile: (should be Shadow Generator + Shadows cause massive FPS drop on MacOS instead)

1 Like

As @sebavan said, if you add more and more (shadow caster) meshes to your scene, the frustum light will get bigger and bigger to encompass all the meshes and the precision of the shadows will decrease more and more.

You could use a cascaded shadow generator instead, but as you already have some perf problems I’m not sure it’s the solution (you can still try it)…

1 Like

I actually noticed it after leaving the game idle for a while and then coming back to my computer.

No changes occurred at all during this idle period except for rendering (and the monster meshes wandering around). However the issue is most pronounced on the tree meshes which never move

I’ll see if I can create a reproducible playground with this

1 Like

This would be awesome !!!