1
0
mirror of https://github.com/luanti-org/luanti.git synced 2025-10-17 10:25:21 +02:00

Port shadow shaders to work with OpenGL3

Co-authored-by: sfan5 <sfan5@live.de>
This commit is contained in:
PtiLuky
2025-10-13 11:04:07 +02:00
committed by sfan5
parent 5e23e478b1
commit d834c45d1c
13 changed files with 128 additions and 264 deletions

View File

@@ -1,13 +0,0 @@
uniform sampler2D ColorMapSampler;
varying vec4 tPos;
void main()
{
vec4 col = texture2D(ColorMapSampler, gl_TexCoord[0].st);
if (col.a < 0.70)
discard;
float depth = 0.5 + tPos.z * 0.5;
gl_FragColor = vec4(depth, 0.0, 0.0, 1.0);
}

View File

@@ -1,42 +0,0 @@
uniform sampler2D ColorMapSampler;
varying vec4 tPos;
#ifdef COLORED_SHADOWS
varying vec3 varColor;
// c_precision of 128 fits within 7 base-10 digits
const float c_precision = 128.0;
const float c_precisionp1 = c_precision + 1.0;
float packColor(vec3 color)
{
return floor(color.b * c_precision + 0.5)
+ floor(color.g * c_precision + 0.5) * c_precisionp1
+ floor(color.r * c_precision + 0.5) * c_precisionp1 * c_precisionp1;
}
const vec3 black = vec3(0.0);
#endif
void main()
{
vec4 col = texture2D(ColorMapSampler, gl_TexCoord[0].st);
#ifndef COLORED_SHADOWS
if (col.a < 0.5)
discard;
#endif
float depth = 0.5 + tPos.z * 0.5;
// ToDo: Liso: Apply movement on waving plants
// depth in [0, 1] for texture
//col.rgb = col.a == 1.0 ? vec3(1.0) : col.rgb;
#ifdef COLORED_SHADOWS
col.rgb *= varColor.rgb;
// premultiply color alpha (see-through side)
float packedColor = packColor(col.rgb * (1.0 - col.a));
gl_FragColor = vec4(depth, packedColor, 0.0,1.0);
#else
gl_FragColor = vec4(depth, 0.0, 0.0, 1.0);
#endif
}

View File

@@ -1,50 +0,0 @@
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
}

View File

@@ -1,43 +0,0 @@
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;
}

View File

@@ -1,23 +0,0 @@
uniform sampler2D ShadowMapClientMap;
#ifdef COLORED_SHADOWS
uniform sampler2D ShadowMapClientMapTraslucent;
#endif
uniform sampler2D ShadowMapSamplerdynamic;
void main() {
#ifdef COLORED_SHADOWS
vec2 first_depth = texture2D(ShadowMapClientMap, gl_TexCoord[0].st).rg;
vec2 depth_splitdynamics = vec2(texture2D(ShadowMapSamplerdynamic, gl_TexCoord[2].st).r, 0.0);
if (first_depth.r > depth_splitdynamics.r)
first_depth = depth_splitdynamics;
vec2 depth_color = texture2D(ShadowMapClientMapTraslucent, gl_TexCoord[1].st).rg;
gl_FragColor = vec4(first_depth.r, first_depth.g, depth_color.r, depth_color.g);
#else
float first_depth = texture2D(ShadowMapClientMap, gl_TexCoord[0].st).r;
float depth_splitdynamics = texture2D(ShadowMapSamplerdynamic, gl_TexCoord[2].st).r;
first_depth = min(first_depth, depth_splitdynamics);
gl_FragColor = vec4(first_depth, 0.0, 0.0, 1.0);
#endif
}

View File

@@ -1,9 +0,0 @@
void main()
{
vec4 uv = vec4(gl_Vertex.xyz, 1.0) * 0.5 + 0.5;
gl_TexCoord[0] = uv;
gl_TexCoord[1] = uv;
gl_TexCoord[2] = uv;
gl_Position = vec4(gl_Vertex.xyz, 1.0);
}