提交 67338a2a 编写于 作者: W WestLangley

Improved penumbra model for spotlight

上级 d6ff5b07
...@@ -2701,8 +2701,8 @@ THREE.WebGLRenderer = function ( parameters ) { ...@@ -2701,8 +2701,8 @@ THREE.WebGLRenderer = function ( parameters ) {
uniforms.direction.sub( _vector3 ); uniforms.direction.sub( _vector3 );
uniforms.direction.transformDirection( viewMatrix ); uniforms.direction.transformDirection( viewMatrix );
uniforms.angleCos = Math.cos( light.angle ); uniforms.coneCos = Math.cos( light.angle );
uniforms.penumbra = Math.cos( light.angle ) * light.penumbra; uniforms.penumbraCos = Math.cos( light.angle * ( 1 - light.penumbra ) );
uniforms.decay = ( light.distance === 0 ) ? 0.0 : light.decay; uniforms.decay = ( light.distance === 0 ) ? 0.0 : light.decay;
uniforms.shadow = light.castShadow; uniforms.shadow = light.castShadow;
......
...@@ -80,8 +80,8 @@ ...@@ -80,8 +80,8 @@
vec3 color; vec3 color;
float distance; float distance;
float decay; float decay;
float angleCos; float coneCos;
float penumbra; float penumbraCos;
int shadow; int shadow;
float shadowBias; float shadowBias;
...@@ -99,12 +99,11 @@ ...@@ -99,12 +99,11 @@
directLight.direction = normalize( lVector ); directLight.direction = normalize( lVector );
float lightDistance = length( lVector ); float lightDistance = length( lVector );
float spotEffect = dot( directLight.direction, spotLight.direction ); float angleCos = dot( directLight.direction, spotLight.direction );
if ( all( bvec2( spotEffect > spotLight.angleCos, testLightInRange( lightDistance, spotLight.distance ) ) ) ) { if ( all( bvec2( angleCos > spotLight.coneCos, testLightInRange( lightDistance, spotLight.distance ) ) ) ) {
float spotEffect = dot( spotLight.direction, directLight.direction ); float spotEffect = smoothstep( spotLight.coneCos, spotLight.penumbraCos, angleCos );
spotEffect *= clamp( ( spotEffect - spotLight.angleCos ) / spotLight.penumbra, 0.0, 1.0 );
directLight.color = spotLight.color; directLight.color = spotLight.color;
directLight.color *= ( spotEffect * calcLightAttenuation( lightDistance, spotLight.distance, spotLight.decay ) ); directLight.color *= ( spotEffect * calcLightAttenuation( lightDistance, spotLight.distance, spotLight.decay ) );
......
...@@ -111,8 +111,8 @@ THREE.UniformsLib = { ...@@ -111,8 +111,8 @@ THREE.UniformsLib = {
"position": { type: "v3" }, "position": { type: "v3" },
"direction": { type: "v3" }, "direction": { type: "v3" },
"distance": { type: "f" }, "distance": { type: "f" },
"angleCos": { type: "f" }, "coneCos": { type: "f" },
"penumbra": { type: "f" }, "penumbraCos": { type: "f" },
"decay": { type: "f" }, "decay": { type: "f" },
"shadow": { type: "i" }, "shadow": { type: "i" },
......
...@@ -36,8 +36,8 @@ THREE.WebGLLights = function () { ...@@ -36,8 +36,8 @@ THREE.WebGLLights = function () {
direction: new THREE.Vector3(), direction: new THREE.Vector3(),
color: new THREE.Color(), color: new THREE.Color(),
distance: 0, distance: 0,
angleCos: 0, coneCos: 0,
penumbra: 0, penumbraCos: 0,
decay: 0, decay: 0,
shadow: false, shadow: false,
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册