godot icon indicating copy to clipboard operation
godot copied to clipboard

Fix animation compression going the wrong way

Open fire opened this issue 1 year ago • 5 comments

On the compression page break breaks the animation rotates wrongly.

Fixes: https://github.com/godotengine/godot/issues/96882

See also https://stackoverflow.com/a/47190699/381724 discussion about rint() and nearbyint(). Math::fast_ftoi uses rint which appears to be using FE_TONEAREST.

See https://stackoverflow.com/questions/311696/why-does-net-use-bankers-rounding-as-default about discussion about banker's rounding which is FE_TONEAREST.

fire avatar Sep 21 '24 17:09 fire

Video of the mrp of animation compression with the fix applied.

https://youtu.be/b5wAQqX9XsM

fire avatar Sep 21 '24 17:09 fire

I'll rewrite the commit message to be slightly better.

fire avatar Sep 22 '24 02:09 fire

I think this is the right way to go, since it seems right to use round(nearest) at least for bit sampling, and this PR is appropriate as Math::fast_ftoi() is faster than Math::round().

However, note that this fix eliminates glitching, it still causes the stutter in the same as Math::round() as I commented in https://github.com/godotengine/godot/issues/96882#issuecomment-2344978163, and there are still areas that could be improved.

https://github.com/user-attachments/assets/24972a2c-b4ed-4e0d-9ead-e4f044917db4

For example, it might be possible to do something like blending the prev page's last few bits and next page's first few bits when decoding to make it smooth like anti-aliasing.

Or it may simply be that there is still a boundary error lurking somewhere, as I commented in there.

TokageItLab avatar Sep 22 '24 14:09 TokageItLab

Would it work to use a cubic interpolation for blending the prev page's last few bits and next page's first few bits?

fire avatar Sep 22 '24 22:09 fire

Since this stutter does not occur unless we use a round()(or fast_ftoi()), I would expect that it is a boundary value error due to some boundary being implemented with assuming to floor truncating, but I do not know where that is.

TokageItLab avatar Sep 22 '24 23:09 TokageItLab

Should this be merged as is, or should some more work be done first to work on the other problem identified?

akien-mga avatar Sep 24 '24 10:09 akien-mga

There is definitely still work to be done, but IMO the stutter still looks better than the glitch, so I think it is acceptable to merge this PR and postpone the work to eliminate the stutter in the later.

TokageItLab avatar Sep 24 '24 13:09 TokageItLab

Thanks!

akien-mga avatar Sep 25 '24 11:09 akien-mga