I’ve imported a GTLF scene from Blender, and it seems like my models can either cast a shadow, or receive a shadow, but cannot do both. When both castShadow
and receiveShadow
are set to true, the model only casts a shadow. However, if I unset castShadow
, the model will properly receive shadows.
The example image shows two models, the top one has receiveShadow = true
and castShadow = false
, while the bottom one has both set to true. For the top one, a shadow properly shows for items sitting on top of the model, but for the bottom it does not, even though the shadow is received by the “wall” model. Changing castShadow = true
for the top model makes it cast a shadow, but no longer receive it.
Ideally both models would be able to both cast and receive shadows, but I’m not sure what might be causing the problem here. Is there someway I can make these objects both cast and receive shadows?
Relevant code:
// Renderer properties
renderer.gammaOutput = true;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = Three.PCFSoftShadowMap;
// Light Setup
const ptLight2 = new Three.PointLight( WHITE, 0.8, 70 );
ptLight2.position.set( 0.5, 6, 0 );
ptLight2.castShadow = true;
ptLight2.shadow.bias = 0.0001;
scene.add( ptLight2 );
helper = new Three.PointLightHelper(ptLight2);
scene.add(helper);
scene.add( new Three.CameraHelper( ptLight2.shadow.camera ) );
// Model Loader
gltfLoader.load("/images/room.glb", (gltf) => {
const root = gltf.scene;
scene.add(root);
root.traverse(obj => {
if(obj.isMesh) {
// Outside view things don't need to cast shadows
if(!obj.name.includes('Floor') && !(obj.name.includes('Wall') && !obj.name.includes('Shelf')) && !obj.name.includes('Door')) {
obj.castShadow = true;
}
obj.receiveShadow = true;
}
});
});
Object log from browser console
UPDATE: Commenting out ptLight2.shadow.bias = 0.0001;
seems to allow both casting and receiving, but causes significant artifacts in the shadows and across the render.