浏览代码

Merge pull request #7518 from bhouston/spotLightAngleFix

Fix spot light cutoff.
Mr.doob 9 年之前
父节点
当前提交
08be8ecfae
共有 1 个文件被更改,包括 16 次插入5 次删除
  1. 16 5
      src/renderers/shaders/ShaderChunk/lights_pars.glsl

+ 16 - 5
src/renderers/shaders/ShaderChunk/lights_pars.glsl

@@ -71,13 +71,24 @@ uniform vec3 ambientLightColor;
 		vec3 lVector = spotLight.position - geometry.position;
 		directLight.direction = normalize( lVector );
 	
-		float spotEffect = dot( spotLight.direction, directLight.direction );
-		spotEffect = saturate( pow( saturate( spotEffect ), spotLight.exponent ) );
-	
-		directLight.color = spotLight.color;
-		directLight.color *= ( spotEffect * calcLightAttenuation( length( lVector ), spotLight.distance, spotLight.decay ) );
+		float spotEffect = dot( directLight.direction, spotLight.direction );
+
+		if ( spotEffect > spotLight.angleCos ) {
+
+			float spotEffect = dot( spotLight.direction, directLight.direction );
+			spotEffect = saturate( pow( saturate( spotEffect ), spotLight.exponent ) );
+		
+			directLight.color = spotLight.color;
+			directLight.color *= ( spotEffect * calcLightAttenuation( length( lVector ), spotLight.distance, spotLight.decay ) );
+
+		}
+		else {
+
+			directLight.color = vec3( 0.0 );
+		}
 
 		return directLight;
+
 	}
 
 #endif