1
0
mirror of https://github.com/luanti-org/luanti.git synced 2025-11-19 16:15:19 +01:00

Dynamic shadows with the ogles2 driver on OpenGL ES 3.0+ (#16661)

This commit is contained in:
grorp
2025-11-17 17:55:13 +01:00
committed by GitHub
parent ac0ebf39ad
commit fcd96e9244
22 changed files with 97 additions and 70 deletions

View File

@@ -317,7 +317,7 @@ vec4 getShadowColor(sampler2D shadowsampler, vec2 smTexCoord, float realDistance
int samples = (1 + 1 * int(SOFTSHADOWRADIUS > 1.0)) * PCFSAMPLES; // scale max samples for the soft shadows
samples = int(clamp(pow(4.0 * radius + 1.0, 2.0), 1.0, float(samples)));
int init_offset = int(floor(mod(((smTexCoord.x * 34.0) + 1.0) * smTexCoord.y, 64.0-samples)));
int init_offset = int(floor(mod(((smTexCoord.x * 34.0) + 1.0) * smTexCoord.y, 64.0-float(samples))));
int end_offset = int(samples) + init_offset;
for (int x = init_offset; x < end_offset; x++) {
@@ -325,7 +325,7 @@ vec4 getShadowColor(sampler2D shadowsampler, vec2 smTexCoord, float realDistance
visibility += getHardShadowColor(shadowsampler, clampedpos.xy, realDistance);
}
return visibility / samples;
return visibility / float(samples);
}
#else
@@ -344,7 +344,7 @@ float getShadow(sampler2D shadowsampler, vec2 smTexCoord, float realDistance)
int samples = (1 + 1 * int(SOFTSHADOWRADIUS > 1.0)) * PCFSAMPLES; // scale max samples for the soft shadows
samples = int(clamp(pow(4.0 * radius + 1.0, 2.0), 1.0, float(samples)));
int init_offset = int(floor(mod(((smTexCoord.x * 34.0) + 1.0) * smTexCoord.y, 64.0-samples)));
int init_offset = int(floor(mod(((smTexCoord.x * 34.0) + 1.0) * smTexCoord.y, 64.0-float(samples))));
int end_offset = int(samples) + init_offset;
for (int x = init_offset; x < end_offset; x++) {
@@ -352,7 +352,7 @@ float getShadow(sampler2D shadowsampler, vec2 smTexCoord, float realDistance)
visibility += getHardShadow(shadowsampler, clampedpos.xy, realDistance);
}
return visibility / samples;
return visibility / float(samples);
}
#endif
@@ -511,8 +511,8 @@ void main(void)
// Apply self-shadowing when light falls at a narrow angle to the surface
// Cosine of the cut-off angle.
const float self_shadow_cutoff_cosine = 0.035;
if (f_normal_length != 0 && cosLight < self_shadow_cutoff_cosine) {
shadow_int = max(shadow_int, 1 - clamp(cosLight, 0.0, self_shadow_cutoff_cosine)/self_shadow_cutoff_cosine);
if (f_normal_length != 0.0 && cosLight < self_shadow_cutoff_cosine) {
shadow_int = max(shadow_int, 1.0 - clamp(cosLight, 0.0, self_shadow_cutoff_cosine)/self_shadow_cutoff_cosine);
shadow_color = mix(vec3(0.0), shadow_color, min(cosLight, self_shadow_cutoff_cosine)/self_shadow_cutoff_cosine);
#if (MATERIAL_TYPE == TILE_MATERIAL_WAVING_LEAVES || MATERIAL_TYPE == TILE_MATERIAL_WAVING_PLANTS)

View File

@@ -162,8 +162,8 @@ float getPenumbraRadius(sampler2D shadowsampler, vec2 smTexCoord, float realDist
// conversion factor from shadow depth to blur radius
float depth_to_blur = f_shadowfar / SOFTSHADOWRADIUS / xyPerspectiveBias0;
if (depth > 0.0 && f_normal_length > 0.0)
// 5 is empirical factor that controls how fast shadow loses sharpness
sharpness_factor = clamp(5 * depth * depth_to_blur, 0.0, 1.0);
// 5.0 is empirical factor that controls how fast shadow loses sharpness
sharpness_factor = clamp(5.0 * depth * depth_to_blur, 0.0, 1.0);
depth = 0.0;
float world_to_texture = xyPerspectiveBias1 / perspective_factor / perspective_factor
@@ -257,7 +257,7 @@ vec4 getShadowColor(sampler2D shadowsampler, vec2 smTexCoord, float realDistance
int samples = (1 + 1 * int(SOFTSHADOWRADIUS > 1.0)) * PCFSAMPLES; // scale max samples for the soft shadows
samples = int(clamp(pow(4.0 * radius + 1.0, 2.0), 1.0, float(samples)));
int init_offset = int(floor(mod(((smTexCoord.x * 34.0) + 1.0) * smTexCoord.y, 64.0-samples)));
int init_offset = int(floor(mod(((smTexCoord.x * 34.0) + 1.0) * smTexCoord.y, 64.0-float(samples))));
int end_offset = int(samples) + init_offset;
for (int x = init_offset; x < end_offset; x++) {
@@ -265,7 +265,7 @@ vec4 getShadowColor(sampler2D shadowsampler, vec2 smTexCoord, float realDistance
visibility += getHardShadowColor(shadowsampler, clampedpos.xy, realDistance);
}
return visibility / samples;
return visibility / float(samples);
}
#else
@@ -284,7 +284,7 @@ float getShadow(sampler2D shadowsampler, vec2 smTexCoord, float realDistance)
int samples = (1 + 1 * int(SOFTSHADOWRADIUS > 1.0)) * PCFSAMPLES; // scale max samples for the soft shadows
samples = int(clamp(pow(4.0 * radius + 1.0, 2.0), 1.0, float(samples)));
int init_offset = int(floor(mod(((smTexCoord.x * 34.0) + 1.0) * smTexCoord.y, 64.0-samples)));
int init_offset = int(floor(mod(((smTexCoord.x * 34.0) + 1.0) * smTexCoord.y, 64.0-float(samples))));
int end_offset = int(samples) + init_offset;
for (int x = init_offset; x < end_offset; x++) {
@@ -292,7 +292,7 @@ float getShadow(sampler2D shadowsampler, vec2 smTexCoord, float realDistance)
visibility += getHardShadow(shadowsampler, clampedpos.xy, realDistance);
}
return visibility / samples;
return visibility / float(samples);
}
#endif
@@ -426,8 +426,8 @@ void main(void)
// Apply self-shadowing when light falls at a narrow angle to the surface
// Cosine of the cut-off angle.
const float self_shadow_cutoff_cosine = 0.14;
if (f_normal_length != 0 && cosLight < self_shadow_cutoff_cosine) {
shadow_int = max(shadow_int, 1 - clamp(cosLight, 0.0, self_shadow_cutoff_cosine)/self_shadow_cutoff_cosine);
if (f_normal_length != 0.0 && cosLight < self_shadow_cutoff_cosine) {
shadow_int = max(shadow_int, 1.0 - clamp(cosLight, 0.0, self_shadow_cutoff_cosine)/self_shadow_cutoff_cosine);
shadow_color = mix(vec3(0.0), shadow_color, min(cosLight, self_shadow_cutoff_cosine)/self_shadow_cutoff_cosine);
}

View File

@@ -3,7 +3,7 @@
#else
uniform sampler2D baseTexture;
#endif
varying vec4 tPos;
VARYING_ vec4 tPos;
CENTROID_ VARYING_ mediump vec2 varTexCoord;
CENTROID_ VARYING_ float varTexLayer; // actually int

View File

@@ -1,6 +1,6 @@
uniform mat4 LightMVP; // world matrix
uniform vec4 CameraPos; // camera position
varying vec4 tPos;
VARYING_ vec4 tPos;
uniform float xyPerspectiveBias0;
uniform float xyPerspectiveBias1;

View File

@@ -3,13 +3,13 @@
#else
uniform sampler2D baseTexture;
#endif
varying vec4 tPos;
VARYING_ vec4 tPos;
CENTROID_ VARYING_ mediump vec2 varTexCoord;
CENTROID_ VARYING_ float varTexLayer; // actually int
#ifdef COLORED_SHADOWS
varying vec3 varColor;
VARYING_ vec3 varColor;
// c_precision of 128 fits within 7 base-10 digits
const float c_precision = 128.0;

View File

@@ -1,8 +1,8 @@
uniform mat4 LightMVP; // world matrix
uniform vec4 CameraPos;
varying vec4 tPos;
VARYING_ vec4 tPos;
#ifdef COLORED_SHADOWS
varying vec3 varColor;
VARYING_ vec3 varColor;
#endif
uniform float xyPerspectiveBias0;

View File

@@ -4,11 +4,7 @@ uniform sampler2D ShadowMapClientMapTraslucent;
#endif
uniform sampler2D ShadowMapSamplerdynamic;
#ifdef GL_ES
varying mediump vec2 varTexCoord;
#else
centroid varying vec2 varTexCoord;
#endif
CENTROID_ VARYING_ mediump vec2 varTexCoord;
void main()
{

View File

@@ -1,8 +1,4 @@
#ifdef GL_ES
varying mediump vec2 varTexCoord;
#else
centroid varying vec2 varTexCoord;
#endif
CENTROID_ VARYING_ mediump vec2 varTexCoord;
void main()
{