1
0
mirror of https://github.com/luanti-org/luanti.git synced 2025-11-20 08:25:23 +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)