]> git.lizzy.rs Git - dragonfireclient.git/commitdiff
Improve self-shadowing based on light/normal angle
authorDmitry Kostenko <codeforsmile@gmail.com>
Wed, 3 Nov 2021 23:18:09 +0000 (00:18 +0100)
committerx2048 <codeforsmile@gmail.com>
Mon, 7 Mar 2022 22:45:26 +0000 (23:45 +0100)
Add compatibility with colored shadows.

client/shaders/nodes_shader/opengl_fragment.glsl
client/shaders/object_shader/opengl_fragment.glsl

index 762a676c68be6e0d15ea7f7d2b5022a02d63d55d..d3194090cda7ab3b9ad2ff3942c139a32bc423e8 100644 (file)
@@ -514,8 +514,12 @@ void main(void)
        // Power ratio was measured on torches in MTG (brightness = 14).
        float adjusted_night_ratio = pow(max(0.0, nightRatio), 0.6);
 
-       if (f_normal_length != 0 && cosLight < 0.035) {
-               shadow_int = max(shadow_int, 1 - clamp(cosLight, 0.0, 0.035)/0.035);
+       // 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);
+               shadow_color = mix(vec3(0.0), shadow_color, min(cosLight, self_shadow_cutoff_cosine)/self_shadow_cutoff_cosine);
        }
 
        shadow_int *= f_adj_shadow_strength;
index 0b9dbc996817fd59316905db50b742514e264ef2..674b6a7393196b28f5907f338fbfe6d17115789c 100644 (file)
@@ -507,8 +507,12 @@ void main(void)
        // Power ratio was measured on torches in MTG (brightness = 14).
        float adjusted_night_ratio = pow(nightRatio, 0.6);
 
-       if (f_normal_length != 0 && cosLight < 0.035) {
-               shadow_int = max(shadow_int, 1 - clamp(cosLight, 0.0, 0.035)/0.035);
+       // cosine of the normal-to-light angle when
+       // we start to apply self-shadowing
+       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);
+               shadow_color = mix(vec3(0.0), shadow_color, min(cosLight, self_shadow_cutoff_cosine)/self_shadow_cutoff_cosine);
        }
 
        shadow_int *= f_adj_shadow_strength;