Skip to content

Commit

Permalink
SpotLight: Implemented @sgrif's penumbra with @WestLangley suggestion…
Browse files Browse the repository at this point in the history
…s. See #5080.
  • Loading branch information
mrdoob committed Feb 8, 2016
1 parent 8e5c48c commit b1f94da
Show file tree
Hide file tree
Showing 7 changed files with 10 additions and 10 deletions.
2 changes: 1 addition & 1 deletion src/lights/Light.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ THREE.Light.prototype.toJSON = function ( meta ) {
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;
if ( this.exponent !== undefined ) data.object.exponent = this.exponent;
if ( this.penumbra !== undefined ) data.object.penumbra = this.penumbra;

return data;

Expand Down
6 changes: 3 additions & 3 deletions src/lights/SpotLight.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* @author alteredq / http://alteredqualia.com/
*/

THREE.SpotLight = function ( color, intensity, distance, angle, exponent, decay ) {
THREE.SpotLight = function ( color, intensity, distance, angle, penumbra, decay ) {

THREE.Light.call( this, color, intensity );

Expand All @@ -15,7 +15,7 @@ THREE.SpotLight = function ( color, intensity, distance, angle, exponent, decay

this.distance = ( distance !== undefined ) ? distance : 0;
this.angle = ( angle !== undefined ) ? angle : Math.PI / 3;
this.exponent = ( exponent !== undefined ) ? exponent : 10;
this.penumbra = ( penumbra !== undefined ) ? penumbra : 0;
this.decay = ( decay !== undefined ) ? decay : 1; // for physically correct lights, should be 2.

this.shadow = new THREE.LightShadow( new THREE.PerspectiveCamera( 50, 1, 0.5, 500 ) );
Expand All @@ -31,7 +31,7 @@ THREE.SpotLight.prototype.copy = function ( source ) {

this.distance = source.distance;
this.angle = source.angle;
this.exponent = source.exponent;
this.penumbra = source.penumbra;
this.decay = source.decay;

this.target = source.target.clone();
Expand Down
2 changes: 1 addition & 1 deletion src/loaders/ObjectLoader.js
Original file line number Diff line number Diff line change
Expand Up @@ -514,7 +514,7 @@ THREE.ObjectLoader.prototype = {

case 'SpotLight':

object = new THREE.SpotLight( data.color, data.intensity, data.distance, data.angle, data.exponent, data.decay );
object = new THREE.SpotLight( data.color, data.intensity, data.distance, data.angle, data.penumbra, data.decay );

break;

Expand Down
2 changes: 1 addition & 1 deletion src/renderers/WebGLRenderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -2702,7 +2702,7 @@ THREE.WebGLRenderer = function ( parameters ) {
uniforms.direction.transformDirection( viewMatrix );

uniforms.angleCos = Math.cos( light.angle );
uniforms.exponent = light.exponent;
uniforms.penumbra = Math.cos( light.angle ) * light.penumbra;
uniforms.decay = ( light.distance === 0 ) ? 0.0 : light.decay;

uniforms.shadow = light.castShadow;
Expand Down
4 changes: 2 additions & 2 deletions src/renderers/shaders/ShaderChunk/lights_pars.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@
float distance;
float decay;
float angleCos;
float exponent;
float penumbra;

int shadow;
float shadowBias;
Expand All @@ -90,7 +90,7 @@
if ( spotEffect > spotLight.angleCos ) {

float spotEffect = dot( spotLight.direction, directLight.direction );
spotEffect = saturate( pow( saturate( spotEffect ), spotLight.exponent ) );
spotEffect *= clamp( ( spotEffect - spotLight.angleCos ) / spotLight.penumbra, 0.0, 1.0 );

directLight.color = spotLight.color;
directLight.color *= ( spotEffect * calcLightAttenuation( length( lVector ), spotLight.distance, spotLight.decay ) );
Expand Down
2 changes: 1 addition & 1 deletion src/renderers/shaders/UniformsLib.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ THREE.UniformsLib = {
"direction": { type: "v3" },
"distance": { type: "f" },
"angleCos": { type: "f" },
"exponent": { type: "f" },
"penumbra": { type: "f" },
"decay": { type: "f" },

"shadow": { type: "i" },
Expand Down
2 changes: 1 addition & 1 deletion src/renderers/webgl/WebGLLights.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ THREE.WebGLLights = function () {
color: new THREE.Color(),
distance: 0,
angleCos: 0,
exponent: 0,
penumbra: 0,
decay: 0,

shadow: false,
Expand Down

0 comments on commit b1f94da

Please sign in to comment.