godot icon indicating copy to clipboard operation
godot copied to clipboard

Adjust StyleBoxFlat antialiasing to account for 2D stretch scale

Open Calinou opened this issue 1 year ago • 3 comments

  • Depends on https://github.com/godotengine/godot/pull/80965.

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

Calinou avatar Jun 10 '24 18:06 Calinou

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

AdriaandeJongh avatar Jun 11 '24 07:06 AdriaandeJongh

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: https://github.com/godotengine/godot/issues/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.

lostminds avatar Jun 11 '24 08:06 lostminds

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.

Calinou avatar Jun 11 '24 15:06 Calinou

Thanks!

Repiteo avatar Dec 20 '24 02:12 Repiteo