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

AtlasTexture Fix calculating rects when flipping #70227

Merged
merged 1 commit into from
Dec 17, 2022

Conversation

kleonc
Copy link
Member

@kleonc kleonc commented Dec 17, 2022

Fixes #70178.

The issue was likely caused/revealed by #56795/#56796, quoting myself:

(...) As a result an AtlasTexture being a source atlas of another AtlasTexture could have resulted in incorrect rendering. This should be fixed now (assuming other methods work as they're supposed to).

Seems like this wasn't the case, offset calculations when flipping the texture (when destination rect has negative size):

Vector2 ofs = (src_c.position - src.position);
if (scale.x < 0) {
float mx = (margin.size.width - margin.position.x);
mx -= margin.position.x;
ofs.x = -(ofs.x + mx);
}
if (scale.y < 0) {
float my = margin.size.height - margin.position.y;
my -= margin.position.y;
ofs.y = -(ofs.y + my);
}

don't make much sense to me. When not flipping the offset is correctly the difference of the positions of the clipped source rect and the non-clipped source rect. When flipping the offset (for the axes being flipped) should be the difference between the rect.ends of the same rects instead (this should already account for the margins as the source rect is clipped to the region), meaning just adding the difference of the sizes of these rects should be enough. And that's what this PR does, the rest are cosmetic changes to clarify the code a little (renaming/removing some variables).

@kleonc kleonc added this to the 4.0 milestone Dec 17, 2022
@akien-mga akien-mga added cherrypick:3.x Considered for cherry-picking into a future 3.x release cherrypick:3.5 Considered for cherry-picking into a future 3.5.x release labels Dec 17, 2022
@akien-mga akien-mga merged commit 7bf6561 into godotengine:master Dec 17, 2022
@akien-mga
Copy link
Member

Thanks!

@kleonc kleonc deleted the atlas-texture-flipping-fix branch December 18, 2022 00:07
@timothyqiu
Copy link
Member

timothyqiu commented Dec 21, 2022

Cherry-picked for 3.6.

@timothyqiu timothyqiu removed the cherrypick:3.x Considered for cherry-picking into a future 3.x release label Dec 21, 2022
@akien-mga
Copy link
Member

Cherry-picked for 3.5.2.

@akien-mga akien-mga removed the cherrypick:3.5 Considered for cherry-picking into a future 3.5.x release label Dec 22, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

AtlasTexture on AnimatedSprite draws incorrectly with horizontal flip
3 participants