Skip to content

Commit

Permalink
SpotLightShadow.cameraAutoUpdate
Browse files Browse the repository at this point in the history
  • Loading branch information
mbredif committed Aug 8, 2018
1 parent 6201c9a commit 2cbd289
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 3 deletions.
8 changes: 8 additions & 0 deletions docs/api/lights/shadows/SpotLightShadow.html
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,14 @@ <h3>[property:Camera camera]</h3>

</p>

<h3>[property:Boolean cameraAutoUpdate]</h3>
<p>
If set to *true*, the shadow camera will be automatically updated each frame to match the
geometry of the spotLight (a square frustum tightly fitting the cone of the spot light defined
by the [page:.angle angle] and [page:.distance distance] properties).
The default is *true*.
</p>

<h3>[property:Boolean isSpotLightShadow]</h3>
<p>
Used to check whether this or derived classes are spot light shadows. Default is *true*.<br /><br />
Expand Down
12 changes: 11 additions & 1 deletion examples/webgl_lights_spotlight.html
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,8 @@

function render() {

spotLight.shadow.update(spotLight);

lightHelper.update();

shadowCameraHelper.update();
Expand All @@ -157,7 +159,8 @@
distance: spotLight.distance,
angle: spotLight.angle,
penumbra: spotLight.penumbra,
decay: spotLight.decay
decay: spotLight.decay,
cameraAutoUpdate: spotLight.shadow.cameraAutoUpdate
}

gui.addColor( params, 'light color' ).onChange( function ( val ) {
Expand Down Expand Up @@ -203,6 +206,13 @@

} );

gui.add( params, 'cameraAutoUpdate').onChange( function ( val ) {

spotLight.shadow.cameraAutoUpdate = val;
render();

} );

gui.open();

}
Expand Down
7 changes: 6 additions & 1 deletion examples/webgl_shadowmap.html
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,12 @@

light.castShadow = true;

light.shadow = new THREE.LightShadow( new THREE.PerspectiveCamera( 50, 1, 1200, 2500 ) );
light.shadow.camera.fov = 50;
light.shadow.camera.aspect = 1;
light.shadow.camera.near = 1200;
light.shadow.camera.far = 2500;
light.shadow.cameraAutoUpdate = false;

light.shadow.bias = 0.0001;

light.shadow.mapSize.width = SHADOW_MAP_WIDTH;
Expand Down
6 changes: 5 additions & 1 deletion examples/webgl_shadowmap_performance.html
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,11 @@

light.castShadow = true;

light.shadow = new THREE.LightShadow( new THREE.PerspectiveCamera( 50, 1, 700, FAR ) );
light.shadow.camera.fov = 50;
light.shadow.camera.aspect = 1;
light.shadow.camera.near = 700;
light.shadow.camera.far = FAR;
light.shadow.cameraAutoUpdate = false;

light.shadow.bias = 0.0001;

Expand Down
3 changes: 3 additions & 0 deletions src/lights/SpotLightShadow.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { PerspectiveCamera } from '../cameras/PerspectiveCamera.js';
function SpotLightShadow() {

LightShadow.call( this, new PerspectiveCamera( 50, 1, 0.5, 500 ) );
this.cameraAutoUpdate = true;

}

Expand All @@ -20,6 +21,8 @@ SpotLightShadow.prototype = Object.assign( Object.create( LightShadow.prototype

update: function ( light ) {

if ( ! this.cameraAutoUpdate ) return;

var camera = this.camera;

var fov = _Math.RAD2DEG * 2 * light.angle;
Expand Down

0 comments on commit 2cbd289

Please sign in to comment.