 
 vec4 applyFog(vec4 color) {
   float fogFactor = (fogEnd - cameraDistance) / (fogEnd - fogStart);
-  fogFactor = fogFactor * fogModifier;
-  fogFactor = clamp(fogFactor, 0.0, 1.0);
-  color.rgb = mix(fogColor.rgb, color.rgb, fogFactor);
-
-  // Ensure alpha channel is gone once a sufficient distance into the fog is reached. Prevents
-  // texture artifacts from overlaying alpha values.
-  if (cameraDistance > fogEnd * 1.5) {
+  fogFactor = 1.0 - clamp(fogFactor, 0.0, 1.0);
+  float fogColorFactor = fogFactor * fogModifier;
+
+  // Only mix fog color for simple blending modes.
+  if (blendingMode <= 2) {
+    color.rgb = mix(color.rgb, fogColor.rgb, fogColorFactor);
+  }
+
+  // Ensure certain blending mode pixels become fully opaque by fog end.
+  if (cameraDistance >= fogEnd) {
+    color.rgb = fogColor.rgb;
     color.a = 1.0;
+  }
+
+  // Ensure certain blending mode pixels fade out as fog increases.
+  if (blendingMode >= 2 && blendingMode < 6) {
+    color.a *= 1.0 - fogFactor;
   }
 
   return color;

uniform float fogEnd;
uniform vec3 fogColor;

vec3 saturate(vec3 value) {
  vec3 result = clamp(value, 0.0, 1.0);
  return result;

    color = applyDiffuseLighting(color);
  }

  color = applyFog(color);

  return color;
}
