The shadow does not work with object .babylon

The shadow does not work with object .babylon

I have a problem, I have a scene with an exported .babylon file, I can not make all objects shadow and the ground receives shadows, I need help with this, please someone has an idea?

sorry for my english, is bit bad.

and her the code

Blockquote

Babylon - Getting Started !-- Babylon.js --> html, body { overflow: hidden; width : 100%; height : 100%; margin : 0; padding : 0; }
    #renderCanvas {
        width   : 100%;
        height  : 100%;
        touch-action: none;
    }
    </style>
var canvas = document.getElementById("renderCanvas");
    // <reference path="../../dist/preview release/babylon.d.ts"/>
    // <reference path="../../dist/preview release/materialsLibrary/babylon.cellMaterial.d.ts"/>
    
    var createScene = function() {
    	var scene = new BABYLON.Scene(engine);
    	scene.clearColor = new BABYLON.Color4(0, 0, 0, 0)
        scene.ambientColor = new BABYLON.Color3(0.4, 0.4, 0.4)
    
    	var camera = new BABYLON.ArcRotateCamera("Camera", 0, Math.PI / 2, 12, BABYLON.Vector3.Zero(), scene);
    	camera.attachControl(canvas, true, true);
        
        var light = new BABYLON.DirectionalLight('light', new BABYLON.Vector3(0, -1, 1), scene)
        
        var SphereTexture = new BABYLON.StandardMaterial("ground", scene);
        SphereTexture.diffuseTexture = new BABYLON.Texture("textures/amiga.jpg", scene);
        SphereTexture.diffuseTexture.uScale = 1;
        SphereTexture.diffuseTexture.vScale = 1;
        SphereTexture.specularColor = new BABYLON.Color3(0, 0, 0);
        
        

        var shadowGenerator = new BABYLON.ShadowGenerator(1024, light);
        shadowGenerator.useExponentialShadowMap = true;
        shadowGenerator.useBlurExponentialShadowMap = true;
        shadowGenerator.useKernelBlur = true;
        shadowGenerator.blurKernel = 500;
        shadowGenerator.setDarkness(0.5);
    
    	//var knot = BABYLON.Mesh.CreateTorusKnot("knot", 2, 0.5, 128, 64, 2, 3, scene);
        BABYLON.SceneLoader.Append("./", "bobermaneditor1.babylon", scene, function (newMeshes) {
        shadowGenerator.addShadowCaster(newMeshes[1]);
        });
        
        
        
    	var cell = new BABYLON.CellMaterial("cell", scene);
    	cell.diffuseTexture = new BABYLON.Texture("textures/amiga.jpg", scene);
    	cell.diffuseTexture.uScale = cell.diffuseTexture.vScale = 3;
    	cell.computeHighLevel = true;
    
    	return scene;
    };
    
    var engine = new BABYLON.Engine(canvas, true, { preserveDrawingBuffer: true, stencil: true });
    var scene = createScene();

    engine.runRenderLoop(function () {
        if (scene) {
            scene.render();
        }
    });

    // Resize
    window.addEventListener("resize", function () {
        engine.resize();
    });
</script>

Hi.

I am not sure but, try setting the position of the directional light.

light.position = new BABYLON.Vector3(x,y,z).

Here is a little playground to test it out.

https://www.babylonjs-playground.com/#20OAV9#480 (uncomment line 8 to see what happen)

nothing dude :c my .babylon is this

Blockquote

BABYLON.SceneLoader.Append("./", "bobermaneditor1.babylon", scene, function (newMeshes) {
        shadowGenerator.addShadowCaster(newMeshes[1]);
        });

Hmm. I am not sure then. Long shot guess xD -> maybe set newMeshes[0] instead of newMeshes[1];
In any case I believe that you have to define position for directional light if you want shadows from it. So whatever is a problem, set that position.

But without some testing and tweaking I cannot help you more (if you can set some playground example would be nice).

Or wait for someone more experienced than me for proper answer. :slight_smile:

A PG would help, is there more than one mesh loaded with your function?