2021-06-06 18:51:21 +02:00
|
|
|
uniform mat4 LightMVP; // world matrix
|
2022-04-07 22:13:50 +02:00
|
|
|
uniform vec4 CameraPos; // camera position
|
2021-06-06 18:51:21 +02:00
|
|
|
varying vec4 tPos;
|
|
|
|
|
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
|
|
|
|
|
|
|
vec4 getPerspectiveFactor(in vec4 shadowPosition)
|
|
|
|
{
|
2022-04-07 22:13:50 +02:00
|
|
|
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);
|
2022-03-31 22:40:06 +02:00
|
|
|
float pFactor = pDistance * xyPerspectiveBias0 + xyPerspectiveBias1;
|
2022-04-07 22:13:50 +02:00
|
|
|
l /= pFactor;
|
|
|
|
shadowPosition.xy = CameraPos.xy * (1.0 - l) + s * l;
|
|
|
|
shadowPosition.z *= zPerspectiveBias;
|
2021-06-06 18:51:21 +02:00
|
|
|
return shadowPosition;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void main()
|
|
|
|
{
|
|
|
|
vec4 pos = LightMVP * gl_Vertex;
|
|
|
|
|
|
|
|
tPos = getPerspectiveFactor(pos);
|
|
|
|
|
|
|
|
gl_Position = vec4(tPos.xyz, 1.0);
|
2022-02-11 23:00:41 +01:00
|
|
|
gl_TexCoord[0] = gl_TextureMatrix[0] * gl_MultiTexCoord0;
|
2021-06-06 18:51:21 +02:00
|
|
|
}
|