Commits

Michael Ludwig committed 907bf94

Fix fog shading bugs.

  • Participants
  • Parent commits 60583c9

Comments (0)

Files changed (2)

File ferox-renderer/src/main/resources/com/ferox/renderer/impl/ffp.frag

 in vec4 vPrimaryColor;
 in vec4 vSecondaryColor;
 in vec4 vTexCoord[4];
+in vec4 vEyePos;
 
 out vec4 fColor;
 
 
     // fog
     if (uEnableFog) {
-    // FIXME I think this part is broken
+        float eyeDepth = abs(vEyePos.z);
+
         float factor = 0.0;
         if (uFogConfig.z > 0) {
             // EXP
-            factor = exp(-uFogConfig.x * gl_FragCoord.z);
+            factor = exp(-uFogConfig.x * eyeDepth);
         } else if (uFogConfig.z < 0) {
             // EXP2
-            factor = exp(-(uFogConfig.x * uFogConfig.x * gl_FragCoord.z * gl_FragCoord.z));
+            factor = exp(-(uFogConfig.x * uFogConfig.x * eyeDepth * eyeDepth));
         } else {
             // LINEAR
-            factor = (uFogConfig.y - gl_FragCoord.z) / (uFogConfig.y - uFogConfig.x);
+            factor = (uFogConfig.y - eyeDepth) / (uFogConfig.y - uFogConfig.x);
         }
 
         // clamp to [0, 1]

File ferox-renderer/src/main/resources/com/ferox/renderer/impl/ffp.vert

 out vec4 vPrimaryColor;
 out vec4 vSecondaryColor;
 out vec4 vTexCoord[4];
+out vec4 vEyePos;
 
 void computeLighting(const int light, const vec4 eyePos, const vec3 eyeNorm,
                      out vec4 primaryColor, out vec4 secondaryColor) {
 
     vPrimaryColor = vec4(primaryColor.xyz, aDiffuse.w);
     vSecondaryColor = vec4(secondaryColor.xyz, 0.0);
+    vEyePos = eyePos;
     gl_Position = uProjection * eyePos;
 }