Friday, May 10, 2024
 Popular · Latest · Hot · Upcoming
154
rated 0 times [  159] [ 5]  / answers: 1 / hits: 37215  / 12 Years ago, thu, may 24, 2012, 12:00:00

Is it possible to create shadows from a DirectionalLight?



If I use SpotLight then I see a shadow, but if I use DirectionalLight it doesn't work.


More From » three.js

 Answers
26

Yes, you most definitely can use directional lights to cast shadows. You need to make sure you are not using MeshBasicMaterial as they don't support shadows. Use MeshLambertMaterial or MeshPhongMaterial instead.



You need to enable shadows for the renderer with something along these lines:



renderer.shadowMapEnabled = true;
renderer.shadowMapSoft = true;

renderer.shadowCameraNear = 3;
renderer.shadowCameraFar = camera.far;
renderer.shadowCameraFov = 50;

renderer.shadowMapBias = 0.0039;
renderer.shadowMapDarkness = 0.5;
renderer.shadowMapWidth = 1024;
renderer.shadowMapHeight = 1024;


And then you must enable shadow casting and shadow receiving per object and per light so you would have



dirLight.castShadow = true;
object.castShadow = true;
otherObject.receiveShadow = true;


Then, if the light and objects are placed at appropriate positions. dirLight will cause the shadow of object to be cast against otherObject.



[EDIT]: Here is a working demo for anyone looking to do something similar.


[#85374] Wednesday, May 23, 2012, 12 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
luna

Total Points: 698
Total Questions: 114
Total Answers: 93

Location: Israel
Member since Wed, Apr 14, 2021
3 Years ago
luna questions
;