Why dont shadows work

hi its my first time using babylon js, i want to create shadows but it doesnt work


var createScene = function () {
    var scene = new BABYLON.Scene(engine);
    scene.defaultMaterial.specularColor = new BABYLON.Color3.Black()

    var camera = new BABYLON.FreeCamera("camera1", new BABYLON.Vector3(0, 5, -10), scene);
    camera.setTarget(BABYLON.Vector3.Zero());
    camera.attachControl(canvas, true);

    var defaultpipeline = new BABYLON.DefaultRenderingPipeline("Default", false, scene, [camera])
    var tonemappingpipeline = new BABYLON.TonemapPostProcess("Tonemapping", BABYLON.TonemappingOperator.HejiDawson, devicePixelRatio, camera)
    var imageprocesspipeline = new BABYLON.ImageProcessingPostProcess("ImageProcessing", devicePixelRatio, camera)

    var light = new BABYLON.HemisphericLight("light", new BABYLON.Vector3(0, 1, 0), scene);
    light.intensity = 1;

    var light2 = new BABYLON.DirectionalLight("l2", new BABYLON.Vector3(0,-1,0),scene);
    light2.intensity = 0.4
    light2.position = new BABYLON.Vector3(0,5,-5)
    light2.shadowEnabled = true;

    var sphere = BABYLON.MeshBuilder.CreateSphere("sphere", { diameter: 2, segments: 32 }, scene);
    sphere.position.y = 1;
    var shadowGenerator = new BABYLON.ShadowGenerator(1024, light2);

    shadowGenerator.addShadowCaster(sphere);

    var ground = BABYLON.MeshBuilder.CreateGround("ground", { width: 6, height: 6,segments: 30 }, scene);
    ground.receiveShadows = true
    return scene;
};

It is actually working but your second light was so strong that you did not see the shadows:
Babylon.js Playground (babylonjs.com)

(btw: instead of pasting your code we recommend to share a Playground where we can interact with the code more easily)

2 Likes