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

Font oversampling doesn't work with custom viewports #28045

Closed
IsjaslawEisenstadt opened this issue Apr 15, 2019 · 14 comments
Closed

Font oversampling doesn't work with custom viewports #28045

IsjaslawEisenstadt opened this issue Apr 15, 2019 · 14 comments

Comments

@IsjaslawEisenstadt
Copy link

Godot version:
3.1 Stable

OS/device including version:
Windows 7

Issue description:
Controls with text won't benefit from font oversampling when placed inside a Viewport and a Viewportcontainer.

Steps to reproduce:
Create a DynamicFont and assign it to a Label. Put the Label inside a Viewport and put the Viewport inside a Viewportcontainer. Enable Font Oversampling in the project settings and set the stretch mode to 2D and aspect to keep. The Label will get blurred upon resizing the window when running the project.
Filter and mipmaps in the DynamicFont doesn't resolve it either.

Minimal reproduction project:
viewport_oversampling_mrp.zip

@Calinou
Copy link
Member

Calinou commented Apr 15, 2019

Font oversampling is currently a global property that scales all DynamicFonts with the same factor, so maybe we need the ability to selectively disable it for specific DynamicFont resources.

A workaround I can think of is resizing the Viewport and scaling the Label depending on the resolution, so that it becomes larger on larger resolutions (and won't be blurry since the font size will match the label size more or less).

@reduz
Copy link
Member

reduz commented Aug 6, 2019

Font oversampling is a global setting, so it will not work on custom viewports.
I think the solution here would most likely to allow disabling it in individual fonts.

@IsjaslawEisenstadt
Copy link
Author

Why would it be a solution to have a toggle for disabling font oversampling on individual fonts when it already doesn't work?

My problem is that I'd like to alpha mask a VBoxContainer with all of its Label children. My current solution would be to place the container inside a Viewport, but the fonts will be pixelated when I do this. Calinous solution is only a bandaid fix and doesn't look good on most resolutions.

@Calinou
Copy link
Member

Calinou commented Aug 7, 2019

My current solution would be to place the container inside a Viewport, but the fonts will be pixelated when I do this.

Last time I checked, you can enable filtering on a ViewportTexture that's applied to a Sprite or TextureRect by editing it then enabling the Filter flag.

@TheMoye
Copy link

TheMoye commented Jan 30, 2020

I don't know if it's the same issue, but I have this Warning on console with fresh 3.2 Godot release :

godot_warning

@Calinou
Copy link
Member

Calinou commented Jan 30, 2020

@TheMoye Font oversampling doesn't make sense if you use the disabled or viewport stretch modes. There's no way you can render a font at an higher resolution and actually benefit from the increased resolution in those modes.

@TheMoye
Copy link

TheMoye commented Jan 30, 2020

Hi @Calinou ,

Okay, I can understand that. But why is Godot giving me this Warning? Especially since I don't use any font. My scene tree doesn't contain any character nodes (label, richtextlabel...) 🤷‍♂️

@Calinou
Copy link
Member

Calinou commented Jan 30, 2020

@TheMoye Disable Rendering > Quality > Dynamic Fonts > Use Oversampling in the Project Settings.

@kuruk-mm
Copy link
Contributor

I'm having the same problem. I need to draw some texts inside a Viewport.

I have "Use Oversampling" enable, and I use 2d strech mode.

Look this image:
image

First image is from Viewport, and the second one is outside the Viewport (it is using the same DynamicFont)

Project structure:
image

Project:
TestViewportText.zip

I already test every option in the Viewport, and I searched and tried a lot, haha.

@kuruk-mm
Copy link
Contributor

kuruk-mm commented Jul 1, 2020

Ok, I found a solution for this problem.

When the game resizes I resize the custom viewport to fit it parent from GDScript, and I put a Camera2D in the custom viewport to zoom in to get the same proportion.

Here is the script (to keep_height), you can change how the zoom is calculated keep or keep_width.

func _ready():
	_screen_resized()
	get_tree().connect("screen_resized", self, "_screen_resized")

func _screen_resized() :
	var custom_viewport = $ViewportContainer/Viewport
	var camera_2d = $ViewportContainer/Viewport/Camera2D
	custom_viewport.size = get_tree().get_root().size
	camera_2d.zoom.x = ProjectSettings.get("display/window/size/width") / custom_viewport.size.x
	camera_2d.zoom.y = camera_2d.zoom.x

Result:

image

Example project:
TestViewportText.zip

With this, I have had some problems with TileMaps in some resolutions (black lines between tiles), but I limited the resolutions and it's working well.

@bmolyneaux
Copy link
Contributor

@TheMoye Disable Rendering > Quality > Dynamic Fonts > Use Oversampling in the Project Settings.

Perhaps the error message should instead say to disable font oversampling if you are using Viewport stretch mode. It's not obvious that font oversampling is a project setting.

@Calinou
Copy link
Member

Calinou commented Feb 9, 2021

@bmolyneaux This is already the case in the latest 3.2 branch:

WARN_PRINT("Font oversampling only works with the stretch modes \"Keep Width\", \"Keep Height\" and \"Expand\", not \"Ignore\". To remove this warning, disable Rendering > Quality > Dynamic Fonts > Use Oversampling in the Project Settings.");

WARN_PRINT("Font oversampling does not work in \"Viewport\" stretch mode, only \"2D\". To remove this warning, disable Rendering > Quality > Dynamic Fonts > Use Oversampling in the Project Settings.");

@Calinou
Copy link
Member

Calinou commented Jun 23, 2022

This is now addressed in two ways:

  • The font oversampling factor can be set on a per-DynamicFont basis using the oversampling property greater than 0.0 (exclusive). In your custom Viewports that do not resize with the window, force the oversampling on the fonts used within the viewport to a value like 1.0.
    • In 3.5.rc, this property is override_oversampling on DynamicFontData.
    • In 4.0.alpha, this property is oversampling on Font.
  • In 4.0.alpha, MSDF font rendering can be used for crisp rendering at any resolution, without requiring oversampling (and therefore avoiding re-rasterization when the viewport scale changes).

@Calinou Calinou closed this as completed Jun 23, 2022
@Calinou Calinou added this to the 3.5 milestone Jun 23, 2022
@wolf1612
Copy link

@kuruk-mm Can I also make the Camera2D as a child of the Viewport and all the labels, containers, maptiles, tiles etc. as childs of the Camera or can/should I make all the Nodes(Lables,Containers, Maptiles, etc.) childs of the Viewport and the Camera also as child of the Viewport as you did in your code?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

8 participants