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

Adjust StyleBoxFlat antialiasing to account for 2D stretch scale #92997

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

Calinou
Copy link
Member

@Calinou Calinou commented Jun 10, 2024

This prevents the antialiasing feather from becoming too wide at viewport sizes higher than the default, which can lead to blurry visuals.

This is adjusted to account for the 2D scale factor returned on the root Window, so it takes both the canvas_items scaling and content_scale_factor into account.

In terms of performance, the added calls take less than 1 microsecond in a debug editor build, so it's unlikely to amount to anything significant.

Line2D antialiasing can also benefit from the same technique (which could be done in a separate PR).

In the future, we can use the same opportunity to adjust corner detail based on this scale factor. This will require adjusting corner detail in the default project theme to work optimally though (i.e. without having too many triangles at high resolutions), so it's probably worth doing that in its own PR.


Other than antialiasing, the visual appearance of corners should remain as close as possible as before. Right now, border corners seem a bit less wide than before at high resolutions – I'm not sure why. I've tried to use aa_size instead of aa_size_scaled in the places that use grow() but it didn't look exactly right. @davthedev Any ideas?

Testing projects:

Preview

Both projects use a base window size of 1152×648, but the screenshots were taken at 3840×2160 resolution. For an accurate comparison, view these images at 1:1 size by opening them in a new tab.

At the original window size, the result is 100% identical to before.

Before After (this PR)
Screenshot_20240610_165114 Screenshot_20240610_202224
Before After (this PR)
Screenshot_20240610_204629 Screenshot_20240610_204457

@AdriaandeJongh
Copy link
Contributor

AdriaandeJongh commented Jun 11, 2024

What's happening here, with the different border radiuses for the fill and the border? I suspect this has nothing to do with this PR, but this PR will make it painfully obvious ;)

Screenshot 2024-06-11 at 09 24 20

@lostminds
Copy link

If this pr changes aa_size rendering offsets, perhaps it could/will also fix this old bug with incorrect offset of AA size on downscaled stylebox corner radius: #68514 . Just set a corner radius larger than size/2 and you should see it. It should probably be less noticeable if the aa offset is now based on display scale, but it'd be nice to get rid of it all together.

@Calinou
Copy link
Member Author

Calinou commented Jun 11, 2024

What's happening here, with the different border radiuses for the fill and the border? I suspect this has nothing to do with this PR, but this PR will make it painfully obvious ;)

I don't know if this is down to the focus outline having a different corner radius than the button, or whether this is a consequence of the issue I mentioned in the PR's description:

Other than antialiasing, the visual appearance of corners should remain as close as possible as before. Right now, border corners seem a bit less wide than before at high resolutions – I'm not sure why. I've tried to use aa_size instead of aa_size_scaled in the places that use grow() but it didn't look exactly right.

doc/classes/Viewport.xml Outdated Show resolved Hide resolved
Copy link
Member

@Geometror Geometror left a comment

Choose a reason for hiding this comment

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

Works as expected and code looks fine too. Nice work!

@Repiteo Repiteo modified the milestones: 4.x, 4.4 Sep 30, 2024
@Calinou Calinou force-pushed the styleboxflat-antialiasing-adjust-for-stretch-scale branch from baf7ee9 to 7db69a9 Compare October 2, 2024 00:13
@Calinou Calinou requested a review from a team as a code owner October 2, 2024 00:13
doc/classes/Viewport.xml Outdated Show resolved Hide resolved
This prevents the antialiasing feather from becoming too wide
at viewport sizes higher than the default, which can lead to blurry visuals.

This is adjusted to account for the 2D scale factor returned on the root
Window, so it takes both the `canvas_items` scaling and
`content_scale_factor` into account.
@Calinou Calinou force-pushed the styleboxflat-antialiasing-adjust-for-stretch-scale branch from 7db69a9 to b43c47d Compare December 4, 2024 00:07
@Calinou Calinou requested a review from a team as a code owner December 4, 2024 00:07
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.

6 participants