aboutsummaryrefslogtreecommitdiff
path: root/client/shaders/shadow_shaders/pass1_trans_vertex.glsl
diff options
context:
space:
mode:
Diffstat (limited to 'client/shaders/shadow_shaders/pass1_trans_vertex.glsl')
-rw-r--r--client/shaders/shadow_shaders/pass1_trans_vertex.glsl10
1 files changed, 7 insertions, 3 deletions
diff --git a/client/shaders/shadow_shaders/pass1_trans_vertex.glsl b/client/shaders/shadow_shaders/pass1_trans_vertex.glsl
index 6d2877d18..c2f575876 100644
--- a/client/shaders/shadow_shaders/pass1_trans_vertex.glsl
+++ b/client/shaders/shadow_shaders/pass1_trans_vertex.glsl
@@ -1,4 +1,5 @@
uniform mat4 LightMVP; // world matrix
+uniform vec4 CameraPos;
varying vec4 tPos;
#ifdef COLORED_SHADOWS
varying vec3 varColor;
@@ -10,10 +11,13 @@ uniform float zPerspectiveBias;
vec4 getPerspectiveFactor(in vec4 shadowPosition)
{
- float pDistance = length(shadowPosition.xy);
+ vec2 s = vec2(shadowPosition.x > CameraPos.x ? 1.0 : -1.0, shadowPosition.y > CameraPos.y ? 1.0 : -1.0);
+ vec2 l = s * (shadowPosition.xy - CameraPos.xy) / (1.0 - s * CameraPos.xy);
+ float pDistance = length(l);
float pFactor = pDistance * xyPerspectiveBias0 + xyPerspectiveBias1;
- shadowPosition.xyz *= vec3(vec2(1.0 / pFactor), zPerspectiveBias);
-
+ l /= pFactor;
+ shadowPosition.xy = CameraPos.xy * (1.0 - l) + s * l;
+ shadowPosition.z *= zPerspectiveBias;
return shadowPosition;
}