aboutsummaryrefslogtreecommitdiff
path: root/client/shaders/shadow_shaders/pass1_trans_vertex.glsl
diff options
context:
space:
mode:
authorx2048 <codeforsmile@gmail.com>2022-04-14 22:49:30 +0200
committerGitHub <noreply@github.com>2022-04-14 22:49:30 +0200
commita5d29fa1d4bc6849d7a6529edc522accac8219d2 (patch)
tree16643a9fcfeef12802fb867803a7de35e93d649f /client/shaders/shadow_shaders/pass1_trans_vertex.glsl
parent9aabd911eb57a5ddef72dd9b7c96f5cca1bd258e (diff)
downloadminetest-a5d29fa1d4bc6849d7a6529edc522accac8219d2.tar.gz
minetest-a5d29fa1d4bc6849d7a6529edc522accac8219d2.tar.bz2
minetest-a5d29fa1d4bc6849d7a6529edc522accac8219d2.zip
Implement shadow offsets for the new SM distortion function (#12191)
* Move shadow position calculation to vertex shaders * Animate entire scene before rendering shadows to prevent lagging of shadows * Remove unnecessary use of PolygonOffsetFactor * Apply normal offset to both nodes and objects * Rename getPerspectiveFactor -> applyPerspectiveDistortion * Remove perspective distortion from fragment shaders
Diffstat (limited to 'client/shaders/shadow_shaders/pass1_trans_vertex.glsl')
-rw-r--r--client/shaders/shadow_shaders/pass1_trans_vertex.glsl31
1 files changed, 22 insertions, 9 deletions
diff --git a/client/shaders/shadow_shaders/pass1_trans_vertex.glsl b/client/shaders/shadow_shaders/pass1_trans_vertex.glsl
index c2f575876..244d2562a 100644
--- a/client/shaders/shadow_shaders/pass1_trans_vertex.glsl
+++ b/client/shaders/shadow_shaders/pass1_trans_vertex.glsl
@@ -9,24 +9,37 @@ uniform float xyPerspectiveBias0;
uniform float xyPerspectiveBias1;
uniform float zPerspectiveBias;
-vec4 getPerspectiveFactor(in vec4 shadowPosition)
+vec4 getRelativePosition(in vec4 position)
{
- 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);
+ vec2 l = position.xy - CameraPos.xy;
+ vec2 s = l / abs(l);
+ s = (1.0 - s * CameraPos.xy);
+ l /= s;
+ return vec4(l, s);
+}
+
+float getPerspectiveFactor(in vec4 relativePosition)
+{
+ float pDistance = length(relativePosition.xy);
float pFactor = pDistance * xyPerspectiveBias0 + xyPerspectiveBias1;
- l /= pFactor;
- shadowPosition.xy = CameraPos.xy * (1.0 - l) + s * l;
- shadowPosition.z *= zPerspectiveBias;
- return shadowPosition;
+ return pFactor;
}
+vec4 applyPerspectiveDistortion(in vec4 position)
+{
+ vec4 l = getRelativePosition(position);
+ float pFactor = getPerspectiveFactor(l);
+ l.xy /= pFactor;
+ position.xy = l.xy * l.zw + CameraPos.xy;
+ position.z *= zPerspectiveBias;
+ return position;
+}
void main()
{
vec4 pos = LightMVP * gl_Vertex;
- tPos = getPerspectiveFactor(LightMVP * gl_Vertex);
+ tPos = applyPerspectiveDistortion(LightMVP * gl_Vertex);
gl_Position = vec4(tPos.xyz, 1.0);
gl_TexCoord[0].st = gl_MultiTexCoord0.st;