-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
Remove shadow direction quantization, increase shadow frames instead #15665
Conversation
i think we should make it a option, especially now that sfan5 removed some options with the latest commit, we need something to fill the settings screen |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
makes sense.
Changed my mind. Now shadows are quantized around noon and midnight, and in a way that does not waste resources. @sfan5 Would you have another look? |
* At those times we update shadows less often. | ||
*/ | ||
v3f q_direction = quantizeDirection(direction, M_PI / 2880 /*15 seconds*/); | ||
if (q_direction == last_quant_directin) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
float comparison is OK here, since quantizeDirection uses ceil for integer math.
src/client/shadows/dynamicshadows.h
Outdated
@@ -102,6 +102,7 @@ class DirectionalLight | |||
|
|||
v3f last_cam_pos_world{0,0,0}; | |||
v3f last_look{0,1,0}; | |||
v3f last_quant_directin{0,0,0}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
v3f last_quant_directin{0,0,0}; | |
v3f last_quant_direction{0,0,0}; |
EDIT: or
v3f last_quant_directin{0,0,0}; | |
v3f last_quant_direction; |
(use default constructor)
{ | ||
if (dirty && !force) | ||
return; | ||
|
||
if (timeoftheday < 0.1 || timeoftheday > 0.9 || (timeoftheday > 0.4 && timeoftheday < 0.6)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What if set_sky
is used, where the sun is tilted? The shadows would still change noticeably during these time limits.
I don't see why we should quantize the direction at all? |
@sfan5 ok... I'll revert the last two commits and then merge (the changes you had already reviewed) |
OK. Reverted the last two commits and re-added @sfan5's original approval of the first commit. |
Ever wondered why shadows are laggy even when you set
shadow_update_frames
to 1?This most visible at dusk and dawn when shadows change quickly due to the angle of the sun.
This has bothered me for quite a while, so I finally tracked it down.
This was due to the direction quantization we do, which was added to reduce the jittering in the shadows (if it is updated less frequently you do not notice the jittering so much).
I had an earlier version where I quantize less during dusk and dawn, but in the end I think we should just remove it. If we really wanted to I can bring quantization back around midday and midnight whrere shadows move the least at the jittering would be most obvious)
The old logic shows a different shadow every PI/2880 change, at a day length of 20 minutes that comes to about 0.2s (20*60/2/pi/2880 = 0.2083...), which matches my observation.
So we go through all the work calculating shadows, etc, just to not show them more than 5 times/s.
Instead we roughly get the same effect if
shadow_update_frames
is set to 16 (assuming 60 FPS).For nice machines and larger shadow texture, folks now reduce this to get smooth shadow movement.
Goal of the PR
Allow for smoothly changing shadows.
How does the PR work?
Removing sun/moon direction quantization, replace it by increasing shadow update frames.
And that allows getting smooth shadow movements on better machine by reducing shadow update frames.
Does it resolve any reported issue?
Nope
Does this relate to a goal in the roadmap?
Nope
If not a bug fix, why is this PR needed? What usecases does it solve?
Shadows were laggy.
To do
This PR is Ready for Review.
How to test
Enable shadows. Pick a good view distance, set time to dusk/dawn and observe shadows moving in a choppy way.
Assuming 60FS this should be roughly the same before and after.
Now reduce
shadow_update_frames
to 1 and enjoy smoothly moving shadows.