core: Fix MorphShape inaccuracy on complex paths #14089
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
SWF stores edges as deltas in its ShapeRecords. When interpolating MorphShapes, Ruffle interpolates these deltas instead of interpolating the absolute positions of the control points. This can cause incorrect rendering of shape tweens.
Explanation in detail:
Imagine a complex path made of many small segments.
The smallest deltas in the path might only be one twip long.
Imagine we're tweening the shape with a shape tween that stretches it out to twice its size.
Consider what happens to a single delta as the ratio smoothly increases from 0 to 1.
The delta is quantized, so it's unable to smoothly stretch from being 1 twip long to being 2 twips long.
Instead, it'll instantaneously "jump" to being 2 twips long as soon as the ratio exceeds 0.5.
Add up all these "jumping" deltas and you get a very jittery tween.
The solution:
MorphShapes should be interpolated using the absolute positions of the control points, not the deltas.
Before:
bad.mov
After:
good.mov
I added this example SWF as a test case in
movieclip_hittest_shapeflag
.Affected SWF in the wild:
https://foon.uk/farcade/hapland2/ — The surface of the water is glitchy because of this.