diff --git a/indra/newview/app_settings/shaders/class1/deferred/avatarShadowF.glsl b/indra/newview/app_settings/shaders/class1/deferred/avatarShadowF.glsl
index 1b7ae0688841b60691e279a18efd5f6d3baa9ec8..3d0884bbe8906ddee9ad267c3e8666cb118040e4 100644
--- a/indra/newview/app_settings/shaders/class1/deferred/avatarShadowF.glsl
+++ b/indra/newview/app_settings/shaders/class1/deferred/avatarShadowF.glsl
@@ -9,10 +9,13 @@
 
 uniform sampler2D diffuseMap;
 
+varying vec4 post_pos;
 
 void main() 
 {
 	//gl_FragColor = vec4(1,1,1,gl_Color.a * texture2D(diffuseMap, gl_TexCoord[0].xy).a);
 	gl_FragColor = vec4(1,1,1,1);
+
+	gl_FragDepth = max(post_pos.z/post_pos.w*0.5+0.5, 0.0);
 }
 
diff --git a/indra/newview/app_settings/shaders/class1/deferred/avatarShadowV.glsl b/indra/newview/app_settings/shaders/class1/deferred/avatarShadowV.glsl
index cf6579a40d4c608193da404644ad33ba1594fa9c..3460f40657921529237c9ade142fa98b8dfc0621 100644
--- a/indra/newview/app_settings/shaders/class1/deferred/avatarShadowV.glsl
+++ b/indra/newview/app_settings/shaders/class1/deferred/avatarShadowV.glsl
@@ -11,6 +11,8 @@ mat4 getSkinnedTransform();
 
 attribute vec4 weight;
 
+varying vec4 post_pos;
+
 void main()
 {
 	gl_TexCoord[0] = gl_MultiTexCoord0;
@@ -30,8 +32,9 @@ void main()
 	norm = normalize(norm);
 	
 	pos = gl_ProjectionMatrix * pos;
-	pos.z = max(pos.z, -pos.w+0.01);
-	gl_Position = pos;
+	post_pos = pos;
+
+	gl_Position = vec4(pos.x, pos.y, pos.w*0.5, pos.w);
 	
 	gl_FrontColor = gl_Color;
 }