godot icon indicating copy to clipboard operation
godot copied to clipboard

Relax motion vector updates to allow skipped frames for skeletons

Open zeux opened this issue 1 year ago • 1 comments

Before this change, a skeleton that was not updated every frame would result in a difference of 2+ between last_change and frame index every frame, which would disable the buffer rotation and set motion vectors to zero. This results in significant visual artifacts for FSR2 that are especially prominent on the characters that move together with the view such as the main character in third person mode.

This is a significant problem for high refresh rate displays: at 120 Hz, we are effectively guaranteed to skip skeleton updates every other frame with skeleton update happening during physics processing, and the lack of physics interpolation for skeletons. This happens by default in TPS demo when FSR2 is enabled and resolution is below native:

image

In other places where motion vectors are disabled, such as multi-mesh and mesh rendering (where previous transform is updated), the logic effectively allows for a single-frame gap in updates, because it compares the frame where the update happened (which is the current frame if updates are consistent) with the current frame, so the latency of 0 means "update just happened", but both multi-mesh and mesh transform updates permit a latency of 1 as well:

https://github.com/godotengine/godot/blob/1bd740d18d714f815486b04bf4c6154ef6c355d9/servers/rendering/renderer_rd/forward_clustered/render_forward_clustered.cpp#L705-L708 https://github.com/godotengine/godot/blob/1bd740d18d714f815486b04bf4c6154ef6c355d9/servers/rendering/renderer_rd/storage_rd/mesh_storage.cpp#L1610-L1612

Here, however, last_change is updated after the frame processing has concluded, so a zero-latency update has a distance of 1. Allowing a distance of 2 (latency 1) reduces the severity of the problem and aligns the logic with transform updates.

With this change at 120 Hz (and even 144 Hz) the problem is not visible:

image

Note that the problem will still happen when refresh rate is noticeably higher than physics rate times 2. For example, it still happens at 240 Hz. However, a longer latency allowance is inconsistent with other transforms and could lead to issues, so ideally long term physics interpolation of skeleton transforms would completely solve this.

zeux avatar Aug 17 '24 17:08 zeux

This makes sense to support for stepped updates for distant animations (which is common for NPCs in open world games), although I still maintain the main character really ought to have physics interpolation affect its skeleton.

Calinou avatar Aug 17 '24 17:08 Calinou

Thanks!

akien-mga avatar Aug 19 '24 10:08 akien-mga

Cherry-picked for 4.3.1.

akien-mga avatar Sep 16 '24 15:09 akien-mga