mirror of
https://github.com/minetest/minetest.git
synced 2024-12-17 19:55:41 +01:00
a5d29fa1d4
* 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
51 lines
1.1 KiB
GLSL
51 lines
1.1 KiB
GLSL
uniform mat4 LightMVP; // world matrix
|
|
uniform vec4 CameraPos;
|
|
varying vec4 tPos;
|
|
#ifdef COLORED_SHADOWS
|
|
varying vec3 varColor;
|
|
#endif
|
|
|
|
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(LightMVP * gl_Vertex);
|
|
|
|
gl_Position = vec4(tPos.xyz, 1.0);
|
|
gl_TexCoord[0].st = gl_MultiTexCoord0.st;
|
|
|
|
#ifdef COLORED_SHADOWS
|
|
varColor = gl_Color.rgb;
|
|
#endif
|
|
}
|