1
0
Fork 0
mirror of https://github.com/luanti-org/luanti.git synced 2025-08-01 17:38:41 +00:00

Adjust shadowmap distortion to use entire SM texture (#12166)

This commit is contained in:
x2048 2022-04-07 22:13:50 +02:00 committed by GitHub
parent 0b5b2b2633
commit 48f7c5603e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
12 changed files with 159 additions and 115 deletions

View file

@ -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;
}

View file

@ -1,4 +1,5 @@
uniform mat4 LightMVP; // world matrix
uniform vec4 CameraPos; // camera position
varying vec4 tPos;
uniform float xyPerspectiveBias0;
@ -7,10 +8,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;
}