2021-06-06 18:51:21 +02:00
|
|
|
uniform mat4 LightMVP; // world matrix
|
2022-04-07 22:13:50 +02:00
|
|
|
uniform vec4 CameraPos;
|
2021-06-06 18:51:21 +02:00
|
|
|
varying vec4 tPos;
|
2021-10-01 16:21:53 +02:00
|
|
|
#ifdef COLORED_SHADOWS
|
|
|
|
varying vec3 varColor;
|
|
|
|
#endif
|
2021-06-06 18:51:21 +02:00
|
|
|
|
2022-03-31 22:40:06 +02:00
|
|
|
uniform float xyPerspectiveBias0;
|
|
|
|
uniform float xyPerspectiveBias1;
|
|
|
|
uniform float zPerspectiveBias;
|
2021-06-06 18:51:21 +02:00
|
|
|
|
2022-04-14 22:49:30 +02:00
|
|
|
vec4 getRelativePosition(in vec4 position)
|
2021-06-06 18:51:21 +02:00
|
|
|
{
|
2022-04-14 22:49:30 +02:00
|
|
|
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);
|
2022-03-31 22:40:06 +02:00
|
|
|
float pFactor = pDistance * xyPerspectiveBias0 + xyPerspectiveBias1;
|
2022-04-14 22:49:30 +02:00
|
|
|
return pFactor;
|
2021-06-06 18:51:21 +02:00
|
|
|
}
|
|
|
|
|
2022-04-14 22:49:30 +02:00
|
|
|
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;
|
|
|
|
}
|
2021-06-06 18:51:21 +02:00
|
|
|
|
|
|
|
void main()
|
|
|
|
{
|
|
|
|
vec4 pos = LightMVP * gl_Vertex;
|
|
|
|
|
2022-04-14 22:49:30 +02:00
|
|
|
tPos = applyPerspectiveDistortion(LightMVP * gl_Vertex);
|
2021-06-06 18:51:21 +02:00
|
|
|
|
|
|
|
gl_Position = vec4(tPos.xyz, 1.0);
|
|
|
|
gl_TexCoord[0].st = gl_MultiTexCoord0.st;
|
2021-10-01 16:21:53 +02:00
|
|
|
|
|
|
|
#ifdef COLORED_SHADOWS
|
|
|
|
varColor = gl_Color.rgb;
|
|
|
|
#endif
|
2021-06-06 18:51:21 +02:00
|
|
|
}
|