Godot: Font oversampling doesn't work with custom viewports

Created on 15 Apr 2019  ·  10Comments  ·  Source: godotengine/godot

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

bug confirmed rendering

Most helpful comment

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

All 10 comments

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).

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.

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.

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.

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

@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.

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...) 🤷‍♂️

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

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.

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.

Was this page helpful?
0 / 5 - 0 ratings