remove useless normalization in lighting shaders

This commit is contained in:
Kirill Vainer 2017-09-30 17:53:45 -04:00
parent fca6d4a8b2
commit 628fa23059
6 changed files with 8 additions and 9 deletions

View File

@ -173,7 +173,7 @@ void main(){
// allow use of control flow
if(g_LightDirection.w != 0.0){
#endif
spotFallOff = computeSpotFalloff(g_LightDirection, lightVec);
spotFallOff = computeSpotFalloff(g_LightDirection, lightDir.xyz);
#if __VERSION__ >= 110
if(spotFallOff <= 0.0){
gl_FragColor.rgb = AmbientSum * diffuseColor.rgb;

View File

@ -158,7 +158,7 @@ void main(){
// allow use of control flow
if(lightColor.w > 1.0){
#endif
spotFallOff = computeSpotFalloff(g_LightDirection, lightVec);
spotFallOff = computeSpotFalloff(g_LightDirection, vLightDir.xyz);
#if __VERSION__ >= 110
}
#endif

View File

@ -223,14 +223,13 @@ void main(){
// allow use of control flow
if(lightColor.w > 1.0){
#endif
fallOff = computeSpotFalloff(g_LightData[i+2], lightVec);
fallOff = computeSpotFalloff(g_LightData[i+2], lightDir.xyz);
#if __VERSION__ >= 110
}
#endif
//point light attenuation
fallOff *= lightDir.w;
lightDir.xyz = normalize(lightDir.xyz);
vec3 directDiffuse;
vec3 directSpecular;

View File

@ -188,7 +188,7 @@ void main(){
// allow use of control flow
if(lightColor.w > 1.0){
#endif
spotFallOff = computeSpotFalloff(g_LightData[i+2], lightVec);
spotFallOff = computeSpotFalloff(g_LightData[i+2], lightDir.xyz);
#if __VERSION__ >= 110
}
#endif

View File

@ -155,7 +155,7 @@ void main(){
if(lightColor.w > 1.0){
#endif
vec4 lightDirection = g_LightData[i+2];
spotFallOff = computeSpotFalloff(lightDirection, lightVec);
spotFallOff = computeSpotFalloff(lightDirection, lightDir.xyz);
#if __VERSION__ >= 110
}
#endif

View File

@ -24,8 +24,8 @@ void lightComputeDir(in vec3 worldPos, in float lightType, in vec4 position, out
* Computes the spot falloff for a spotlight
*/
float computeSpotFalloff(in vec4 lightDirection, in vec3 lightVector) {
vec3 L=normalize(lightVector);
vec3 spotdir = normalize(lightDirection.xyz);
vec3 L = lightVector;
vec3 spotdir = lightDirection.xyz;
float curAngleCos = dot(-L, spotdir);
float innerAngleCos = floor(lightDirection.w) * 0.001;
float outerAngleCos = fract(lightDirection.w);