commit b6d1be46e550755a732610e9ec0c500f4818baf4
Author: myconid <christofi.cos@gmail.com>
Date:   Thu Nov 15 21:21:46 2012 +0200

    shadowbias

diff --git a/binaries/data/mods/public/shaders/glsl/model_common.fs b/binaries/data/mods/public/shaders/glsl/model_common.fs
index 5ffe2a2..2d374f8 100644
--- a/binaries/data/mods/public/shaders/glsl/model_common.fs
+++ b/binaries/data/mods/public/shaders/glsl/model_common.fs
@@ -66,26 +66,28 @@ varying vec2 v_los;
 #endif
 
 
+float shadowBias = 0.004;
 float get_shadow()
 {
   #if USE_SHADOW && !DISABLE_RECEIVE_SHADOWS
+    float biasedShdwZ = v_shadow.z - shadowBias;
     #if USE_SHADOW_SAMPLER
       #if USE_SHADOW_PCF
         vec2 offset = fract(v_shadow.xy - 0.5);
         vec4 size = vec4(offset + 1.0, 2.0 - offset);
         vec4 weight = (vec4(2.0 - 1.0 / size.xy, 1.0 / size.zw - 1.0) + (v_shadow.xy - offset).xyxy) * shadowScale.zwzw;
         return (1.0/9.0)*dot(size.zxzx*size.wwyy,
-          vec4(shadow2D(shadowTex, vec3(weight.zw, v_shadow.z)).r,
-               shadow2D(shadowTex, vec3(weight.xw, v_shadow.z)).r,
-               shadow2D(shadowTex, vec3(weight.zy, v_shadow.z)).r,
-               shadow2D(shadowTex, vec3(weight.xy, v_shadow.z)).r));
+          vec4(shadow2D(shadowTex, vec3(weight.zw, biasedShdwZ)).r,
+               shadow2D(shadowTex, vec3(weight.xw, biasedShdwZ)).r,
+               shadow2D(shadowTex, vec3(weight.zy, biasedShdwZ)).r,
+               shadow2D(shadowTex, vec3(weight.xy, biasedShdwZ)).r));
       #else
-        return shadow2D(shadowTex, v_shadow.xyz).r;
+        return shadow2D(shadowTex, vec3(v_shadow.xy, biasedShdwZ)).r;
       #endif
     #else
-      if (v_shadow.z >= 1.0)
+      if (biasedShdwZ >= 1.0)
         return 1.0;
-      return (v_shadow.z <= texture2D(shadowTex, v_shadow.xy).x ? 1.0 : 0.0);
+      return (biasedShdwZ < texture2D(shadowTex, v_shadow.xy).x ? 1.0 : 0.0);
     #endif
   #else
     return 1.0;
diff --git a/binaries/data/mods/public/shaders/glsl/terrain_common.fs b/binaries/data/mods/public/shaders/glsl/terrain_common.fs
index f54880d..a169b35 100644
--- a/binaries/data/mods/public/shaders/glsl/terrain_common.fs
+++ b/binaries/data/mods/public/shaders/glsl/terrain_common.fs
@@ -66,26 +66,28 @@ varying vec3 v_normal;
   #endif
 #endif
 
+float shadowBias = 0.004;
 float get_shadow()
 {
   #if USE_SHADOW
+    float biasedShdwZ = v_shadow.z - shadowBias;
     #if USE_SHADOW_SAMPLER
       #if USE_SHADOW_PCF
         vec2 offset = fract(v_shadow.xy - 0.5);
         vec4 size = vec4(offset + 1.0, 2.0 - offset);
         vec4 weight = (vec4(2.0 - 1.0 / size.xy, 1.0 / size.zw - 1.0) + (v_shadow.xy - offset).xyxy) * shadowScale.zwzw;
         return (1.0/9.0)*dot(size.zxzx*size.wwyy,
-          vec4(shadow2D(shadowTex, vec3(weight.zw, v_shadow.z)).r,
-               shadow2D(shadowTex, vec3(weight.xw, v_shadow.z)).r,
-               shadow2D(shadowTex, vec3(weight.zy, v_shadow.z)).r,
-               shadow2D(shadowTex, vec3(weight.xy, v_shadow.z)).r));
+          vec4(shadow2D(shadowTex, vec3(weight.zw, biasedShdwZ)).r,
+               shadow2D(shadowTex, vec3(weight.xw, biasedShdwZ)).r,
+               shadow2D(shadowTex, vec3(weight.zy, biasedShdwZ)).r,
+               shadow2D(shadowTex, vec3(weight.xy, biasedShdwZ)).r));
       #else
-        return shadow2D(shadowTex, v_shadow.xyz).r;
+        return shadow2D(shadowTex, vec3(v_shadow.xy, biasedShdwZ)).r;
       #endif
     #else
-      if (v_shadow.z >= 1.0)
+      if (biasedShdwZ >= 1.0)
         return 1.0;
-      return (v_shadow.z <= texture2D(shadowTex, v_shadow.xy).x ? 1.0 : 0.0);
+      return (biasedShdwZ < texture2D(shadowTex, v_shadow.xy).x ? 1.0 : 0.0);
     #endif
   #else
     return 1.0;
diff --git a/source/renderer/ShadowMap.cpp b/source/renderer/ShadowMap.cpp
index 6c39851..3d361ae 100644
--- a/source/renderer/ShadowMap.cpp
+++ b/source/renderer/ShadowMap.cpp
@@ -276,7 +276,7 @@ void ShadowMapInternals::CalcShadowMatrices()
 	LightProjection._22 = scale.Y;
 	LightProjection._24 = (shift.Y + offsetY) * scale.Y;
 	LightProjection._33 = scale.Z;
-	LightProjection._34 = shift.Z * scale.Z + renderer.m_ShadowZBias;
+	LightProjection._34 = shift.Z * scale.Z;
 	LightProjection._44 = 1.0;
 
 	// Calculate texture matrix by creating the clip space to texture coordinate matrix
