diff --git a/NEWS.md b/NEWS.md index e2d5ab2..1ec8c01 100644 --- a/NEWS.md +++ b/NEWS.md @@ -5,6 +5,8 @@ * Reworked the water completely. Now it has much more convincing waves and specular highlights. * Clouds now have highlights and shade. +* Shadows no longer disappear all of a sudden when it starts raining + (#40). ## 1.4.0 -- 2019-01-14 diff --git a/src/shaders/glsl/natural-mystic-hacks.h b/src/shaders/glsl/natural-mystic-hacks.h index 7df64ff..2a603dc 100644 --- a/src/shaders/glsl/natural-mystic-hacks.h +++ b/src/shaders/glsl/natural-mystic-hacks.h @@ -55,7 +55,15 @@ bool isTheEndFog(vec4 fogColor) { * also be the bad weather fog. */ bool isRenderDistanceFog(vec2 fogControl) { - return fogControl.x > 0.5; + return fogControl.x > 0.6; +} + +/* When it's raining on the Overworld, the game gradually reduces the + * fog far to < 1.0. We exploit this fact to detect rain. This + * function returns 0.0 when it's raining, and 1.0 otherwise. + */ +float isClearWeather(vec2 fogControl) { + return smoothstep(0.8, 1.0, fogControl.y); } #endif /* NATURAL_MYSTIC_HACKS_H_INCLUDED */ diff --git a/src/shaders/glsl/renderchunk.fragment b/src/shaders/glsl/renderchunk.fragment index 23128f1..47abc8b 100644 --- a/src/shaders/glsl/renderchunk.fragment +++ b/src/shaders/glsl/renderchunk.fragment @@ -116,6 +116,11 @@ vec4 inColor = color; #else const bool isUnderwater = false; #endif /* defined(UNDERWATER) */ +#if defined(FOG) + float clearWeather = isClearWeather(FOG_CONTROL); +#else + const float clearWeather = 1.0; +#endif /* defined(FOG) */ vec3 ambientColor; #if defined(FOG) @@ -125,13 +130,21 @@ vec4 inColor = color; ambientColor = ambientLightColor(uv1.y, daylight); } else { - ambientColor = ambientLightColor(fogColor); - /* The existence of bad weather fog (and also underwater fog) * should increase the intensity of ambient light (#32). But * at night it should work the other way. */ - ambientBrightness *= mix(0.9, 1.4, daylight); + if (isUnderwater) { + ambientColor = ambientLightColor(fogColor); + ambientBrightness *= mix(0.9, 1.4, daylight); + } + else { + ambientColor = mix( + ambientLightColor(fogColor), + ambientLightColor(uv1.y, daylight), + clearWeather); + ambientBrightness *= mix(mix(0.9, 1.4, daylight), 1.0, clearWeather); + } } #else ambientColor = ambientLightColor(uv1.y, daylight); @@ -148,13 +161,17 @@ vec4 inColor = color; light += ambientLight(ambientColor, ambientBrightness); #if defined(FOG) /* When it's raining the sunlight shouldn't affect the scene - * (#24), but this has a side effect. Shadows appear and disappear - * all of sudden (#33). + * (#24), but we cannot treat the rain as a boolean switch as that + * would cause #40. */ - if (isUnderwater || isRenderDistanceFog(FOG_CONTROL)) { + if (isUnderwater) { light += sunlight(uv1.y, daylight); light += moonlight(uv1.y, daylight); } + else { + light += sunlight(uv1.y, daylight) * clearWeather; + light += moonlight(uv1.y, daylight) * clearWeather; + } #else light += sunlight(uv1.y, daylight); light += moonlight(uv1.y, daylight);