aboutsummaryrefslogtreecommitdiff
path: root/client/shaders/shadow_shaders
diff options
context:
space:
mode:
Diffstat (limited to 'client/shaders/shadow_shaders')
-rw-r--r--client/shaders/shadow_shaders/pass1_trans_vertex.glsl35
-rw-r--r--client/shaders/shadow_shaders/pass1_vertex.glsl37
2 files changed, 53 insertions, 19 deletions
diff --git a/client/shaders/shadow_shaders/pass1_trans_vertex.glsl b/client/shaders/shadow_shaders/pass1_trans_vertex.glsl
index 0a9efe450..244d2562a 100644
--- a/client/shaders/shadow_shaders/pass1_trans_vertex.glsl
+++ b/client/shaders/shadow_shaders/pass1_trans_vertex.glsl
@@ -1,28 +1,45 @@
uniform mat4 LightMVP; // world matrix
+uniform vec4 CameraPos;
varying vec4 tPos;
#ifdef COLORED_SHADOWS
varying vec3 varColor;
#endif
-const float bias0 = 0.9;
-const float zPersFactor = 0.5;
-const float bias1 = 1.0 - bias0 + 1e-6;
+uniform float xyPerspectiveBias0;
+uniform float xyPerspectiveBias1;
+uniform float zPerspectiveBias;
-vec4 getPerspectiveFactor(in vec4 shadowPosition)
+vec4 getRelativePosition(in vec4 position)
{
- float pDistance = length(shadowPosition.xy);
- float pFactor = pDistance * bias0 + bias1;
- shadowPosition.xyz *= vec3(vec2(1.0 / pFactor), zPersFactor);
+ vec2 l = position.xy - CameraPos.xy;
+ vec2 s = l / abs(l);
+ s = (1.0 - s * CameraPos.xy);
+ l /= s;
+ return vec4(l, s);
+}
- return shadowPosition;
+float getPerspectiveFactor(in vec4 relativePosition)
+{
+ float pDistance = length(relativePosition.xy);
+ float pFactor = pDistance * xyPerspectiveBias0 + xyPerspectiveBias1;
+ 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;
diff --git a/client/shaders/shadow_shaders/pass1_vertex.glsl b/client/shaders/shadow_shaders/pass1_vertex.glsl
index a6d8b3db8..1dceb93c6 100644
--- a/client/shaders/shadow_shaders/pass1_vertex.glsl
+++ b/client/shaders/shadow_shaders/pass1_vertex.glsl
@@ -1,26 +1,43 @@
uniform mat4 LightMVP; // world matrix
+uniform vec4 CameraPos; // camera position
varying vec4 tPos;
-const float bias0 = 0.9;
-const float zPersFactor = 0.5;
-const float bias1 = 1.0 - bias0 + 1e-6;
+uniform float xyPerspectiveBias0;
+uniform float xyPerspectiveBias1;
+uniform float zPerspectiveBias;
-vec4 getPerspectiveFactor(in vec4 shadowPosition)
+vec4 getRelativePosition(in vec4 position)
{
- float pDistance = length(shadowPosition.xy);
- float pFactor = pDistance * bias0 + bias1;
- shadowPosition.xyz *= vec3(vec2(1.0 / pFactor), zPersFactor);
+ vec2 l = position.xy - CameraPos.xy;
+ vec2 s = l / abs(l);
+ s = (1.0 - s * CameraPos.xy);
+ l /= s;
+ return vec4(l, s);
+}
- return shadowPosition;
+float getPerspectiveFactor(in vec4 relativePosition)
+{
+ float pDistance = length(relativePosition.xy);
+ float pFactor = pDistance * xyPerspectiveBias0 + xyPerspectiveBias1;
+ 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(pos);
+ tPos = applyPerspectiveDistortion(pos);
gl_Position = vec4(tPos.xyz, 1.0);
- gl_TexCoord[0].st = gl_MultiTexCoord0.st;
+ gl_TexCoord[0] = gl_TextureMatrix[0] * gl_MultiTexCoord0;
}