diff options
Diffstat (limited to 'client/shaders/shadow_shaders/pass1_vertex.glsl')
-rw-r--r-- | client/shaders/shadow_shaders/pass1_vertex.glsl | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/client/shaders/shadow_shaders/pass1_vertex.glsl b/client/shaders/shadow_shaders/pass1_vertex.glsl new file mode 100644 index 000000000..1dceb93c6 --- /dev/null +++ b/client/shaders/shadow_shaders/pass1_vertex.glsl @@ -0,0 +1,43 @@ +uniform mat4 LightMVP; // world matrix +uniform vec4 CameraPos; // camera position +varying vec4 tPos; + +uniform float xyPerspectiveBias0; +uniform float xyPerspectiveBias1; +uniform float zPerspectiveBias; + +vec4 getRelativePosition(in vec4 position) +{ + 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; + 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 = applyPerspectiveDistortion(pos); + + gl_Position = vec4(tPos.xyz, 1.0); + gl_TexCoord[0] = gl_TextureMatrix[0] * gl_MultiTexCoord0; +} |