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:
parent
0b5b2b2633
commit
48f7c5603e
12 changed files with 159 additions and 115 deletions
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue