3

I keep running into a weird problem with spot light's shadow camera. From all the examples it seems trivial, yet when I write the same thing, the shadow's camera is fixed at 0, 0, 0.

Even when I set the camera position myself at the end of animation loop, the camera helper shows it at the center of the scene and no shadow is drawn.

Is that a bug?

Here is my code: https://jsfiddle.net/Eskel/stm4v8k7/2/ (the orange lines is the shadow camera helper)

light = new THREE.SpotLight();
light.position.set(1000, 1000, 1000);
light.target = scene;
light.castShadow = true;
scene.add(light);

Nothing fancy, I'm just adding a light, setting a position and expecting a shadow to be drawn. Using r77 release.

Eskel
  • 795
  • 1
  • 8
  • 21

1 Answers1

3

You need to set the following for shadow support and for the shadow map helper to work properly:

renderer.shadowMap.enabled = true;

three.js r.77

WestLangley
  • 102,557
  • 10
  • 276
  • 276
  • I always forget this setting :( Thank you – Eskel Jun 13 '16 at 09:40
  • The shadow now works (when I move the light closer) but setting of shadow.camera.far doesn't. Any idea what that is? https://jsfiddle.net/stm4v8k7/3/ – Eskel Jun 13 '16 at 10:00
  • 1
    See [this answer](http://stackoverflow.com/questions/37581812/shadow-is-abnormally-shaped-for-meshlambertmaterial-in-three-js-r76/37644913#37644913). – WestLangley Jun 13 '16 at 11:44
  • Interesting, thanks. "Frustrum is set to match light fov" sounds good but I don't see how it explains anything I'm seeing. My light here has long enough view that the shadow simply doesn't match. The three.js change prevents me to set shadow's camera clipping manually? What's the benefit of that? I have to specify my own frustrum for such a basic thing? – Eskel Jun 14 '16 at 11:07
  • Ah I see the problem, the SpotLight helper doesn't show the light's true distance value. So the change is ok I guess, the helper is not. Thank you – Eskel Jun 14 '16 at 11:11