Skip to content

Commit

Permalink
SpotLightShadow.cameraAutoUpdate -> Light.shadowAutoUpdate
Browse files Browse the repository at this point in the history
  • Loading branch information
mbredif committed Aug 9, 2018
1 parent c6b05ad commit 9a706ef
Show file tree
Hide file tree
Showing 16 changed files with 37 additions and 36 deletions.
6 changes: 6 additions & 0 deletions docs/api/lights/Light.html
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,12 @@ <h3>[property:Boolean isLight]</h3>
You should not change this, as it used internally for optimisation.
</p>

<h3>[property:Boolean shadowAutoUpdate]</h3>
<p>
If set to *true*, its light shadow will be updated each frame using
[page:LightShadow.update LightShadow.update]) (e.g. [page:SpotLightShadow.update SpotLightShadow.update]).
The default is *false*.
</p>

<h2>Methods</h2>
<p>
Expand Down
7 changes: 7 additions & 0 deletions docs/api/lights/SpotLight.html
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,13 @@ <h3>[property:Object3D target]</h3>
The spotlight will now track the target object.
</p>

<h3>[property:Boolean shadowAutoUpdate]</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>

<h2>Methods</h2>

Expand Down
5 changes: 5 additions & 0 deletions docs/api/lights/shadows/LightShadow.html
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,11 @@ <h3>[method:Object toJSON]()</h3>
Serialize this LightShadow.
</p>

<h3>[method:void update]( [param:Light light] )</h3>
<p>
Updates this LightShadow (e.g. [page:SpotLightShadow.update SpotLightShadow.update]).
</p>

<h2>Source</h2>

[link:https://github.com/mrdoob/three.js/blob/master/src/lights/[name].js src/lights/[name].js]
Expand Down
17 changes: 1 addition & 16 deletions docs/api/lights/shadows/SpotLightShadow.html
Original file line number Diff line number Diff line change
Expand Up @@ -79,25 +79,10 @@ <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 />

You should not change this, as it used internally for optimisation.
</p>

<h2>Methods</h2>
See the base [page:LightShadow LightShadow] class for common methods.

<h3>[method:SpotLightShadow update]( [param:SpotLight light] )</h3>
<h3>[method:void update]( [param:SpotLight light] )</h3>
<p>
Updates the internal perspective [page:.camera camera] based on the passed in [page:SpotLight light].
</p>
Expand Down
2 changes: 1 addition & 1 deletion examples/webgl_geometry_spline_editor.html
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@
light.shadow.camera.aspect = 1;
light.shadow.camera.near = 200;
light.shadow.camera.far = 2000;
light.shadow.cameraAutoUpdate = false;
light.shadowAutoUpdate = false;
light.shadow.bias = -0.000222;
light.shadow.mapSize.width = 1024;
light.shadow.mapSize.height = 1024;
Expand Down
8 changes: 3 additions & 5 deletions examples/webgl_lights_spotlight.html
Original file line number Diff line number Diff line change
Expand Up @@ -139,8 +139,6 @@

function render() {

spotLight.shadow.update(spotLight);

lightHelper.update();

shadowCameraHelper.update();
Expand All @@ -160,7 +158,7 @@
angle: spotLight.angle,
penumbra: spotLight.penumbra,
decay: spotLight.decay,
cameraAutoUpdate: spotLight.shadow.cameraAutoUpdate
shadowAutoUpdate: spotLight.shadowAutoUpdate
}

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

} );

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

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

} );
Expand Down
2 changes: 1 addition & 1 deletion examples/webgl_shading_physical.html
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@
sunLight.shadow.camera.aspect = 1;
sunLight.shadow.camera.near = shadowConfig.shadowCameraNear;
sunLight.shadow.camera.far = shadowConfig.shadowCameraFar;
sunLight.shadow.cameraAutoUpdate = false;
sunLight.shadowAutoUpdate = false;
sunLight.shadow.bias = shadowConfig.shadowBias;

scene.add( sunLight );
Expand Down
2 changes: 1 addition & 1 deletion examples/webgl_shadowmap.html
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@
light.shadow.camera.aspect = 1;
light.shadow.camera.near = 1200;
light.shadow.camera.far = 2500;
light.shadow.cameraAutoUpdate = false;
light.shadowAutoUpdate = false;

light.shadow.bias = 0.0001;

Expand Down
2 changes: 1 addition & 1 deletion examples/webgl_shadowmap_performance.html
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@
light.shadow.camera.aspect = 1;
light.shadow.camera.near = 700;
light.shadow.camera.far = FAR;
light.shadow.cameraAutoUpdate = false;
light.shadowAutoUpdate = false;

light.shadow.bias = 0.0001;

Expand Down
5 changes: 5 additions & 0 deletions src/helpers/SpotLightHelper.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,11 @@ SpotLightHelper.prototype.update = function () {
return function update() {

this.light.updateMatrixWorld();
if ( this.light.shadowAutoUpdate ) {

this.light.shadow.update( this.light );

}

var coneLength = this.light.distance ? this.light.distance : 1000;
var coneWidth = coneLength * Math.tan( this.light.angle );
Expand Down
1 change: 1 addition & 0 deletions src/lights/Light.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ function Light( color, intensity ) {
this.intensity = intensity !== undefined ? intensity : 1;

this.receiveShadow = undefined;
this.shadowAutoUpdate = false;

}

Expand Down
4 changes: 3 additions & 1 deletion src/lights/LightShadow.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,9 @@ Object.assign( LightShadow.prototype, {

return object;

}
},

update: function ( ) { }

} );

Expand Down
1 change: 1 addition & 0 deletions src/lights/SpotLight.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ function SpotLight( color, intensity, distance, angle, penumbra, decay ) {
this.decay = ( decay !== undefined ) ? decay : 1; // for physically correct lights, should be 2.

this.shadow = new SpotLightShadow();
this.shadowAutoUpdate = true;

}

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

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

}

SpotLightShadow.prototype = Object.assign( Object.create( LightShadow.prototype ), {

constructor: SpotLightShadow,

isSpotLightShadow: true,

update: function ( light ) {

var camera = this.camera;
Expand Down
2 changes: 1 addition & 1 deletion src/renderers/webgl/WebGLShadowMap.js
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ function WebGLShadowMap( _renderer, _objects, maxTextureSize ) {

}

if ( shadow.isSpotLightShadow && shadow.cameraAutoUpdate ) {
if ( light.shadowAutoUpdate ) {

shadow.update( light );

Expand Down
6 changes: 0 additions & 6 deletions test/unit/src/lights/SpotLightShadow.tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,6 @@ export default QUnit.module( 'Lights', () => {
} );

// PUBLIC STUFF
QUnit.todo( "isSpotLightShadow", ( assert ) => {

assert.ok( false, "everything's gonna be alright" );

} );

QUnit.todo( "update", ( assert ) => {

assert.ok( false, "everything's gonna be alright" );
Expand Down

0 comments on commit 9a706ef

Please sign in to comment.