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

Distance field fonts are blurry #8022

Closed
Zylann opened this issue Mar 13, 2017 · 28 comments
Closed

Distance field fonts are blurry #8022

Zylann opened this issue Mar 13, 2017 · 28 comments

Comments

@Zylann
Copy link
Contributor

Zylann commented Mar 13, 2017

Tested on Godot 2.1.2
Windows 10 64 bits

I created a theme with a custom font, and it looks fine with Labels. However, every other control gets blurry text instead. I expected the same result as the label, because I see the text appears to be the same size.

image

ItemListFontBlurry.zip

Related QA thread I investigated from: https://godotengine.org/qa/13127/itemlist-font-is-scaled-and-blurry

@eon-s
Copy link
Contributor

eon-s commented Mar 14, 2017

Seems to affect just distance field fonts, by the way.

@Laseph
Copy link

Laseph commented Mar 17, 2017

I've had the same problem. I've looked through the code and although I'm not a programming expert at all, I found this piece of code that can only be found in the label.cpp. This is probably why it doesn't render correctly. Edit: I meant by that why it doesn't render correctly for the rest of the text based nodes
VisualServer::get_singleton()->canvas_item_set_distance_field_mode(get_canvas_item(), font.is_valid() && font->is_distance_field_hint());

@Zylann
Copy link
Contributor Author

Zylann commented Mar 18, 2017

Well, maybe it's why only the label renders correctly, in fact^^

@kubecz3k
Copy link
Contributor

First of all thank you for your report and sorry for the delay.

We released Godot 3.0 in January 2018 after 18 months of work, fixing many old issues either directly, or by obsoleting/replacing the features they were referring to.

We still have hundreds of issues whose relevance/reproducibility needs to be checked against the current stable version, and that's where you can help us.
Could you check if the issue that you described initially is still relevant/reproducible in Godot 3.0 or any newer version, and comment about its current status here?

For bug reports, please also make sure that the issue contains detailed steps to reproduce the bug and, if possible, a zipped project that can be used to reproduce it right away. This greatly speeds up debugging and bugfixing tasks for our contributors.

Our Bugsquad will review this issue more in-depth in 15 days, and potentially close it if its relevance could not be confirmed.

Thanks in advance.

Note: This message is being copy-pasted to many "stale" issues (90+ days without activity). It might happen that it is not meaningful for this specific issue or appears oblivious of the issue's context, if so please comment to notify the Bugsquad about it.

@eon-s
Copy link
Contributor

eon-s commented Apr 10, 2018

Is there a way to create distance field fonts? It do not seem possible on godot 3.

@Zylann
Copy link
Contributor Author

Zylann commented Apr 10, 2018

Just try to import the same font as in the example project?

@eon-s
Copy link
Contributor

eon-s commented Apr 10, 2018

No, that font is not recognized as a resource.

@Zylann
Copy link
Contributor Author

Zylann commented Apr 10, 2018

Argh I need to find the original, I believe that one was imported with 2.x

@Zylann
Copy link
Contributor Author

Zylann commented Apr 10, 2018

Importing that font in 3.0.2 works:

image

@kubecz3k kubecz3k added this to the 3.0 milestone Apr 10, 2018
@eon-s
Copy link
Contributor

eon-s commented Apr 10, 2018

@Zylann how do you managed to import it? (and as .tres)

@Zylann
Copy link
Contributor Author

Zylann commented Apr 10, 2018

@eon-s the original is a TTF, I created a DynamicFont from it. I'm not sure why distance field was a thing in the first place in this issue (the FNT file was a result of Godot 2 import).

@eon-s
Copy link
Contributor

eon-s commented Apr 10, 2018

Oh, I was able to replicate only with that font, I will see if I can get one and try again later

@eon-s
Copy link
Contributor

eon-s commented Apr 11, 2018

This issue is not solved, still valid for distance field fonts,

Example using the font on the SDF demo.
ItemFontBlurryV3.zip

@akien-mga akien-mga reopened this Apr 11, 2018
@akien-mga akien-mga changed the title All GUI text is blurry except for labels Distance field fonds are blurry Apr 11, 2018
@akien-mga akien-mga changed the title Distance field fonds are blurry Distance field fonts are blurry Apr 11, 2018
@kubecz3k kubecz3k modified the milestones: 3.0, 3.1 Apr 11, 2018
@reduz
Copy link
Member

reduz commented Jul 30, 2018

Distance field fonts have not really been properly re-added yet, so this gets kicked to 3.2

@reduz reduz modified the milestones: 3.1, 3.2 Jul 30, 2018
@Zylann
Copy link
Contributor Author

Zylann commented Nov 4, 2018

Bumped again into this after upgrading my game from Godot 2 (where it worked) to Godot 3.0.6 (no longer works), still with the same font.
It should be noted that the difference is not like the first example I posted, and what I thought was working actually isn't. See this comparison:

(Click to see full size)
image

If having to wait for 3.2, that means... quite a long time, since it's the version we plan to have Vulkan in^^" I'd expect such a fix to be in a 3.1 maintainance release instead. Meanwhile... no pixel fonts...

@KoBeWi
Copy link
Member

KoBeWi commented Oct 22, 2020

