Skip to content
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

core: Fix MorphShape inaccuracy on complex paths #14089

Merged
merged 4 commits into from
Nov 21, 2023

Conversation

rogual
Copy link
Contributor

@rogual rogual commented Nov 20, 2023

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.

@Dinnerbone
Copy link
Contributor

Thank you so much! Nice work, and thanks for the test :)

It's inaccurate to interpolate the moveTo/lineTo deltas individually
because on complex paths they're often small integers, which won't
interpolate smoothly.

Instead, interpolate absolute positions.
It's from the control point, not from the start point.
@Dinnerbone Dinnerbone enabled auto-merge (squash) November 21, 2023 12:28
@Dinnerbone Dinnerbone merged commit cad1621 into ruffle-rs:master Nov 21, 2023
13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants