瀏覽代碼

Merge pull request #2364 from jMonkeyEngine/yaRnMcDonuts-patch-6

Fix Fog in Lighting.frag
Ryan McDonough 6 月之前
父節點
當前提交
becdf50528

+ 4 - 30
jme3-core/src/main/resources/Common/MatDefs/Light/Lighting.frag

@@ -6,25 +6,9 @@
     #import "Common/ShaderLib/Lighting.glsllib"
 #endif
 
-// fog - jayfella
 #ifdef USE_FOG
-#import "Common/ShaderLib/MaterialFog.glsllib"
-varying float fog_distance;
-uniform vec4 m_FogColor;
-
-#ifdef FOG_LINEAR
-uniform vec2 m_LinearFog;
-#endif
-
-#ifdef FOG_EXP
-uniform float m_ExpFog;
-#endif
-
-#ifdef FOG_EXPSQ
-uniform float m_ExpSqFog;
-#endif
-
-#endif // end fog
+    #import "Common/ShaderLib/MaterialFog.glsllib"
+#endif 
 
 varying vec2 texCoord;
 #ifdef SEPARATE_TEXCOORD
@@ -231,21 +215,11 @@ void main(){
                            SpecularSum2.rgb * specularColor.rgb * vec3(light.y);
     #endif
 
-
     // add fog after the lighting because shadows will cause the fog to darken
     // which just results in the geometry looking like it's changed color
     #ifdef USE_FOG
-        #ifdef FOG_LINEAR
-            gl_FragColor = getFogLinear(gl_FragColor, m_FogColor, m_LinearFog.x, m_LinearFog.y, fog_distance);
-        #endif
-        #ifdef FOG_EXP
-            gl_FragColor = getFogExp(gl_FragColor, m_FogColor, m_ExpFog, fog_distance);
-        #endif
-        #ifdef FOG_EXPSQ
-            gl_FragColor = getFogExpSquare(gl_FragColor, m_FogColor, m_ExpSqFog, fog_distance);
-        #endif
-    #endif // end fog
-
+        gl_FragColor = MaterialFog_calculateFogColor(vec4(gl_FragColor));
+    #endif
 
     gl_FragColor.a = alpha;
 }

+ 3 - 4
jme3-core/src/main/resources/Common/ShaderLib/MaterialFog.glsllib

@@ -1,7 +1,7 @@
+//author @jayfella
 #ifndef __MATERIAL_FOG_UTIL__
     #define __MATERIAL_FOG_UTIL__
 
-
     vec4 getFogLinear(in vec4 diffuseColor, in vec4 fogColor, in float start, in float end, in float distance) {
 
         float fogFactor = (end - distance) / (end - start);
@@ -39,8 +39,7 @@
 
         #ifdef FOG_EXPSQ
             uniform float m_ExpSqFog;        
-        #endif
-        
+        #endif        
 
         vec4 MaterialFog_calculateFogColor(in vec4 fragColor){
             #ifdef FOG_LINEAR
@@ -54,7 +53,7 @@
             #endif
 
             return fragColor;
-        }           
+        }          
 
     #endif   
 #endif