mirror of
https://github.com/luanti-org/luanti.git
synced 2025-11-21 00:45:23 +01:00
Dynamic shadows with the ogles2 driver on OpenGL ES 3.0+ (#16661)
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user