Disabling PCF shadows (with scene optimizer) makes objects go invisible

Hello,

Here’s repro code (can’t save to playground, error 500).
The floor will disappear after 2s when the optimizer disables shadows (same effect with scene.disableShadows = true)
Without PCF the floor will still be there but small dark spots from the shadow are still visible
Switching ground.receiveShadows back & forth in the inspector will have the situation go back to normal

var createScene = function (engine) {
    const  scene = new BABYLON.Scene(engine);

    const camera = new BABYLON.ArcRotateCamera("Camera", -3 * Math.PI / 4, Math.PI / 3, 50, BABYLON.Vector3.Zero(), scene);
    camera.attachControl(canvas, true);
    
    const  light = new BABYLON.DirectionalLight("dir01", new BABYLON.Vector3(0, -1, 1), scene);
    light.position = new BABYLON.Vector3(0, 15, -30);

    var ground = BABYLON.Mesh.CreateGround("ground", 100, 100, 1, scene, false);
    ground.receiveShadows = true;

    // Shadow generator
    const shadowGenerator = new BABYLON.ShadowGenerator(1024, light);
    shadowGenerator.usePercentageCloserFiltering = true;


    BABYLON.SceneLoader.ImportMesh("him", "/scenes/Dude/", "Dude.babylon", scene, function (newMeshes2, particleSystems2, skeletons2) {
        var dude = newMeshes2[0];
        dude.scaling = new BABYLON.Vector3(0.2, 0.2, 0.2);
            
        //add dude, true means add children as well
        shadowGenerator.addShadowCaster(dude, true);
                
        scene.beginAnimation(skeletons2[0], 0, 100, true);

        var options = new BABYLON.SceneOptimizerOptions(70, 2000);
        options.addOptimization(new BABYLON.ShadowsOptimization(0));
        var optimizer = new BABYLON.SceneOptimizer(scene, options);
        optimizer.onNewOptimizationAppliedObservable.add(function (optim) {
            console.log(optim.getDescription());
        });        
        optimizer.start();

    });

    return scene;
};

We are currently working on a better fix, but as a workaround you can simply create a standard material and apply it to the ground (the bug is related to the fact that the ground uses the default material):

I have the same issue with my real scene which is a .glb import (with standard material already)

With this error
[.WebGL-000069F00456A300] GL_INVALID_OPERATION: Mismatch between texture format and sampler type (signed/unsigned/float/shadow).

It looks related to the fact that scene.shadowsEnabled=false (called in the optimizer) does not mark meshes as light dirty, like for instance changing Light.shadowEnabled does :


 public _markMeshesAsLightDirty() {
        for (const mesh of this.getScene().meshes) {
            if (mesh.lightSources.indexOf(this) !== -1) {
                mesh._markSubMeshesAsLightDirty();
            }
        }
    }

Adding this to my original code will make it work:

It’s another workaround to make it work, but we do have a problem with the existing code which should work, and we will see to fix it asap.