godotengine / godot

Godot Engine – Multi-platform 2D and 3D game engine
https://godotengine.org
MIT License
90.35k stars 21.06k forks source link

Incorrect font rendering despite disabling Subpixel Positioning #74694

Closed 20milliliter closed 1 year ago

20milliliter commented 1 year ago

Godot version

4.0.stable

System information

Windows 10, Forward+, NVIDIA Studio 527.56

Issue description

A pixel font is being rendered incorrectly despite disabling Subpixel Positioning. (#70327)

image *image is exact size

Steps to reproduce

The minimal reproduction project shows various sizes of the font, comparing their appearance in engine and how they are supposed to look (via a keep size texture rect containing an image created seperately).

The left column shows the text in engine, the right shows the texture rects. The font sizes from top to bottom are 12, 16, 24, 32, and 36.

Minimal reproduction project

Bug.zip

xahon commented 1 year ago

I have an issue with font rendering as well. On the left is rendered text in Godot (10px size) and on the right default Windows 10 font viewer image

I've tried different import options. I use these options now because it looks the best of all other setting sets image

The UI control and all it's parents are not scaled (1, 1, 1)


Here is an SDF approach. On the left is how it looks like in the editor, on the right how it looks in the game

image

I've tried different MSDF settings, it still looks awful

It worth noting that I use fixed viewport size and window override. Both have the same aspect ratio.

thornySoap commented 1 year ago

This is only when alignment is center (isn't it), so probably a devide-by-2 thing

Calinou commented 1 year ago

This is not a bug; this occurs because you're displaying the font at a non-integer multiple. Pixel art fonts must be displayed at a multiple of the size they were designed for to look correct. If you follow this guidance correctly (including on the scale of Control nodes that display the font), you shouldn't even need to disable antialiasing on import – disabling subpixel positioning is enough.

For example, if I enable antialiasing, notice how all fonts turn blurry except the ones that are a multiple of the intended size (16 and 32):

image

Unifont is designed for size 16.

thornySoap commented 1 year ago

But then how to explain this?:

![Screenshot 2023-05-15 17:28:07](https://github.com/godotengine/godot/assets/115401023/b896548d-6a6e-402a-af9c-649384b766e1) ![Screenshot 2023-05-15 17:28:07](https://github.com/godotengine/godot/assets/115401023/07a831ca-cedc-4708-8433-5cfa03ee0b79)
viewport width 200 width 199
Calinou commented 1 year ago

@thornySoap If using the canvas_items or viewport stretch mode, this is likely an issue with the window size not being an integer multiple, which causes uneven pixel scaling. See https://github.com/godotengine/godot-proposals/issues/1666.

thornySoap commented 1 year ago

@Calinou this is with stretch mode disabled:

Screenshot 2023-05-15 17:28:07

test.zip

Calinou commented 1 year ago

@thornySoap You have subpixel positioning set to Auto on fonts/Pixeloid/PixeloidSans.ttf in the Import dock. Set it to Disabled, click Reimport then use Scene > Reload Saved Scene. Doing so fixes the font display for me in the MRP you uploaded.

thornySoap commented 1 year ago

@Calinou thank you yery much. Sorry for having annoyed you with that 😣

20milliliter commented 1 year ago

Unifont is designed for size 16.

@Calinou How do you know? Why does other software disagree with you?

image image

Calinou commented 1 year ago

12 pt is different from 16px :)

Different software uses different coventions for font sizes, so it's best to try different font sizes until you find one that looks "right".

20milliliter commented 1 year ago

Different software uses different coventions for font sizes

TIL. Very unintuitive. @Calinou Mention of this should also be included in your PR, I feel.

Calinou commented 1 year ago

@Calinou Mention of this should also be included in your PR, I feel.

Done: https://github.com/godotengine/godot-docs/pull/7389

20milliliter commented 1 year ago

Great, thanks so much.