Skip to content

Commit

Permalink
Treat the rain as a range between 0.0 and 1.0, fixes #40
Browse files Browse the repository at this point in the history
  • Loading branch information
depressed-pho committed Jan 21, 2019
1 parent 8c15136 commit 611e10e
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 7 deletions.
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
10 changes: 9 additions & 1 deletion src/shaders/glsl/natural-mystic-hacks.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
29 changes: 23 additions & 6 deletions src/shaders/glsl/renderchunk.fragment
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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);
Expand All @@ -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);
Expand Down

0 comments on commit 611e10e

Please sign in to comment.