Still valid in 3.2.3
In 32be929 the font isn't even loaded.

@Calinou
Copy link
Member

Calinou commented Oct 25, 2021

This is fixed by the new MSDF font rendering implementation in master. This is unlikely to be fixed in 3.x though, unless a motivated contributor finds a solution.

@Calinou Calinou modified the milestones: 4.0, 3.5 Oct 25, 2021
@ghost
Copy link

ghost commented Dec 10, 2021

I fixed this in my custom build. Took me about 1 day. Works perfectly for GLES2 and GLES3 just like it did in Godot 2 but was only implemented for specific (non advanced) buttons and in the editor the Theme plugin always shows blurry still. This feature was never properly implemented in 3 and over the years it kinda got moved around bits and pieces everywhere and some lines completely gone. I had put all the pieces back together or completely re-implement some things. I guess I'm 5 years too late nobody really cares about this feature anymore but here it is working in Godot 3.x latest.
image

@Zireael07
Copy link
Contributor

@filipworksdev Can you make a PR?

@ghost
Copy link

ghost commented Dec 10, 2021

Hi @Zireael07 I can try but can't guarantee I'll be approved. Is only implemented for some controls. I skipped all the advanced stuff because I don't think they were meant to work with bitmap fonts like a TextEditor for ex. Works in game though for the specific implement controls. The main issue is I could not make it work for the new Theme Editor Plugin preview. It only works when you do a popup but not in the actual theme. The new Theme Editor needs more work from someone that knows it better . I tried but couldn't figure it out.
image .

@Zireael07
Copy link
Contributor

I can't guarantee it will be approved either, but as it is a bugfix chances are it will and/or someone will take a look at the other places that need the fix, like the Theme Editor you mentioned,

@Calinou
Copy link
Member

Calinou commented Jan 20, 2022

@filipworksdev If you don't have time to finish this work, could you push your work to a branch so others can improve it and open a pull request based on it? Thanks in advance 🙂

@ghost
Copy link

ghost commented Jan 20, 2022

@Calinou Sorry! I did push it to a branch but is using my custom build of Godot for educational purpose where I am doing more core changes and more basic work to learn C++.

This is the commit with all the changes. Is compatible with 3.x branch goblinengine/goblin@66c4f2f

It works but has a number of issues which need to be addressed:

It causes some blurry effects on some controls . The signed field was not ported correctly and then for years the controls were modified without signed field in mind so now adding these back I realize the style rects are drawn in a way that conflicts with how signed field work.

I have also adjusted signed field shader to be slightly less sharp to avoid it looking blurry when zoomed all the way out or on lower rez (retro-style) viewports.

Signed field needs to be manually flagged for each control font in order to make it work . In Godot 2 only label used this while all other controls would automatically turn on Signed Field when the font was marked as such and this happened when Canvas item was rendered. Now because of batching that way of rendering cannot happen and cannot individually turn on/off signed field shader for those specific fonts. Each control would have to use something like this VisualServer::get_singleton()->canvas_item_set_distance_field_mode(get_canvas_item(), font.is_valid() && font->is_distance_field_hint()); on the control font to enable it. This marks the specific canvas item font to render with signed distance field shader via the VisualServer. This can in fact be done from GDScript , however, the signed field canvas shader was incorrectly written for GLES 3 and was completely missing in GLES2 canvas shader.

My code will not work inside theme preview either. I wasn't able to figure out how to make it with the newly reworked theme preview. It just looks blurry. I think is because the theme preview panel uses custom rendering and doesn't enable signed distance fields on any of the fonts.

Also signed filed is not enabled for more complex controls like for example TextEditor. It doesn't seem like it was designed with simple fonts in mind.

So I got a bit ahead of myself. After further testing works well but not perfectly 😄

@Calinou Calinou modified the milestones: 3.5, 3.x May 19, 2022
@Calinou
Copy link
Member

Calinou commented May 20, 2022

I ported filipworksdev's changes above to a branch based on 3.x: https://github.com/Calinou/godot/tree/fix-sdf-font-rendering-3.x

Right now, it's working correctly, but only when batching is disabled. I changed the rendering formula in the shader to further improve the sharpness/antialiasing quality balance as well.

Improvements to rendering quality could be made by adjusting SDF smoothing depending on font size (relative to screen size) or performing supersampling. However, the screen_pixel_size uniform is only available when SCREEN_UV is used in the shader, and I need that to adjust SDF smoothing based on resolution.

Testing project: https://0x0.st/oaBt.zip (link expires in April 2023)

1024×600

2022-05-20_02 41 32

2560×1440

2022-05-20_02 41 36

@eon-s
Copy link
Contributor

eon-s commented May 20, 2022

It would be great if this could land on 3.5, even as experimental because is a huge improvement.

@filipworksdev
Copy link

Thanks @Calinou ! Looks great. Sorry it says Ghost above I'm still here I had some issues with my old account so I ported everything to a new account same usename and same repots. Still here :) Did you manage to fix the theme preview and I think there are also batching issues.

@akien-mga
Copy link
Member

Thanks!

@Calinou
Copy link
Member

Calinou commented Feb 7, 2024

Fixed by #86786.

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