Search Unity

  1. Looking for a job or to hire someone for a project? Check out the re-opened job forums.
    Dismiss Notice
  2. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    Dismiss Notice

TextMesh Pro Artifacting in Text Mesh Pro even after fixing SP/Padding ratio

Discussion in 'UGUI & TextMesh Pro' started by AlliBee, Mar 24, 2021.

  1. AlliBee

    AlliBee

    Joined:
    Sep 9, 2020
    Posts:
    8
    Hi everyone!
    I'm doing a mass change of fonts in our project, and when I changed to our new font (it's a much thicker font than the original), I see these artifacts (low alpha boxes) in editor (play mode). The smaller the font, the worse the artifacting is. This is a picture before any of my attempts to fix:

    upload_2021-3-25_10-33-1.png

    More details:
    • I'm in unity 2020.1.17f1
    • Orthographic camera (2d project)
    • I'm using a font with the "bold" setting turned on. The "bold" setting is another TMP file.
    • I have 30+ materials for the font. These materials apply to the regular font and the bold font, since the bold setting is nested into the font.
    I've already tried:
    • Changing the sample point/padding ratio to 10% and then to 20% (90 x 9, and 90 x 18). This got rid of the random lines that were appearing, but the "alpha background" remains. In fact, the more I increased the ratio, the darker the box got.
    • Adjusting the "bold" weight down, as another thread suggested. This didn't do anything.
    • Changing the settings on my materials from "1" to bellow 0.75, this also didn't do anything.
    Running out of ideas here, thoughts?
    Thanks!
     
    Last edited: Mar 25, 2021
  2. Stephan_B

    Stephan_B

    Unity Technologies

    Joined:
    Feb 26, 2017
    Posts:
    5,660
    Can you provide me with a simple scene / project containing one of those font assets and material to take a closer look?

    What version of the TMP package are you using?
     
  3. AlliBee

    AlliBee

    Joined:
    Sep 9, 2020
    Posts:
    8
    Hey Stephan! Thanks for the reply!
    So, I actually undid all my changes to my branch, started over and re-imported my fonts (saving over my existing TMP and existing materials). This time, it did get rid of the boxes.
    However, this is what my fonts look like now:

    upload_2021-3-24_15-24-53.png

    The original TMP file and materials had a different ratio than the new ones, so I was expecting something odd to happen.
    But the bizarre thing is: everything is working correctly, despite it all looking like this ^
    Is there any way to have materials/atlas displaying correctly? or do I need to delete everyone, reimport the font from scratch and recreate my materials?
    And, if I do that, will all my references be lost? Or as long as I rename the materials the same thing, TMP will recognize them?
     
  4. Stephan_B

    Stephan_B

    Unity Technologies

    Joined:
    Feb 26, 2017
    Posts:
    5,660
    Can you provide me (using the export options in the context menu) with this font asset and a few of those materials to look at?
     
  5. AlliBee

    AlliBee

    Joined:
    Sep 9, 2020
    Posts:
    8
    Let me know if this is what you meant?
     

    Attached Files:

  6. Stephan_B

    Stephan_B

    Unity Technologies

    Joined:
    Feb 26, 2017
    Posts:
    5,660
    Just had a chance to look at the font assets you provided.

    The MSB font asset doesn't contain any characters or glyphs so not sure if that was an export issue or the actual state of the font asset in your project.

    The MSBL font asset does contain characters and glyph so it appears to be fine. However, given this font asset is assigned as the bold font weight to the MSB font asset, we'll need to fix the MSB.

    I am not sure if the MSB font asset contained the same characters and glyphs as MSBL. Assuming it did, it is pretty simple to regenerate this font asset. It also appears the material presets still reference the empty atlas texture of the MSB font asset where updating the font asset should update these presets as well.

    To regenerate the MSB font asset, I simply used the Font Asset Creator using the MSBL as reference to include the same characters and glyphs.

    upload_2021-3-25_23-45-9.png

    I used SDF16 but noticed that your MSB was using SDF and the MSBL using SDFAA. Not sure what was the original sampling mode of these original font assets. Do you have a backup of these?

    After the regeneration, the material presets maintained their reference to the parent font asset atlas texture.

    upload_2021-3-25_23-52-9.png

    I noticed that your material presets are using maximum values on many of the material properties which is likely what was leading to the issue you initially posted about. Basically anytime these material property values are near 1, you are essentially at the edge of the adjacent glyph in the atlas texture. At certain zoom factor and due to bilinear filtering, you will get that ghosting / visual artifact in your screenshot.

    The Sampling Point Size to Padding ratio determines the effective range of material properties. For example, if the Underlay Offset X value is 1 (max) at a 10% ratio, increasing that ratio to 20% would double the distance / effective range of that shadow. However, in both cases you are still at max value of 1 where this visual artifact can occur.

    The idea behind increasing this ratio is so that you can use smaller material property values to achieve the same visual look while using smaller material property values thus keep you well inside the padding between each glyph in the atlas texture.

    Whenever you create a font asset and end up using material property values near their maximum, it is a sign that your sampling point size to padding ratio is too small as you are pushing everything to the maximum.

    Here is an example of the same font and material with 10% vs. 20% ratio with the same values.

    upload_2021-3-26_0-13-45.png

    Notices how the outline thickness is 2X with double the ratio.

    Since I am not sure what your original sampling point size and padding were on these font asset prior to the upgrade as well as what Atlas Render Mode you were using, I would suggest going back to a backup to verify this information.

    Since the issue you initially reported appears to have been caused by using material property values at their max range, either decreasing these values or assuming you want to preserve the same visual appearance then increasing the ratio of sampling point size to padding from something like 10% to 15% for example would enable you to reduce these material property values to maintain the same visual appearance while staying without getting to the edge of the adjacent glyph in the texture.

    P.S. When using fallback font assets, you want to keep the same sampling point size to padding ratio in order to maintain the same visual appearance at the same material property values. Although the sampling point size and padding can change, as long as the ratio is the same that outline thickness for example will appear the same between those font assets.

    Hopefully, this gives you enough information to update your font assets and resolve this issue. Keep me posted please.
     
  7. AlliBee

    AlliBee

    Joined:
    Sep 9, 2020
    Posts:
    8
    Thank you so much for such a detailed response! This makes a lot of sense to me!
    I am not sure what the SDF16/SDF/SDFAA settings are or do, I just saw in another thread that cycling through them might get rid of the artifacts (which, might have been the case for me, I don't know). But sounds like I should use the same one for MSB and MSBL?
    Is there a link where I can learn what they are so I can pick the correct one for my project?

    I think I can look back to my commits and see what my original ratio was -- I'm not sure because it was automatic. So I'm not sure what the automatic one is, I only did it manually when I realized that was how I could fix the artifacting.

    Thanks again!
     
  8. Stephan_B

    Stephan_B

    Unity Technologies

    Joined:
    Feb 26, 2017
    Posts:
    5,660
    These represent the different Signed Distance Field modes which are as follows:

    Render Mode
    Specify the render mode used when rendering the glyphs in the font atlas texture.

    Bitmap Modes
    1. SMOOTH Renders the atlas to an antialiased bitmap.

    2. RASTER Renders the atlas to a non-antialiased bitmap.

    3. SMOOTH_HINTED Renders the atlas to an antialiased bitmap, and aligns character pixels with texture pixels for a crisper result.

    4. RASTER_HINTED Renders the atlas to a non-antialiased bitmap and aligns character pixels with texture pixels for a crisper result.

    Signed Distance Fields Modes
    1. SDF Renders the atlas using a slower, but more accurate SDF generation mode, and no oversampling.

    2. SDF8 Renders the atlas using a slower, but more accurate SDF generation mode, and 8x oversampling. Ideal for static font assets.

    3. SDF16 Renders the atlas using a slower, but more accurate SDF generation mode, and 16x oversampling. Ideal for static font assets.

    4. SDF32 Renders the atlas using a slower, but more accurate SDF generation mode, and 32x oversampling. Use this setting for fonts with complex or small characters. Ideal for static font assets.

    5. SDFAA Renders the atlas using a faster, but less accurate SDF generation mode. Best suited for dynamic font assets.

    6. SDFAA_HINTED Renders the atlas using a faster, but less accurate SDF generation mode, and aligns character pixels with texture pixels for a crisper result.. Best suited for dynamic font assets.

    NOTE: The SDFAA modes are less accurate but significantly faster than over sampled SDF modes like SDF16 and SDF32.

    Although the SDFAA modes are less accurate and visible in the Editor when zoomed in on the text, this is not visible in the game view unless the text is larger than 90 point size as at lower point size, there is not enough pixels to represents those inaccuracies. This would most likely only impact text like Titles.

    It is recommended to use the same mode for all font assets although it is ok for static font assets to use one of the oversampled modes. Dynamic font assets should always use SDFAA or SDFAA Hinted although I recommend SDFAA.
     
  9. AlliBee

    AlliBee

    Joined:
    Sep 9, 2020
    Posts:
    8
    Thank you so much for all the info! I'm going to be redoing the fonts and updating the materials with new settings!
     
unityunity