From 9bec2f036316cb6561a141098478fd2605895de6 Mon Sep 17 00:00:00 2001 From: "Mr.doob" Date: Fri, 20 Nov 2015 20:49:53 -0500 Subject: [PATCH] Added intensity to Light (thus AmbientLight). See #7621. --- src/lights/AmbientLight.js | 4 ++-- src/lights/DirectionalLight.js | 5 +---- src/lights/HemisphereLight.js | 4 +--- src/lights/Light.js | 7 +++++-- src/lights/PointLight.js | 4 +--- src/lights/SpotLight.js | 4 +--- src/renderers/WebGLRenderer.js | 6 +++--- 7 files changed, 14 insertions(+), 20 deletions(-) diff --git a/src/lights/AmbientLight.js b/src/lights/AmbientLight.js index d7b812a158..450574d2c0 100644 --- a/src/lights/AmbientLight.js +++ b/src/lights/AmbientLight.js @@ -2,9 +2,9 @@ * @author mrdoob / http://mrdoob.com/ */ -THREE.AmbientLight = function ( color ) { +THREE.AmbientLight = function ( color, intensity ) { - THREE.Light.call( this, color ); + THREE.Light.call( this, color, intensity ); this.type = 'AmbientLight'; diff --git a/src/lights/DirectionalLight.js b/src/lights/DirectionalLight.js index 9f8fbee919..033fc49413 100644 --- a/src/lights/DirectionalLight.js +++ b/src/lights/DirectionalLight.js @@ -5,7 +5,7 @@ THREE.DirectionalLight = function ( color, intensity ) { - THREE.Light.call( this, color ); + THREE.Light.call( this, color, intensity ); this.type = 'DirectionalLight'; @@ -14,8 +14,6 @@ THREE.DirectionalLight = function ( color, intensity ) { this.target = new THREE.Object3D(); - this.intensity = ( intensity !== undefined ) ? intensity : 1; - this.shadow = new THREE.LightShadow( new THREE.OrthographicCamera( - 500, 500, 500, - 500, 50, 5000 ) ); }; @@ -27,7 +25,6 @@ THREE.DirectionalLight.prototype.copy = function ( source ) { THREE.Light.prototype.copy.call( this, source ); - this.intensity = source.intensity; this.target = source.target.clone(); this.shadow = source.shadow.clone(); diff --git a/src/lights/HemisphereLight.js b/src/lights/HemisphereLight.js index 46dcabe9b0..4ce6970fed 100644 --- a/src/lights/HemisphereLight.js +++ b/src/lights/HemisphereLight.js @@ -4,7 +4,7 @@ THREE.HemisphereLight = function ( skyColor, groundColor, intensity ) { - THREE.Light.call( this, skyColor ); + THREE.Light.call( this, skyColor, intensity ); this.type = 'HemisphereLight'; @@ -14,7 +14,6 @@ THREE.HemisphereLight = function ( skyColor, groundColor, intensity ) { this.updateMatrix(); this.groundColor = new THREE.Color( groundColor ); - this.intensity = ( intensity !== undefined ) ? intensity : 1; }; @@ -26,7 +25,6 @@ THREE.HemisphereLight.prototype.copy = function ( source ) { THREE.Light.prototype.copy.call( this, source ); this.groundColor.copy( source.groundColor ); - this.intensity = source.intensity; return this; diff --git a/src/lights/Light.js b/src/lights/Light.js index 8fb3a354a1..b7d9809d7d 100644 --- a/src/lights/Light.js +++ b/src/lights/Light.js @@ -3,13 +3,14 @@ * @author alteredq / http://alteredqualia.com/ */ -THREE.Light = function ( color ) { +THREE.Light = function ( color, intensity ) { THREE.Object3D.call( this ); this.type = 'Light'; this.color = new THREE.Color( color ); + this.intensity = intensity !== undefined ? intensity : 1; this.receiveShadow = undefined; @@ -23,6 +24,7 @@ THREE.Light.prototype.copy = function ( source ) { THREE.Object3D.prototype.copy.call( this, source ); this.color.copy( source.color ); + this.intensity = source.intensity; return this; @@ -33,9 +35,10 @@ THREE.Light.prototype.toJSON = function ( meta ) { var data = THREE.Object3D.prototype.toJSON.call( this, meta ); data.object.color = this.color.getHex(); + data.object.intensity = this.intensity; + if ( this.groundColor !== undefined ) data.object.groundColor = this.groundColor.getHex(); - if ( this.intensity !== undefined ) data.object.intensity = this.intensity; if ( this.distance !== undefined ) data.object.distance = this.distance; if ( this.angle !== undefined ) data.object.angle = this.angle; if ( this.decay !== undefined ) data.object.decay = this.decay; diff --git a/src/lights/PointLight.js b/src/lights/PointLight.js index 54872f4abf..d4de6a7328 100644 --- a/src/lights/PointLight.js +++ b/src/lights/PointLight.js @@ -5,11 +5,10 @@ THREE.PointLight = function ( color, intensity, distance, decay ) { - THREE.Light.call( this, color ); + THREE.Light.call( this, color, intensity ); this.type = 'PointLight'; - this.intensity = ( intensity !== undefined ) ? intensity : 1; this.distance = ( distance !== undefined ) ? distance : 0; this.decay = ( decay !== undefined ) ? decay : 1; // for physically correct lights, should be 2. @@ -24,7 +23,6 @@ THREE.PointLight.prototype.copy = function ( source ) { THREE.Light.prototype.copy.call( this, source ); - this.intensity = source.intensity; this.distance = source.distance; this.decay = source.decay; diff --git a/src/lights/SpotLight.js b/src/lights/SpotLight.js index 31550c4e8d..209e50edb6 100644 --- a/src/lights/SpotLight.js +++ b/src/lights/SpotLight.js @@ -4,7 +4,7 @@ THREE.SpotLight = function ( color, intensity, distance, angle, exponent, decay ) { - THREE.Light.call( this, color ); + THREE.Light.call( this, color, intensity ); this.type = 'SpotLight'; @@ -13,7 +13,6 @@ THREE.SpotLight = function ( color, intensity, distance, angle, exponent, decay this.target = new THREE.Object3D(); - this.intensity = ( intensity !== undefined ) ? intensity : 1; this.distance = ( distance !== undefined ) ? distance : 0; this.angle = ( angle !== undefined ) ? angle : Math.PI / 3; this.exponent = ( exponent !== undefined ) ? exponent : 10; @@ -30,7 +29,6 @@ THREE.SpotLight.prototype.copy = function ( source ) { THREE.Light.prototype.copy.call( this, source ); - this.intensity = source.intensity; this.distance = source.distance; this.angle = source.angle; this.exponent = source.exponent; diff --git a/src/renderers/WebGLRenderer.js b/src/renderers/WebGLRenderer.js index eae6b80dbd..29fb63e5ee 100644 --- a/src/renderers/WebGLRenderer.js +++ b/src/renderers/WebGLRenderer.js @@ -2663,9 +2663,9 @@ THREE.WebGLRenderer = function ( parameters ) { if ( light instanceof THREE.AmbientLight ) { - r += color.r; - g += color.g; - b += color.b; + r += color.r * intensity; + g += color.g * intensity; + b += color.b * intensity; } else if ( light instanceof THREE.DirectionalLight ) { -- GitLab