Hello,
I’m trying to simulate the sun in a scene with a house model to see the how the shadow behaves.
I’ve got a funky shadow at the moment!
I don’t have an online repro as I don’t know where to upload my gltf file on a service that keeps the extension so that I’m still able to use the loader. If anyone knows of one please let me know and I may try to get a live repro.
Hopefully the pieces of code I’m about to share still help to see more clearly for someone knowing more than me
For the light, based on what I read, the DirectionalLight
seems to be the more appropriate (?).
Here’s what I’ve used:
this.light = new DirectionalLight(
'sunLight',
new Vector3(0, -1, -1),
this.scene
);
The movement you see is just for debugging, I’ve added:
setInterval(() => {
this.light.position.y -= 0.01;
}, 10);
For the ground I’ve got:
const ground = MeshBuilder.CreateGround(
'ground',
{ width: 40, height: 40, subdivisions: 2 },
this.scene
);
ground.receiveShadows = true;
And finally for the loading of the mesh and the shadows I’ve got:
const mesh = await SceneLoader.ImportMeshAsync(
undefined,
'./assets/',
'house-v1.gltf',
game.getScene()
);
const shadowGenerator = new ShadowGenerator(1024, game.getLight());
mesh.meshes.forEach((m) => {
shadowGenerator.addShadowCaster(m);
m.receiveShadows = true;
});
shadowGenerator.useExponentialShadowMap = true;
I don’t have anything else fancy in the scene except the ground and the house. How is the shadow behaving as such?
Thanks for any help (and do let me know how to get my mesh somewhere so I can provide a live repro please)