Search code examples
dynamicthree.jsshadowspotlight

How to change SpotLight shadowCameraNear parameter in THREE.js?


How do I change the shadowCameraNear and shadowCameraFar parameters of SpotLight?

In this demo, I change the shadowCameraNear parameter in the animation loop, but even though console.log() shows the change happened, the shadowCameraVisible helper object shows no change.

JSFiddle Demo


Solution

  • Here is the pattern you need to follow if you want to change a light's shadowCamera parameters dynamically.

    light.shadowCameraNear += 0.01;
    
    light.shadowCamera.near = light.shadowCameraNear;
    
    light.shadowCamera.updateProjectionMatrix(); // important
    

    updated fiddle: http://jsfiddle.net/3h8h1pzd/21/

    three.js r.69