Create a shadow just get a circle

my code:

var light1 = new BABYLON.DirectionalLight(
“light1”,
new BABYLON.Vector3(0.60, -0.7, 0.63),
scene
);
// eslint-disable-next-line no-unused-vars
// var light2 = new BABYLON.PointLight(
// “light2”,
// new BABYLON.Vector3(0, 1, -1),
// scene
// );

    // eslint-disable-next-line no-unused-vars
    var sphere = BABYLON.MeshBuilder.CreateSphere(
            "sphere",
            { diameter: 2 },
            scene
    );
    const mat = new BABYLON.StandardMaterial('groundMat')
    sphere.position = new BABYLON.Vector3(1,1.5,1);
    mat.diffuseColor = new BABYLON.Color3(1,1,1);
    var ground = BABYLON.MeshBuilder.CreateGround("ground", {width: 50, height: 50}, scene);
    // ground.material = mat;

     // light1.shadowMaxZ = 1111;
    const shadow = (scene,light) => {
      const shadowGenerator = new BABYLON.ShadowGenerator(1024,light);
       shadowGenerator.useExponentialShadowMap = true;
       shadowGenerator.usePoissonSampling = true; 

      // scene.meshes.forEach((meshItem)=>{
      //   console.log(meshItem)
      //   shadowGenerator.getShadowMap().renderList.push(meshItem);
      //   meshItem.receiveShadows = true;
      // })
      shadowGenerator.getShadowMap().renderList.push(scene.getMeshByName("sphere"));
      ground.receiveShadows = true;
      // shadowGenerator.getShadowMap().refreshRate = BABYLON.RenderTargetTexture.REFRESHRATE_RENDER_ONCE; 
    }

    shadow(scene,light1);
    return scene;

Your light is not well positionned. You can see this by using the new (in 5.0) “Display Frustum” option in the inspector for a directional light:

You can see that the light is inside the sphere.

If you move it a bit:

PG: Babylon.js Playground

6 Likes

I was waiting for these improved light helpers. Very nice :slight_smile:

thanks,its very helpful !

on the bottom

1 Like

Nice. Yup. Approved :grinning:

Note that this debug option works only with standard shadow generators, not with CSM.

its very helpful ! Thanks,I hope to update babylonjs-inspector as soon as possible