Search Unity

  1. Unity 2019.1 is now released.
    Dismiss Notice

TextMesh Pro Cut off and misplaced glyphs in static font assets with SDF/8/16/32

Discussion in 'Unity UI (uGUI) & TextMesh Pro' started by osmoticstudios, May 15, 2019.

  1. osmoticstudios

    osmoticstudios

    Joined:
    Aug 19, 2014
    Posts:
    2
    We have an issue that surfaced after we upgraded to TMP 1.4.0 and rebuilt all our font assets in preperation of localization for our game. I've so far been unable to pinpoint what's wrong and I hope you can help me.

    Here's what's happening:
    Glyphs of some fonts get cut off at the sides or the glyph rectangle appears to be misplaced otherwise (i.e. too much whitespace around the actual glyph). This results in both cut-off characters and text that seems to move up and down between characters.

    Example:
    I've prepared an example where it is most apparant, using the Ubuntu font (Ubuntu Light in this case). Here is what the 'S' glyph and corresponding text look like when rendered with the following settings:

    Ubuntu Light -> Static (Extended ASCII), Point Size 50, Padding 5, Atlas 512*512, SDF16:
    settings_static_sdf16.png
    static_sdf16.png
    Note how the 'S' right side is cut off and the characters in the text seem to move up and down, not being placed on the same baseline.

    However, these are the corresponding results using the exact same settings, but switching the asset to dynamic:

    Ubuntu Light -> Dynamic, Point Size 50, Padding 5, Atlas 512*512, SDF16:
    settings_dynamic_sdf16.png dynamic_sdf16.png
    Not only does the issue disappear, also note the difference in glyph rect width/height and glyph metrics. Unfortunately, we need to build static atlases rather than using dynamic ones, so switching to dynamic is not a possible workaround.

    The issue remains observable regardless of atlas size, point size, padding, and across all SDF/8/16/32 render modes and affects many other fonts as well. Interestingly, SDFAA (both hinted and non-hinted) looks fine. Since we used SDF16 throughout our project before we'd like to maintain that render mode so our fonts keep the same visually.

    If you have any idea what may be going wrong here, your help would be much appreciated. Thanks!
     
  2. Stephan_B

    Stephan_B

    Unity Technologies

    Joined:
    Feb 26, 2017
    Posts:
    2,641
    Just to make sure I understand correctly.

    Newly created font assets using SDF16 (with similar settings as above) appear incorrectly positioned?

    I'll take a look tomorrow and provide feedback shortly thereafter.

    Update
    Decided to quickly test this before going to sleep.

    upload_2019-5-15_3-30-56.png

    Top is SDF16 and bottom SDFAA. 50 Sampling point size with padding of 5.

    Glyph metrics are identical (besides their position in the atlas).

    I am seeing the cut-off. Using Extra Padding in the Extra Settings will get around this but this is something I need to look at.

    upload_2019-5-15_3-34-41.png

    I'll look at it more closely tomorrow...
     
    Last edited: May 15, 2019
  3. osmoticstudios

    osmoticstudios

    Joined:
    Aug 19, 2014
    Posts:
    2
    Thanks for the fast answer! Yes, this occurs with all new font assets and updated atlases created with any SD16 (or basically any SDF among 8/16/32). To exclude that this is somehow caused by our game, I created a new project from scratch.

    With a font asset created in TMP 1.3.0 with SDF16, the text looks like this:

    tmp_130.png

    Then I updated TMP to 1.4.1 and re-built the font atlas of the asset with the same settings. Afterward it looked like this:

    tmp_141.png

    The characters have slightly moved up and down, though it's not too noticable here. But the 'S' is clearly cut off and the same thing happens e.g. to the '.' glyph.

    To highlight the vertical displacement issue I tried the same thing with the font "Vollkorn Regular":

    In TMP 1.3.0:

    vollkorn_130.png

    In TMP 1.4.1:

    vollkorn_141.png
     
  4. Stephan_B

    Stephan_B

    Unity Technologies

    Joined:
    Feb 26, 2017
    Posts:
    2,641
    I can definitely see the issue with the legacy SDF modes (SDF16 and SDF32).

    Until I resolve that, I would suggest using the SDFAA mode which still allows you to create static font assets. From a visual standpoint and at moderate on screen point sizes (anything smaller than 72+), you should not be able to see any difference.

    I will be looking into this later today but suspect the required changes will be in the FontEngine which is part of the Unity Editor / Engine. Ie. not just a new TMP package.
     
  5. Stephan_B

    Stephan_B

    Unity Technologies

    Joined:
    Feb 26, 2017
    Posts:
    2,641
    Here is an image showing SDF (no up-upsampling) vs. SDFAA Hinted. As you can see their metrics are identical and the positioning correct.

    upload_2019-5-15_14-12-58.png

    The shift occurs due to the up-sampling on SDF8 / SDF16 / SDF32 whereas the SDFAA modes do not up sample and are correct out of the gate.