Skip to content

Commit

Permalink
Merge pull request #7518 from bhouston/spotLightAngleFix
Browse files Browse the repository at this point in the history
Fix spot light cutoff.
  • Loading branch information
mrdoob committed Nov 2, 2015
2 parents 8f970b4 + bb960c6 commit 08be8ec
Showing 1 changed file with 16 additions and 5 deletions.
21 changes: 16 additions & 5 deletions src/renderers/shaders/ShaderChunk/lights_pars.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 08be8ec

Please sign in to comment.