Shadows not coming off smaller objects onto the floor

I have multiple objects on the ground right like this.


I’m wanting the cube itself to give off shadows such as behind it like this. .

It does however give shadows off onto the wall when its right on it however it does not do it on the floor neither when its a little distance from any other object like so.

The walls project light onto the floor like u can see on my game however on smaller objects it does not. I have no idea how it doesn’t and would like it to be how it is in the second screenshot :slight_smile:

At the moment in my code I am doing this.

var ligh = new BABYLON.DirectionalLight(“DirectionalLight”, new BABYLON.Vector3(1, -1, 1), scene);
ligh.diffuse = new BABYLON.Color3.FromHexString(light);
ligh.position = new BABYLON.Vector3(0, 0, 0);
ligh.intensity = 1;

this.shadowGenerator = new BABYLON.ShadowGenerator(7000, ligh);
this.shadowGenerator.usePoissonSampling = true;
this.shadowGenerator.bias = 0.000001;
this.shadowGenerator.useContactHardeningShadow = true;
this.shadowGenerator.setDarkness(0.2);
this.shadowGenerator.transparencyShadow = true
this.shadowGenerator.depthScale = 20000;

box.receiveShadows = true;

Try with Cascaded Shadow Maps and see if that helps.

Doc: Shadows with Cascaded Shadow Maps - Babylon.js Documentation

Note: don’t set a 7000x7000 texture size with CSM as the engine will create 4 textures of this size (if you use the default number of cascades)!

Hmm it seems i cannot use that kind of generator BABYLON.CascadedShadowGenerator is not a constructor

I updated the babylon core and this is the output

However shouldnt there be a shadow on the floor where i am stood aswell due to the ceiling also there is still no shadow around the cube objects to the right?

Have you followed the tips from the doc? Notably regarding the camera far plane.

Nothing changes when changing the camera.maxZ it just makes it extremely laggy but does nothing regarding the shadows

Would be great to see what you do in a playground or s live demo (preferably playground :grin:). Because my first question from the code above is - is the ground set to receive shadows?

1 Like

I think you might need to move the position, because at 0,0,0 low objects might get clipped from the shadowProjection. Think of the shadow pass as a camera at a position with the direction as its “rotation” and an orthographic projection. That is how the system generates the shadowMap (I think).

Take your direction and then normalize it then scale it by approx -half the scene size, then set that as your directional lights position. See if that fixes it. There are a lot of assumptions like that your scenes origin is 0,0,0 etc for this to work but I bet it will get you going the right way regardless.