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

Question How can I make pixel-perfect font rendering in Unity?

Discussion in 'UGUI & TextMesh Pro' started by wechat_os_Qy0z3kA7rbaDKIfRpwm8-4bhw, Jun 26, 2023.

  1. wechat_os_Qy0z3kA7rbaDKIfRpwm8-4bhw

    wechat_os_Qy0z3kA7rbaDKIfRpwm8-4bhw

    Joined:
    May 4, 2021
    Posts:
    3
    I'm trying to make unifont work for me, like which in Minecraft with force unicode font on, but I can't get every pixel in my text to have the same size on screen. It seems that the size every pixel in my font is non-integer numbers of pixel on my screen, and I can't find a way to reliably scale the font to have the intended look.




    • What I'm doing and what I've get, I tried to change canvas scaling, font size, font scaling, and font sample size, and I also tried using pixel perfect camera, but none works. The last image was a screenshot taken in Game window with 5x scaling
     
  2. Murgilod

    Murgilod

    Joined:
    Nov 12, 2013
    Posts:
    9,724
    This is a pretty common issue, one I've run into myself. You'll have to make extra certain that your font size is correct, and this generally ends up being trial and error to some extent. I believe the formula is the Y bounds of the font in pixels + the above and lower padding, but I could be wrong on this. You'll find the above and lower padding when you click on the TMP font asset itself.

    Once you've figured out the appropriate font size, you'll be good though.
     
  3. wechat_os_Qy0z3kA7rbaDKIfRpwm8-4bhw

    wechat_os_Qy0z3kA7rbaDKIfRpwm8-4bhw

    Joined:
    May 4, 2021
    Posts:
    3
    How do I know the above and lower padding here? It seems that currently the problem works more on the verticle axis, I'm having every pixel in my font equal to 2 by 1.8 pixel on screen for some reason.
    (Update: some of them are 2 by 1.8, some are 2 by 1.9, and some ar other size)
     
    Last edited: Jun 27, 2023
  4. wechat_os_Qy0z3kA7rbaDKIfRpwm8-4bhw

    wechat_os_Qy0z3kA7rbaDKIfRpwm8-4bhw

    Joined:
    May 4, 2021
    Posts:
    3
    It seems that this problem is fixed when I manually set the height of glyph metrics in each glyph to be 1 more than the height of glyph rect, but I can't find a way to automatically do this, and this doesn't feel fine