-
-
Notifications
You must be signed in to change notification settings - Fork 21k
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
Add multi-channel SDF font generation and rendering support. #44772
Conversation
This looks great! I noticed the MSDF becomes quite "thin" at lower zoom values. Is it possible to force using a minimal amount of sharpness/width for the MSDF font at the cost of worse antialiasing? This would help keep the font more readable at lower font sizes. |
Probably, I have not tested any SDF generation parameters yet, and used the default shader with AA as is. |
I wonder how this approach compares? https://github.com/hypernewbie/VEFontCache |
10b8f35
to
bf4172f
Compare
1501e6e
to
0d7b68e
Compare
Is this for the master branch or 3.2? |
This is for the |
Update: Contour orientation detection and alignment issues are fixed, self intersection elimination is still desired, but rare and usually cause only small artifacts, probably can be omitted for now. Seems to work fine with all fonts I have tested. Stuff still missing (help needed):
Other stuff:
|
ea54d75
to
8cb39eb
Compare
Also, exposed M(T)SDF drawing function to the canvas item for custom textures ( Image taken from https://github.com/V-Sekai/godot-msdf-project/ ( |
msdfgen seems to have issues with sharp internal angles, usually resulting artifacts are small and barely noticeable. Unfortunately outlines generated by FreeType glyph stroker have tons of internal angles (in addition of common self-intersections) and the resulting distance field is total mess. Small artifacts on the normal glyph (zoomed in to 3500%): On the other hand, simply applying radial blur to the "true distance" component of M(T)SDF seems to have almost the same effect. Probably it's more than enough for all real use cases of the outline. MSDF font on the top buttons, dynamic font on bottom buttons, scaled to: 25%, 50%, 75%, 100%, 200% and 500%. |
9cf0244
to
92991c8
Compare
I have changed outline rendering from "blur" to using max value in range, now MSDF font outlines look the same as dynamic font outlines at all sizes (right now MSDF font outline texture size is limited to 3 x glyph size, which should be more than enough for any real use case). Also, added API for individual font oversampling override (which was used to disable oversampling for MSDF fonts). Everything seems to be working as expected. I'll do a bit more testing and performance profiling, and it should be ready to go. |
d22eba4
to
dda9391
Compare
c27efcc
to
c049eac
Compare
e428d53
to
110c75a
Compare
c8f1b02
to
8a1b707
Compare
343e077
to
7aac252
Compare
So far this looks good to me for the most part. I really dislike a custom binary format, though. Can we use regular resource serializing here? |
Add multi-channel + true SDF font texture generation and rendering support. Add FontData import plugin, font texture cache pre-generation and loading, move font properties from resource to imported cache. Add bitmap font generation support.
…to distance fields.
There may be some bug fixes for corner bugs. See https://github.com/Chlumsky/msdfgen/releases/tag/v1.9.1 |
Superseded by #51908 |
Support for M(T)SDF font rendering. Font texture is generated using https://github.com/Chlumsky/msdfgen.
Zoom video
Screen.Recording.2021-03-02.at.10.34.08.mov
Logos on background are rendered from 128x128 custom MSDF image.
.fontdata
(and set of textures) which store all its properties (see file description below). It's still possible to load any of.ttf
/.otf
/.font
/.fnt
files directly.Import options:
antialiased
- ignored for MSDF and bitmap fonts, if selected uses 8-bit greyscale rendering, otherwise uses 1-bit rendering.force_autohinter
- if selected prefers FreeType autohinter over font built-in hinter.msdf
- enables MSDF generation for dynamic fonts (or indicates that source is MSDF for bitmap fonts). MSDF generation is slow, but allows to use same texture for all fonts sizes, with almost no extra rendering cost.msdf_px_range
- MSDF pixel range (range around the shape between the minimum and maximum representable distance).oversampling
- font oversampling factor, ignored for MSDF and bitmap, if set to 0 global value is used.hintinhg
- ignored for bitmap fonts.base_variation
- default font size and variation, comma separated list of "size", "outline_size" or OpenType variation tags.convert_to_bitmap
- ignored for bitmap fonts, removes dynamic font source file form import (disables OpenType features, and limits font to pre-rendered glyphs only).extra_spacing_*
- extra spacing for glyphs and spaces.preload\ranges
- list of character ranges to preload in'A'-'Z'
,U+0000-U+0000
or0x0000-0x0000
format, or glyph ranges inG+0000-G+0000
format.support_overrides
- list of overrides of language and scripts, can be used to increase or decrease font fallback usage priority for specific language or script.Supported import variants:
TrueType / OpenType source -> pre-renders glyphs and outlines for each size, original font file is preserved in cache and used for OpenType features, shaping and rendering missing glyphs.
TrueType / OpenType source +
msdf
selected -> Same as above but pre-renders glyphs as MSDF for one size only. Outlines are generated from the same MSDF. Generating MSDF require outline and will not work with bitmap fonts (e.g. emoji fonts).TrueType / OpenType source +
convert_to_bitmap
selected -> Same as above, removes original font file from cache (font have no OpenType features and limited to pre-rendered glyphs only).AngelCode bitmap font -> font is copied to cache as is (
msdf
flag should be set manually, if source image is MSDF or M(T)SDF).".fontdata" file format:
Bugsquad edit: This closes godotengine/godot-proposals#2021 and #28045 (by implementing per-font oversampling override).