Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

TextMeshPro atlas generation quality

Discussion in 'UGUI & TextMesh Pro' started by Vedran_M, Jun 18, 2020.

  1. Vedran_M

    Vedran_M

    Joined:
    Dec 16, 2019
    Posts:
    14
    Would it be possible to have setting for atlas generation quality?

    I've created and used SDF font systems for many years now, and I know that when we generated SDF atlases with out own software, or with libgdx's Hiero, we had an option for how much we want to scale original glyph bitmap before SDF calculations would reduce it to small SDF bitmap.
    For relatively fast font generation, we used x4 or x8 scaling, and that would generate atlas in a few seconds.
    But for production we used x128 or even x256 scale, and that would take about 1-2 hours to generate the atlas.

    We did it because quality of SDF glyphs created from x128 or x256 bitmap would be noticeably better than that created from x4 or x16 or x32 or even x64.

    So what I'm asking, would it be possible to expose option for how much does TextMeshPro scale up the glyphs when doing SDF calculation? That way we could create a really high quality production fonts.
    We would really appreciate it!
     
  2. Stephan_B

    Stephan_B

    Unity Technologies

    Joined:
    Feb 26, 2017
    Posts:
    6,588
    The Sampling Point Size determines the baseline for the Glyph sampling. So if the Sampling Point Size is 32 vs 64 vs 128, you will see a big difference.

    The SDF, SDF8, SDF16 and SDF32 are over sample modes which are a multipliers on those values.

    In terms of sampling quality difference between let's say Sampling Point Size of 72 using SDF16 or SDF32, there is very little difference as you are already sampling these glyphs at 72 X 16 or 1152 point size. Given the results are stores in an 8 bit alpha texture or 8 bit precision, you are already pretty much at the precision limit where even if we added a x64, x128 or x256 mode, I don't think it would produce any real improvements.

    Having said that and for the sake of technical due diligence, I will revisit this testing specifically lower sampling point size like 32 with x64, x128 and x256 to see if we get any measurable visual differences.

    P.S. We are working on adding support for the FontEngine to compute SDF from curve data directly with 32bit precision which will provide better result without having to oversample. No ETA on this but it will be coming.
     
    MNNoxMortem and Vedran_M like this.
  3. Vedran_M

    Vedran_M

    Joined:
    Dec 16, 2019
    Posts:
    14
    Thank you for the detailed answer Stephan!

    For previous projects where we used Hiero or our own SDF atlas generator, we used 32x32 point size for all the glyphs. Most noticeable difference in quality was with complex Chinese and Japanese glyphs, with those we could notice difference between x32, x64 and x128 scaling. And you are right, x256 scaling did not improve on x128.

    Out of current settings, which would have the best quality? SDFAA or SDF32?

    Glad to hear about new method to compute SDF in progress! I really like TextMeshPro and I'm glad it is continuing to develop further with new algorithms.
    And thank you again for all your effort.
     
  4. Stephan_B

    Stephan_B

    Unity Technologies

    Joined:
    Feb 26, 2017
    Posts:
    6,588
    SDFAA is less accurate but very fast and suited for dynamic runtime use whereas SDF16 and SDF32 are more accurate but way too slow for dynamic use.

    In terms of quality difference, unless the text will be displayed on screen at a point size larger than 72 points (taking scaling into consideration), there are not enough pixels to really see the difference.

    It is important to realize that while you can zoom into the text in the Editor and see the difference, you have to look at it in the game view and the actual rendered size. Most of the time, the difference between these modes on text of average point size used in projects is negligible and very subjective.

    Typical sampling point size for Latin base glyphs using SDFAA is about 72 to 96 point size whereas for East Asian glyphs, you can get away with 36 to 48. This is obviously affected by the font itself but with typical fonts of normal design that is the case.
     
    MNNoxMortem and Vedran_M like this.