Search Unity

TextMesh Pro Upgrade from 2019 to 2020 gives font strange rect padding problem

Discussion in 'UGUI & TextMesh Pro' started by orreborre, Dec 5, 2020.

  1. orreborre

    orreborre

    Joined:
    Feb 18, 2014
    Posts:
    21
    Hello!

    When I upgrade my project to Unity 2020, I get this strange behaviour on my TMP font.
    It's a bitmap font. The glyph rects still look fine in the font asset.
    This happen do anybody else?

    Unity 2019.3.10f1, TMP 2.0.1
    upload_2020-12-5_22-48-19.png

    Unity 2020.1.9f1, TMP 3.0.3
    upload_2020-12-5_22-42-10.png

    Thanks for reading
     
  2. Stephan_B

    Stephan_B

    Joined:
    Feb 26, 2017
    Posts:
    6,595
    Do you have Extra Padding enabled in the Extra Setting section of the text component inspector? In the top image, the geometry is tight fitted whereas in the bottom it looks like Extra Padding is on.

    This property expands the geometry of each character quad where if your padding value on the font asset is smaller than the extra padding added, you will end up with parts of the adjacent glyphs showing as your image appears to show.

    Can you post an image showing your font asset settings? Specifically how much padding you have?
     
  3. orreborre

    orreborre

    Joined:
    Feb 18, 2014
    Posts:
    21
    Hey, thanks for replying!

    I don't have extra padding set
    Here are the text component settings:
    upload_2020-12-6_14-48-3.png

    And the font asset settings:
    upload_2020-12-6_14-50-16.png

    Some of the glyph settings:
    upload_2020-12-6_14-51-17.png

    upload_2020-12-6_14-51-46.png

    If I change the glyph rect from 5x8 to 3x6 I can make it look correct but it doesn't feel right looking at the glyph preview :p (also added spaces in text so the 8 can be seen more clearly)
    upload_2020-12-6_15-0-15.png
     
    Last edited: Dec 6, 2020
  4. Stephan_B

    Stephan_B

    Joined:
    Feb 26, 2017
    Posts:
    6,595
    Is this a new font asset or one that you previously created in the older version of TMP?

    I believe the padding around glyphs was slightly increased in the latest release to prevent clipping but since your font asset has zero padding, this is likely the cause of the issue.

    Can you provide me this font asset for testing?
     
  5. orreborre

    orreborre

    Joined:
    Feb 18, 2014
    Posts:
    21
    It's been some time, but if I remember correctly it's a copy of the old LiberationSans default asset that I've manually edited the _typelessdata of, that would explain why most characters are not displayed correctly(since I just use the numbers mostly).

    Here's the current asset anyway. Sorry for the terrible naming. I will try and see if I can make something out of a freshly imported asset from the package.
     

    Attached Files:

  6. orreborre

    orreborre

    Joined:
    Feb 18, 2014
    Posts:
    21
    So I started fresh with a new copy of LiberationSans SDF, however I ended up with the same result in the end.
    Since the font is a custom bitmap font I edit the asset file and replace the pixeldata with a 64x64px data and strip glyph data that isn't included. I just don't understand where the extra 1px padding comes from; I made sure all padding is set to 0. I will use a workaround-version of the font for now where all characters have reduced width and height by 2.
     
  7. Stephan_B

    Stephan_B

    Joined:
    Feb 26, 2017
    Posts:
    6,595
    The issue is due to the lack of padding where if the geometry of each character is slightly larger (which it is slightly to prevent clipping and even larger with Extra Padding enabled) then you get to see a piece of the adjacent glyph.

    The solution is to add some padding between glyphs. Add a small padding value of like 5% to 10% of the sampling point size.
     
  8. orreborre

    orreborre

    Joined:
    Feb 18, 2014
    Posts:
    21
    I suppose I could add a pixel between all my glyphs in the texture, but then I would in this case have to increase the texture size, since the glyphs are really tightly packed in my 64x64px texture.
    However, I wouldn't call it a solution - it's a workaround.
    The issue for me here is that if I define a glyph to be 8x5 pixels, Unity seems to make it 10x7 even though padding is set to 0. Defining the 8x5 glyph as being 6x3 pixels is another workaround that seems to work, but it causes the glyph preview to look wrong but it looks correct in the scene.

    I did some looking around in the TMP package, and found that in TMPro_ShaderUtilities.cs there is a function called GetPadding() that in version 1.3.0 has a return like so:
    Code (CSharp):
    1. return extraPadding;
    But looking at the same place in version 3.0.3 looks like this:
    Code (CSharp):
    1. return extraPadding + 1.0f;
    If I remove the + 1.0f and go back to Unity the font looks correct. I believe that this is the change that broke my font.
     
  9. orreborre

    orreborre

    Joined:
    Feb 18, 2014
    Posts:
    21
    @Stephan_B any input on my last post? :) That +1.0f seems strange, since it seems to me it means that even if padding is set to 0 it will be 1 no matter what. Which is exactly what I'm experiencing.

    Why was the +1.0f added? Shouldn't the padding be 0 if set to 0?

    Oh, and it seems TMPro_ShaderUtilities.cs was renamed to TMP_ShaderUtilities.cs, forgot to include in my that last post.
     
  10. Stephan_B

    Stephan_B

    Joined:
    Feb 26, 2017
    Posts:
    6,595
    This additional padding was added to prevent clipping when the text gets small but it would most certainly cause an issue when there is no padding between glyphs in the texture.

    I will consider reverting this change.
     
  11. orreborre

    orreborre

    Joined:
    Feb 18, 2014
    Posts:
    21
    If you were to keep the +1.0f change I suggest you also add the +1 padding to the glyph previews so that they resemble what they will look like. Screenshot to show what I mean:
    upload_2021-1-8_10-6-54.png
    I ended up shrinking all my glyph rects with 2 pixels in height and width.
    Thanks for answering!