From f2cccf8da72c39299c8e7ba6ad8f782a7d61b883 Mon Sep 17 00:00:00 2001 From: Dmitry Kostenko Date: Thu, 4 Nov 2021 00:18:09 +0100 Subject: Improve self-shadowing based on light/normal angle Add compatibility with colored shadows. --- client/shaders/nodes_shader/opengl_fragment.glsl | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'client/shaders/nodes_shader') 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; -- cgit v1.2.3