-
Notifications
You must be signed in to change notification settings - Fork 2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Objects flicker in brightness between time 6125 and 6375 (and at sunset) (basic shaders on) #8416
Comments
t 4444.366211 f 0.277465 dnr 149.999999
t 4444.706543 f 0.278826 dnr 149.999998
t 4444.706543 f 0.278826 dnr 149.999998
t 4444.706543 f 0.278826 dnr 149.999998
bl 2 t 4444.706543 f 0.278826 dnr 149.999998
t 4444.706543 f 0.278826 dnr 149.999998
t 4444.706543 f 0.278826 dnr 149.999998
t 4444.706543 f 0.278826 dnr 149.999998
t 4444.706543 f 0.278826 dnr 149.999998
t 4444.706543 f 0.278826 dnr 149.999998 t 4446.046875 f 0.284187 dnr 150.000000
t 4446.366699 f 0.285467 dnr 150.000000
t 4446.366699 f 0.285467 dnr 150.000000
t 4446.366699 f 0.285467 dnr 150.000000
bl 2 t 4446.366699 f 0.285467 dnr 150.000000
t 4446.366699 f 0.285467 dnr 150.000000
t 4446.366699 f 0.285467 dnr 150.000000
t 4446.366699 f 0.285467 dnr 150.000000
t 4446.366699 f 0.285467 dnr 150.000000
t 4446.366699 f 0.285467 dnr 150.000000 Same interpolation jumpiness, so returned value will jump between 149 and 150, but this time both light levels are 2 for the default light curve. This should be fixed too. My fix will be to only return 150, 1000, or smoothly varying values between. |
Confirmed by printf() the value returned by With shaders off, |
This code can also be much optimised, the table should be 'static', and codestyle needs work, i'll do this in a follow-up PR. |
PR #8417 |
Nice find. I had observed the same... But never actually looked at why this would be happening. |
Folow up PR could consider a better interpolation method, see IRC http://irc.minetest.net/minetest-dev/2019-03-25#i_5517930 01:40 p_gimeno The instability probably comes from the formula for linear interpolation. That formula is not monotonic and has problems. I suggest an alternate formula here: http://math.stackexchange.com/questions/907327/accurate-floating-point-linear-interpolation |
Noticed this while when working on something else.
I added printf() lines to src/daynightratio.h.
When basic shaders are on, the
smooth
bool is true so the loop at the end of the function is used.Also to src/light.h.
to print:
I discovered that
time_to_daynight_ratio()
behaves like this:During sunrise until time 6125, day night ratio smoothly increases towards 1000 (full brightness) as it interpolates between the value pairs in the table.
Between time 6125 and 6375 it is interpolating between two 1000 values, but tiny float errors cause the result of the interpolation to jump back and forth between, for example, 999.999995 and 1000.000006. Because the function returns an integer the returned value switches between 999 and 1000.
Printing the light level calculated by
blend_light()
shows that these tiny changes cause the lightlevel to jump back and forth between 14 and 15, causing objects to flicker.This is only noticeable recently because the visual brightness of light levels 14 and 15 were identical until recently, now they differ.
After time 6375 the function returns 1000 all the time, the calculated light level is always 15 and object brightness stops flickering.
Printed data in terminal:
During flicker:
After time 6375:
I will fix this soon.
A similar problem may possibly occur when time is between 4375 and 4625, as the interpolation is between 2 identical values.
The text was updated successfully, but these errors were encountered: