aboutsummaryrefslogtreecommitdiff
path: root/client
diff options
context:
space:
mode:
authorDmitry Kostenko <codeforsmile@gmail.com>2021-11-04 00:18:09 +0100
committerx2048 <codeforsmile@gmail.com>2022-03-07 23:45:26 +0100
commitf2cccf8da72c39299c8e7ba6ad8f782a7d61b883 (patch)
treeee4639b2090bc55a709d46187b310fd775c65c4d /client
parent10be033791dd71af6ba3120eb6a397f27673c2bb (diff)
downloadminetest-f2cccf8da72c39299c8e7ba6ad8f782a7d61b883.tar.gz
minetest-f2cccf8da72c39299c8e7ba6ad8f782a7d61b883.tar.bz2
minetest-f2cccf8da72c39299c8e7ba6ad8f782a7d61b883.zip
Improve self-shadowing based on light/normal angle
Add compatibility with colored shadows.
Diffstat (limited to 'client')
-rw-r--r--client/shaders/nodes_shader/opengl_fragment.glsl8
-rw-r--r--client/shaders/object_shader/opengl_fragment.glsl8
2 files changed, 12 insertions, 4 deletions
diff --git a/client/shaders/nodes_shader/opengl_fragment.glsl b/client/shaders/nodes_shader/opengl_fragment.glsl
index 762a676c6..d3194090c 100644
--- a/client/shaders/nodes_shader/opengl_fragment.glsl
+++ b/client/shaders/nodes_shader/opengl_fragment.glsl
@@ -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;
diff --git a/client/shaders/object_shader/opengl_fragment.glsl b/client/shaders/object_shader/opengl_fragment.glsl
index 0b9dbc996..674b6a739 100644
--- a/client/shaders/object_shader/opengl_fragment.glsl
+++ b/client/shaders/object_shader/opengl_fragment.glsl
@@ -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;