aboutsummaryrefslogtreecommitdiff
path: root/client/shaders/shadow_shaders/pass1_trans_vertex.glsl
diff options
context:
space:
mode:
authorx2048 <codeforsmile@gmail.com>2022-04-07 22:13:50 +0200
committerGitHub <noreply@github.com>2022-04-07 22:13:50 +0200
commit48f7c5603e5b2dfca941d228e76e452bc269a1fa (patch)
tree7983bb05e762792e38ba22a59e8718cac5381747 /client/shaders/shadow_shaders/pass1_trans_vertex.glsl
parent0b5b2b2633609f646a534d353a2c587af4be46fa (diff)
downloadminetest-48f7c5603e5b2dfca941d228e76e452bc269a1fa.tar.gz
minetest-48f7c5603e5b2dfca941d228e76e452bc269a1fa.tar.bz2
minetest-48f7c5603e5b2dfca941d228e76e452bc269a1fa.zip
Adjust shadowmap distortion to use entire SM texture (#12166)
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;
}