X Tutup
Skip to content

Adjust StyleBoxFlat antialiasing to account for Viewport oversampling#109358

Merged
Repiteo merged 1 commit intogodotengine:masterfrom
zenorbi:styleboxflat-antialiasing-adjust-for-oversampling
Oct 24, 2025
Merged

Adjust StyleBoxFlat antialiasing to account for Viewport oversampling#109358
Repiteo merged 1 commit intogodotengine:masterfrom
zenorbi:styleboxflat-antialiasing-adjust-for-oversampling

Conversation

@zenorbi
Copy link
Contributor

@zenorbi zenorbi commented Aug 6, 2025

Original proposal: godotengine/godot-proposals#12949

This adjusts the original antialiasing of StyleBoxFlat introduced in #92997 to account for the new per-viewport oversampling introduced later in #104872

Previously the StyleBoxFlat took the root window's stretch transform into account, independent of what the current render target was. Once per-viewport oversampling got introduced, text rendering scaled properly, but rounded corners did not, resulting in blurry edges.

In the original proposal I suggested to move the TextServer::set_current_drawn_item_oversampling to the RenderingServer instead, but looking into the implemention of the RenderingServer I am afraid that the new get_current_drawn_item_oversampling would introduce unnecessary synchronization, even though the RenderingServer would only be used to temporarily hold a double.

Testing project:

test_styleboxflat_antialiasing_stretch.zip

Preview:

Before this PR:

before

After this PR:

after

@zenorbi zenorbi requested a review from a team as a code owner August 6, 2025 15:04
@AThousandShips AThousandShips added this to the 4.x milestone Aug 6, 2025
Copy link
Member

@Calinou Calinou left a comment

Choose a reason for hiding this comment

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

Tested locally, it works as expected. Code looks good to me.

Since this uses TextServer now, it might be worth a second look from @bruvzg.

However, this has a strange effect on the MRP if you call this in _ready() in the MRP:

func _ready():
	get_viewport().oversampling_override = 0.1

Lines become much thicker and the antialiasing is mostly gone:

image

With the value set to 0.1, you can see the issue more clearly:

image

I'm not sure to which degree this is intended.

@bruvzg bruvzg self-requested a review August 6, 2025 16:21
@zenorbi zenorbi force-pushed the styleboxflat-antialiasing-adjust-for-oversampling branch from 0731546 to 8703baa Compare August 6, 2025 16:44
@zenorbi
Copy link
Contributor Author

zenorbi commented Aug 6, 2025

@Calinou I think this is still correct when the provided oversampling value fits the render target's resolution.

This is how the image looks like with oversampling override set to 0, but I scale the SubViewport's size to be 10% the resolution set in Size 2D Override.

Screenshot_20250806_231658

The lines are just fighting to still be visible.

With 0.5 scaling and filtering set to nearest to make the pixels more visible:

image

I think solving this so that the line doesn't fight but rather fades out when its width is less than the size of a pixel would require a separate PR.

Copy link
Member

@Calinou Calinou left a comment

Choose a reason for hiding this comment

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

Code looks good to me.

@Repiteo
Copy link
Contributor

Repiteo commented Oct 23, 2025

Could you rebase your PR? See our pull request guidelines for more information

@zenorbi zenorbi force-pushed the styleboxflat-antialiasing-adjust-for-oversampling branch from 8703baa to cc518e6 Compare October 23, 2025 20:50
@zenorbi zenorbi force-pushed the styleboxflat-antialiasing-adjust-for-oversampling branch from cc518e6 to a29be8f Compare October 23, 2025 20:53
@zenorbi
Copy link
Contributor Author

zenorbi commented Oct 23, 2025

Done and tested. Sorry for not noticing the merge conflict earlier.

@Repiteo Repiteo modified the milestones: 4.x, 4.6 Oct 24, 2025
Copy link
Contributor

@Repiteo Repiteo left a comment

Choose a reason for hiding this comment

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

No worries, and great job handling that so quickly!

@Repiteo Repiteo merged commit 9ee2640 into godotengine:master Oct 24, 2025
20 checks passed
@Repiteo
Copy link
Contributor

Repiteo commented Oct 24, 2025

Thanks! Congratulations on your first merged contribution! 🎉

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.

Make Viewport oversampling affect StyleBoxFlat anti aliased rendering

5 participants

X Tutup