From 628fa23059e45f3ea2b45b314476304a120ed271 Mon Sep 17 00:00:00 2001 From: Kirill Vainer Date: Sat, 30 Sep 2017 17:53:45 -0400 Subject: [PATCH] remove useless normalization in lighting shaders --- .../src/main/resources/Common/MatDefs/Light/Lighting.frag | 2 +- .../src/main/resources/Common/MatDefs/Light/Lighting.vert | 2 +- .../main/resources/Common/MatDefs/Light/PBRLighting.frag | 3 +-- .../src/main/resources/Common/MatDefs/Light/SPLighting.frag | 2 +- .../src/main/resources/Common/MatDefs/Light/SPLighting.vert | 2 +- .../src/main/resources/Common/ShaderLib/Lighting.glsllib | 6 +++--- 6 files changed, 8 insertions(+), 9 deletions(-) diff --git a/jme3-core/src/main/resources/Common/MatDefs/Light/Lighting.frag b/jme3-core/src/main/resources/Common/MatDefs/Light/Lighting.frag index 9b8aa2709..17db8f7b1 100644 --- a/jme3-core/src/main/resources/Common/MatDefs/Light/Lighting.frag +++ b/jme3-core/src/main/resources/Common/MatDefs/Light/Lighting.frag @@ -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; diff --git a/jme3-core/src/main/resources/Common/MatDefs/Light/Lighting.vert b/jme3-core/src/main/resources/Common/MatDefs/Light/Lighting.vert index 395bc1bca..f2d4a3a89 100644 --- a/jme3-core/src/main/resources/Common/MatDefs/Light/Lighting.vert +++ b/jme3-core/src/main/resources/Common/MatDefs/Light/Lighting.vert @@ -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 diff --git a/jme3-core/src/main/resources/Common/MatDefs/Light/PBRLighting.frag b/jme3-core/src/main/resources/Common/MatDefs/Light/PBRLighting.frag index 118ebbe19..3e130d415 100644 --- a/jme3-core/src/main/resources/Common/MatDefs/Light/PBRLighting.frag +++ b/jme3-core/src/main/resources/Common/MatDefs/Light/PBRLighting.frag @@ -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; diff --git a/jme3-core/src/main/resources/Common/MatDefs/Light/SPLighting.frag b/jme3-core/src/main/resources/Common/MatDefs/Light/SPLighting.frag index a510fc1db..472b7c128 100644 --- a/jme3-core/src/main/resources/Common/MatDefs/Light/SPLighting.frag +++ b/jme3-core/src/main/resources/Common/MatDefs/Light/SPLighting.frag @@ -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 diff --git a/jme3-core/src/main/resources/Common/MatDefs/Light/SPLighting.vert b/jme3-core/src/main/resources/Common/MatDefs/Light/SPLighting.vert index 49cc5b96e..c24ee7f19 100644 --- a/jme3-core/src/main/resources/Common/MatDefs/Light/SPLighting.vert +++ b/jme3-core/src/main/resources/Common/MatDefs/Light/SPLighting.vert @@ -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 diff --git a/jme3-core/src/main/resources/Common/ShaderLib/Lighting.glsllib b/jme3-core/src/main/resources/Common/ShaderLib/Lighting.glsllib index fb8f40524..d75f4eb9c 100644 --- a/jme3-core/src/main/resources/Common/ShaderLib/Lighting.glsllib +++ b/jme3-core/src/main/resources/Common/ShaderLib/Lighting.glsllib @@ -23,9 +23,9 @@ 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); +float computeSpotFalloff(in vec4 lightDirection, in vec3 lightVector) { + vec3 L = lightVector; + vec3 spotdir = lightDirection.xyz; float curAngleCos = dot(-L, spotdir); float innerAngleCos = floor(lightDirection.w) * 0.001; float outerAngleCos = fract(lightDirection.w);