瀏覽代碼

Single pass lighting now computes view dir in the appropriate space out of the lights loop as it's the same for all lights.

Nehon 10 年之前
父節點
當前提交
3bad91ef19
共有 1 個文件被更改,包括 5 次插入4 次删除
  1. 5 4
      jme3-core/src/main/resources/Common/MatDefs/Light/SPLighting.frag

+ 5 - 4
jme3-core/src/main/resources/Common/MatDefs/Light/SPLighting.frag

@@ -162,6 +162,9 @@ void main(){
 
         #ifdef NORMALMAP   
             mat3 tbnMat = mat3(normalize(vTangent.xyz) , normalize(vBinormal.xyz) , normalize(vNormal.xyz));
+            vec3 viewDir = normalize(-vPos.xyz * tbnMat);
+        #else
+            vec3 viewDir = normalize(-vPos.xyz);
         #endif
 
         for( int i = 0;i < NB_LIGHTS; i+=3){
@@ -183,12 +186,10 @@ void main(){
          
             #ifdef NORMALMAP         
                 //Normal map -> lighting is computed in tangent space
-                lightDir.xyz = normalize(lightDir.xyz * tbnMat);
-                vec3 viewDir = normalize(-vPos.xyz * tbnMat);
+                lightDir.xyz = normalize(lightDir.xyz * tbnMat);                
             #else
                 //no Normal map -> lighting is computed in view space
-                lightDir.xyz = normalize(lightDir.xyz);
-                vec3 viewDir = normalize(-vPos.xyz);
+                lightDir.xyz = normalize(lightDir.xyz);                
             #endif
 
             vec2 light = computeLighting(normal, viewDir, lightDir.xyz, lightDir.w * spotFallOff , m_Shininess);