GLTF child not blocking shadows?

Hello guys, I am new to shadows and things so please dont eat me, but it seems like my GLTF object’s children simply do not block/cast shadows, pretty weird if you ask me.

Here’s my code:

    renderer.shadowMap.enabled = true;
    var light = new THREE.DirectionalLight(0xffffff);
    light.castShadow = true;
    light.shadowDarkness = 1;
    renderer.shadowMapSoft = true;
    light.shadowCameraNear = 2;
	light.shadowCameraFar = 5;
	light.shadowCameraLeft = -0.5;
	light.shadowCameraRight = 0.5;
	light.shadowCameraTop = 0.5;
	light.shadowCameraBottom = -0.5;
	scene.add(light);
	light.position.x = 500;

&

var gltfloader = new GLTFLoader();
gltfloader.load("./maps/dd2fix/de_dust2.glb", function(object) {
	var obj = object.scene;
	scene.add(obj);
	obj.castShadow = true;
	obj.receiveShadow = true;
	obj.scale.x = obj.scale.y = obj.scale.z = 0.175;
	obj.traverse(function(child) {
		if(child.isMesh) {
			child.castShadow = true;
			child.receiveShadow = true;
		}
	});
});

Lastly, here is what I get to see, when running this code:

As you can see, both in the tunnel and the side of the stairs, they are lit like there is nothing in front of them.

You are not configuring the shadow camera correctly. It should be something like:

light.shadow.camera.top = 0.5;
light.shadow.camera.bottom = - 0.5;
light.shadow.camera.left = - 0.5;
light.shadow.camera.right = 0.5;
light.shadow.camera.near = 2;
light.shadow.camera.far = 5;

I could also imagine that the frustum of your shadow camera is too small. You can debug the frustum visually by adding a camera helper to your scene:

scene.add( new THREE.CameraHelper( light.shadow.camera ) );

BTW: It seems you are using an outdated code reference. Stuff like shadowDarkness or shadowMapSoft do not exist.

Uh, thanks for that all, but I guess, that this is not really ideal, right


I angled the camera weirdly, just so you can see the shadow still passes through a wall

Depending on your screenshot, the shadow camera frustum is too small.

1 Like