I am loading a model from GLTF, then I create lighting for the model from above (the Y-axis pointing down towards the OXZ plane). However, the result I get is that the shadows of the objects are behind the floor (img 1)
this is my code
const scene = new Scene();
const camera = new PerspectiveCamera(75, width / height, 0.1, 1000);
const renderer = new WebGLRenderer({ antialias: true });
renderer.toneMapping = ACESFilmicToneMapping; // Tone mapping Linear
renderer.toneMappingExposure = 1;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = PCFSoftShadowMap;
// Light
const directionalLight1 = new DirectionalLight(0xffeeff, 1);
directionalLight1.position.set(0, 5, 0);
directionalLight1.lookAt(0,0,0)
directionalLight1.castShadow = true;
directionalLight1.shadow.mapSize.width = 2048;
directionalLight1.shadow.mapSize.height = 2048;
directionalLight1.shadow.camera.near = 0.01;
directionalLight1.shadow.camera.far = 1000;
directionalLight1.shadow.camera.top = 100;
directionalLight1.shadow.camera.bottom = -100;
directionalLight1.shadow.camera.left = 100;
directionalLight1.shadow.camera.right = -100;
directionalLight1.shadow.bias = 0.0005;
scene.add(directionalLight1);
const ambientLight = new AmbientLight(0xffffff, 2);
scene.add(ambientLight);
I traversed each child of the loaded GLTF model:
- Objects that are floors will be set:
floor.receiveShadow = true;
floor.castShadow = false;
const material = floor.material as Material;
material.side = DoubleSide;
material.shadowSide = FrontSide;
Other objects will be set:
other.receiveShadow = false;
other.castShadow = true;
Is there any way to fix this?
Image 1 shows the shadow displayed on the back of the floor.
Image 2 shows the objects placed above the floor (but without any shadows).