diff options
author | Paramat <paramat@users.noreply.github.com> | 2019-04-04 23:30:10 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-04-04 23:30:10 +0100 |
commit | 5b8363af0084786a7e949ae8fa16bde046f8ffda (patch) | |
tree | f9f84305c883ba14f93c4a97dc25401103f65c47 /src | |
parent | d1118658902cb70182718f3a32c72b1cd799285f (diff) | |
download | minetest-5b8363af0084786a7e949ae8fa16bde046f8ffda.tar.gz minetest-5b8363af0084786a7e949ae8fa16bde046f8ffda.tar.bz2 minetest-5b8363af0084786a7e949ae8fa16bde046f8ffda.zip |
Stabilise 'day night ratio' to fix object brightness flicker (#8417)
Previously, when basic shaders were enabled, the function
time_to_daynight_ratio() returned values jumping between 149 and 150
between times 4375 and 4625, and values jumping between 999 and 1000
between times 6125 and 6375, (and the corresponding times at sunset)
due to tiny float errors in the interpolation code.
This caused the light level returned by blend_light() to jump between
14 and 15, which became noticeable recently as those light levels were
given different visual brightnesses.
Add early returns to avoid the problematic interpolation, and to
avoid unnecessary running of the loop.
Diffstat (limited to 'src')
-rw-r--r-- | src/daynightratio.h | 8 |
1 files changed, 5 insertions, 3 deletions
diff --git a/src/daynightratio.h b/src/daynightratio.h index f959cdf6c..a7b93234e 100644 --- a/src/daynightratio.h +++ b/src/daynightratio.h @@ -52,15 +52,17 @@ inline u32 time_to_daynight_ratio(float time_of_day, bool smooth) return 1000; } + if (t <= 4625) // 4500 + 125 + return values[0][1]; + else if (t >= 6125) // 6000 + 125 + return 1000; for (u32 i=0; i < sizeof(values) / sizeof(*values); i++) { if (values[i][0] <= t) continue; - if (i == 0) - return values[i][1]; + float td0 = values[i][0] - values[i-1][0]; float f = (t - values[i-1][0]) / td0; return f * values[i][1] + (1.0 - f) * values[i-1][1]; } return 1000; - } |