Issue with cascadedshadowgenerator and thin instances?

Hi,
I am trying to use thin instances with the cascaded shadow generator.

The issue I am facing is an ugly distorted result. Please have a look at the picture.
This is a plane.

Please note that the distortion follows the camera, what you see on top of the first picture is always at the same place, granted that I keep the same direction.

Everything else (scene, camera) set to default values.


        let custom_mesh = new Mesh("custom", globalThis.scene);

        let vd = new VertexData();
        vd.positions = raw_buffer_root;
        vd.indices = [...Array(raw_buffer_root.length / 3).keys()];
        vd.normals = [];
        VertexData.ComputeNormals(vd.positions, vd.indices, vd.normals);

        let material1 = new PBRMetallicRoughnessMaterial(
          "testmat",
          globalThis.scene
        );

        material1.backFaceCulling = false;
        material1.wireframe = false;
        
        material1.freeze()

        custom_mesh.material = material1;
        let buffer_matrices = Float32Array.from(array_mats);
        let buffer_colors = new Float32Array(4 * array_mats.length);
        ...
        //loop to set the color
        ...
        custom_mesh.thinInstanceSetBuffer("matrix", buffer_matrices, 16, true);
        custom_mesh.thinInstanceSetBuffer("color", buffer_colors, 4, true);
        custom_mesh.checkCollisions = false;
        custom_mesh.receiveShadows = true;
        custom_mesh.freezeWorldMatrix()
        custom_mesh.alwaysSelectAsActiveMesh = true

        globalThis.shadowGenerator.addShadowCaster(custom_mesh, true);

        // and at the end
        globalThis.scene.freezeActiveMeshes()

I can’t prep a PG, sorry, but if I disable

globalThis.shadowGenerator.addShadowCaster(custom_mesh, true);

Everything looks perfect but has no shadows.

I am not sure what is going on.

my light setup:

    globalThis.light = new DirectionalLight("DirectionalLight", new Vector3(-1900 , -1900 , 0), globalThis.scene);
    globalThis.light.intensity = 9.4;
    globalThis.light.position = new Vector3(10 , 10, 0.1);

    globalThis.shadowGenerator = new CascadedShadowGenerator(2048, globalThis.light);

Decreasing the light intensity reduces the issue, but it is still there.
maxZ, minZ untouched.
Any idea?

thanks

I also see this in that PG:
https://playground.babylonjs.com/#AU5641

So the question now is: is it only me?
I run an Nvidia RTX 2060 with drivers 515 on Linux.

It seems your problem is coming from the bias value.

See Shadows | Babylon.js Documentation in the doc for more details.

1 Like

Thanks Evgeni, that was it :+1: