Improve self-shadowing based on light/normal angle

Add compatibility with colored shadows.
This commit is contained in:
Dmitry Kostenko 2021-11-04 00:18:09 +01:00 committed by x2048
parent 10be033791
commit f2cccf8da7
2 changed files with 12 additions and 4 deletions

@ -514,8 +514,12 @@ void main(void)
// Power ratio was measured on torches in MTG (brightness = 14). // Power ratio was measured on torches in MTG (brightness = 14).
float adjusted_night_ratio = pow(max(0.0, nightRatio), 0.6); float adjusted_night_ratio = pow(max(0.0, nightRatio), 0.6);
if (f_normal_length != 0 && cosLight < 0.035) { // Apply self-shadowing when light falls at a narrow angle to the surface
shadow_int = max(shadow_int, 1 - clamp(cosLight, 0.0, 0.035)/0.035); // 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; shadow_int *= f_adj_shadow_strength;

@ -507,8 +507,12 @@ void main(void)
// Power ratio was measured on torches in MTG (brightness = 14). // Power ratio was measured on torches in MTG (brightness = 14).
float adjusted_night_ratio = pow(nightRatio, 0.6); float adjusted_night_ratio = pow(nightRatio, 0.6);
if (f_normal_length != 0 && cosLight < 0.035) { // cosine of the normal-to-light angle when
shadow_int = max(shadow_int, 1 - clamp(cosLight, 0.0, 0.035)/0.035); // 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; shadow_int *= f_adj_shadow_strength;