Bläddra i källkod

SinglePass Lighting: fix GLSL syntax error when parallax mapping is used

shadowislord 10 år sedan
förälder
incheckning
270f4957ef
1 ändrade filer med 11 tillägg och 11 borttagningar
  1. 11 11
      jme3-core/src/main/resources/Common/MatDefs/Light/SPLighting.frag

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

@@ -72,6 +72,13 @@ uniform float m_Shininess;
 #endif
 
 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
+
     vec2 newTexCoord;
      
     #if (defined(PARALLAXMAP) || (defined(NORMALMAP_PARALLAX) && defined(NORMALMAP))) && !defined(VERTEX_LIGHTING) 
@@ -79,18 +86,18 @@ void main(){
        #ifdef STEEP_PARALLAX
            #ifdef NORMALMAP_PARALLAX
                //parallax map is stored in the alpha channel of the normal map         
-               newTexCoord = steepParallaxOffset(m_NormalMap, vViewDir, texCoord, m_ParallaxHeight);
+               newTexCoord = steepParallaxOffset(m_NormalMap, viewDir, texCoord, m_ParallaxHeight);
            #else
                //parallax map is a texture
-               newTexCoord = steepParallaxOffset(m_ParallaxMap, vViewDir, texCoord, m_ParallaxHeight);         
+               newTexCoord = steepParallaxOffset(m_ParallaxMap, viewDir, texCoord, m_ParallaxHeight);         
            #endif
        #else
            #ifdef NORMALMAP_PARALLAX
                //parallax map is stored in the alpha channel of the normal map         
-               newTexCoord = classicParallaxOffset(m_NormalMap, vViewDir, texCoord, m_ParallaxHeight);
+               newTexCoord = classicParallaxOffset(m_NormalMap, viewDir, texCoord, m_ParallaxHeight);
            #else
                //parallax map is a texture
-               newTexCoord = classicParallaxOffset(m_ParallaxMap, vViewDir, texCoord, m_ParallaxHeight);
+               newTexCoord = classicParallaxOffset(m_ParallaxMap, viewDir, texCoord, m_ParallaxHeight);
            #endif
        #endif
     #else
@@ -160,13 +167,6 @@ void main(){
              vec4 refColor = Optics_GetEnvColor(m_EnvMap, refVec.xyz);
         #endif
 
-        #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){
             vec4 lightColor = g_LightData[i];
             vec4 lightData1 = g_LightData[i+1];