0

I was trying to create shadows using a simple directional light & a shadow material, the problem is that the shadows seem to work properly, in a box and when model outside that zone it just disappear ???

image of the shadow at the bounds

here's the code :

var light = new THREE.DirectionalLight(0xffffff, 0);
renderer.shadowMap.enabled = true;
light.position.x = 100;
light.position.y = 150;
light.position.z = 0;
light.castShadow = true;
scene.add(light);

plane.receiveShadow = true;
plane.material = new THREE.ShadowMaterial({color: 0, opacity:1});
aymen ayoo
  • 92
  • 9
  • Have a look at the documentation: https://threejs.org/docs/index.html#api/lights/shadows/DirectionalLightShadow – prisoner849 Aug 12 '18 at 07:15
  • Of couse i did, before posting the question, and if you've read my code you can see am using a shadowMaterial not a standardMaterial – aymen ayoo Aug 12 '18 at 09:36

1 Answers1

1

You have to configure the internal shadow camera of DirectionalLight in order to get proper shadows. Use the following example as a template for your own code. The important part is:

var d = 5;
directionalLight.castShadow = true;
directionalLight.shadow.camera.left = - d;
directionalLight.shadow.camera.right = d;
directionalLight.shadow.camera.top = d;
directionalLight.shadow.camera.bottom = - d;

directionalLight.shadow.camera.near = 1;
directionalLight.shadow.camera.far = 20;

This configuration determines which part of your scene will create and receive shadows by the directional light. Be aware to setup the frustum as tight as possible in order to get sharp results.

Mugen87
  • 28,829
  • 4
  • 27
  • 50
  • Okay, that did control the wideness of the zone, but it changes the quality of the shadows as you said, so, is there a way to prevent this quality loss & Make the shadows all over the scene ? – aymen ayoo Aug 12 '18 at 10:14
  • 1
    This is tricky. You can try to increase the resolution of the shadow map but this only works to a certain degree. In some scenarios, you can try to move the directional light so the shadow is always present at the focus area (e.g. where the player is on the map). – Mugen87 Aug 12 '18 at 10:26