Mesh can't receive and cast shadow in the same time

How can I set shadow for objects
For example, if I have a Cube, it should both accept a shadow and give a shadow, but now it can only give a shadow.
I need to configure it as both a shadow source and a shadow receiver

// box
        var box = BABYLON.Mesh.CreateBox("box", 4, scene);
        box.position.y = 2;
        box.position.z = -2;
        box.position.x = -7;
        box.material = new BABYLON.StandardMaterial("box", scene);
        box.material.emissiveTexture = new BABYLON.Texture("assets/textures/weathered_brown_planks_diff_2k.jpg", scene);
        box.material.specularColor = new BABYLON.Color3(0.04, 0.04, 0.04);
        box.receiveShadows = true;
        box.castShadow = true;

Welcome aboard!

receiveShadows=true should be all you need. Maybe the bias value of the shadow generator is too big? Try to lower it / set it to 0. Also, this page may help you find your problem:

If you could setup a repro in the Playground we could help you more.

Lastly, castShadow does not exist in Babylon, box.castShadow = true will do nothing. It’s shadowGenerator.addShadowCaster(box); that sets the box as a shadow caster for the shadow generator.

1 Like