提交 b1f94dac 编写于 作者: M Mr.doob

SpotLight: Implemented @sgrif's penumbra with @WestLangley suggestions. See #5080.

上级 8e5c48cc
......@@ -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;
......
......@@ -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 );
......@@ -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 ) );
......@@ -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();
......
......@@ -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;
......
......@@ -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;
......
......@@ -68,7 +68,7 @@
float distance;
float decay;
float angleCos;
float exponent;
float penumbra;
int shadow;
float shadowBias;
......@@ -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 ) );
......
......@@ -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" },
......
......@@ -37,7 +37,7 @@ THREE.WebGLLights = function () {
color: new THREE.Color(),
distance: 0,
angleCos: 0,
exponent: 0,
penumbra: 0,
decay: 0,
shadow: false,
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册