1
0
Fork 0
mirror of https://github.com/luanti-org/luanti.git synced 2025-08-01 17:38:41 +00:00

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
This commit is contained in:
x2048 2022-04-14 22:49:30 +02:00 committed by GitHub
parent 9aabd911eb
commit a5d29fa1d4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 184 additions and 122 deletions

View file

@ -6,24 +6,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);
float pFactor = pDistance * xyPerspectiveBias0 + xyPerspectiveBias1;
l /= pFactor;
shadowPosition.xy = CameraPos.xy * (1.0 - l) + s * l;
shadowPosition.z *= zPerspectiveBias;
return shadowPosition;
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 = getPerspectiveFactor(pos);
tPos = applyPerspectiveDistortion(pos);
gl_Position = vec4(tPos.xyz, 1.0);
gl_TexCoord[0] = gl_TextureMatrix[0] * gl_MultiTexCoord0;