Adjust StyleBoxFlat antialiasing to account for 2D stretch scale
- 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:
- test_styleboxflat_antialiasing_stretch.zip
- https://github.com/godotengine/godot-demo-projects/tree/master/gui/control_gallery
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) |
|---|---|
| Before | After (this PR) |
|---|---|
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 ;)
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.
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.
Thanks!