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);