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

Added accurate_alpha parameter to fix blending #37503

Closed
wants to merge 1 commit into from

Conversation

azagaya
Copy link
Contributor

@azagaya azagaya commented Apr 1, 2020

Fixes #31124

@azagaya
Copy link
Contributor Author

azagaya commented Apr 1, 2020

Oh i forgot clang_format again

core/image.h Outdated
Comment on lines 348 to 349
void blend_rect(const Ref<Image> &p_src, const Rect2 &p_src_rect, const Point2 &p_dest, bool accurate_alpha = false);
void blend_rect_mask(const Ref<Image> &p_src, const Ref<Image> &p_mask, const Rect2 &p_src_rect, const Point2 &p_dest, bool accurate_alpha = false);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Parameters in C++ prototypes are prefixed with p_, so this should be p_accurate_alpha.

@akien-mga
Copy link
Member

I'm not sure that the parameter's name properly conveys what it involves, but otherwise the code looks OK.

Please also add the relevant documentation to doc/classes/Image.xml.

@akien-mga akien-mga requested a review from reduz April 10, 2020 10:13
@azagaya
Copy link
Contributor Author

azagaya commented Apr 10, 2020

I'm not sure that the parameter's name properly conveys what it involves

p_accurate_blending would be better?

@akien-mga
Copy link
Member

akien-mga commented Apr 10, 2020

p_accurate_blending would be better?

Well, why would anyone want inaccurate blending in a function named "blend"? :)

@azagaya
Copy link
Contributor Author

azagaya commented Apr 10, 2020

p_accurate_blending would be better?

Well, why would anyone want inaccurate blending in a function named "blend"? :)

According to the issue discussing this, this is what i understood. Usually in a game, you blend against a fully opaque background. In those cases, the result without the fix is the same as if it had the fix, because dc.a equals 1. So, in those cases, the fix would be an unnecessary loss of performance for each pixel blended.
However, you may want to export some blended images from your game, without fully opaque transparency (like the project uploaded to test the issue). In those cases, not dividing by dc.a will give you darkened areas in regions not fully opaque. So, in those cases, the blending is not being accurate.
I initially proposed something like fix_alpha, or maybe fix_alpha_darkening.
What do you think?

@azagaya azagaya requested a review from a team as a code owner April 10, 2020 12:55
@bojidar-bg
Copy link
Contributor

Not sure if it is applicable for this case, but maybe p_premultipled_alpha or p_straight_alpha might do?

@azagaya
Copy link
Contributor Author

azagaya commented Apr 10, 2020

Not sure if it is applicable for this case, but maybe p_premultipled_alpha or p_straight_alpha might do?

Well, i think the output without the fix could be thought as the value in "premultiplied alpha". And as the fix divides by alpha, it could be thought that the fix is converting premultiplied to straight. So perhaps the parameter could be called "p_straight_alpha" as you suggest.

@azagaya
Copy link
Contributor Author

azagaya commented Apr 13, 2020

Should i rename the parameter to any of those options?

@azagaya
Copy link
Contributor Author

azagaya commented Apr 17, 2020

Should i use Color.blend() as suggested in the issue? It seems to work fine with that, and that function is already implemented.

@OverloadedOrama
Copy link
Contributor

Is there any chance this will be merged before 3.2.2? It would be really helpful for Pixelorama.

@akien-mga akien-mga removed the cherrypick:3.x Considered for cherry-picking into a future 3.x release label Jun 7, 2020
@akien-mga
Copy link
Member

Superseded by #39200.

@akien-mga akien-mga closed this Jun 7, 2020
@azagaya azagaya deleted the fix-blend-rect branch June 10, 2021 19:35
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.

Image::blend_rect might not blend as expected
5 participants