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

Blurry UI Text

Discussion in 'UGUI & TextMesh Pro' started by tccbryant, Nov 6, 2020.

  1. tccbryant

    tccbryant

    Joined:
    Aug 6, 2016
    Posts:
    10

    Unity seems to be reducing the quality of the text from scene view to game view and I can't figure out why. The sprite is also reduced in quality. How can I fix this?

    Things I've tried:
    - Scaling everything up
    - Messing with camera settings
    - Scaling the text size down and increasing font size
    - TextMeshPro Text UI

    Any help would be greatly appreciated!
     
    online_frog likes this.
  2. uMathieu

    uMathieu

    Unity Technologies

    Joined:
    Jun 6, 2017
    Posts:
    384
    In the gameView, do you have the `Low resolution aspect ratios` option enabled? The GameView will lower the resolution on high dpi screens if that option is enabled.
     
    amirhesam2001 and Alekxss like this.
  3. tccbryant

    tccbryant

    Joined:
    Aug 6, 2016
    Posts:
    10


    @uMathieu yes! It is greyed out though and I cannot change it. What should I do?
    I am using Unity 2019.4.0f1 if that is any help.
     
    Last edited: Nov 6, 2020
  4. etienne_unity

    etienne_unity

    Unity Technologies

    Joined:
    Aug 31, 2017
    Posts:
    102
    This option is enabled only for Retina displays (when
    GUIUtility.pixelsPerPoint > 1
    ), and is only useful when "aspect ratio" resolution types are selected.

    Make sure the Scale slider (right of the resolution/aspect ratio dropdown) is set at 1x, and try fixed resolutions instead of aspect ratios (like the Standalone setting in your screenshot).
     
  5. tccbryant

    tccbryant

    Joined:
    Aug 6, 2016
    Posts:
    10
    @etienne_unity Thank you for the response. I took the screenshots zoomed in to show the effect more explicitly, the buttons are actually fairly small on the screen.

    I set the aspect ratio to 16:9 and the scale to 1 and the problem still occurs. Is the only solution to make the text and sprite larger until things are sharp?

     
  6. Stephan_B

    Stephan_B

    Unity Technologies

    Joined:
    Feb 26, 2017
    Posts:
    6,588
    What point size is the text?

    Can you provide the steps to reproduce the above in a new project or provide / export a simple project / scene that would enable me to take a closer look?
     
  7. tccbryant

    tccbryant

    Joined:
    Aug 6, 2016
    Posts:
    10
    https://github.com/tccbryant/SampleBlurryText I have uploaded a simple reproduction of this here.

    The font is 200 point at a 0.1 scale but I have tried many different combinations.

    Here are the steps if you want to recreate on your own.
    1. Create new 2D project
    2. Add a sprite to the main scene, create a UI canvas as a child of the sprite
    3. Set the canvas to World Space, 0.01 scale, 0, 0, 0 position
    4. Create a button on canvas (width 50 height 50)
    5. Edit the text of the button to have 0.1 scale and 200 font size)
    There may be a simpler way to reproduce this but these were the step I used. Please let me know if there is any other useful info that I can provide.
    Unity 2019.4.0f1
     
  8. japhib

    japhib

    Joined:
    May 26, 2017
    Posts:
    65
    .01 scale on the canvas element itself seems suspicious to me. I don’t think you want size 50x50 for a world space canvas. Have you tried setting the size to width.5 and height .5 so the canvas element scale can be 1 instead of .01?
     
  9. tccbryant

    tccbryant

    Joined:
    Aug 6, 2016
    Posts:
    10
    @japhib I have tried this. When I don't scale the canvas down the other UI elements are massive must all be scaled to 0.01. For reference, my screen space canvas is 1080 by 608 and my camera (size 7) is about 24 by 14.
     
    Last edited: Nov 7, 2020
  10. Stephan_B

    Stephan_B

    Unity Technologies

    Joined:
    Feb 26, 2017
    Posts:
    6,588
    Thanks for providing the sample project for me to look at. I had a chance to review it and here are my findings / suggestions.

    First, the rendering between the scene view and game view appears to be consistent. For instance, if you were to render these objects at relatively the same size, they would appear similar as seen in the image below (left scene view - right game view).

    upload_2020-11-6_17-34-9.png

    In such cases where we have extreme scaling (relative to the pixel size of the sprite for instance) there is only so much that can be done by the bilinear filtering. You could try to enable Anti-aliasing in the Project Setting - Quality Settings or use some post process FX but in the end trying to display a 390 x 465 sprite in about 39 x 46 pixels or 1/10th its pixel size will be problematic. This is one of the reasons why artwork / sprites are usually designed a different target resolutions. Emojis for instance, are usually designed at 16 x 16, 32 x 32, 64 x 64 and 128 x 128 where depending on the resolution, a different size of those sprites are used.

    Now in regards to text, we basically have the same issue where we are trying to represent characters (glyphs) in a very small pixel grid as seen in the image below (left UI.Text - right TMP UGUI)

    upload_2020-11-6_17-56-24.png

    Similar to sprites, these glyphs have been rendered into a texture at a sampling point size far larger than this target resolution where scaling these down to a pixel grid of 3 x 5 pixels makes it very difficult to accurately render them. As seen on the left side, these glyphs sampled at 200 points and scaled down look pretty bad whereas the glyphs on the right side using TMP and SDF came out a bit better.

    In order for bitmap text (used by UI Text) to render correctly at small point size, the glyphs must be sampled for each target point size using Hinted (Raster or Smooth) and displayed at 1:1 and pixel aligned. Here is an example using the same font at 6 point size (left hinted raster - right hinted smooth)

    upload_2020-11-7_1-26-11.png

    Zoomed in
    upload_2020-11-7_1-27-17.png

    At 1:1 the hinted smooth on the right renders similar to the SDF from the previous example. Rendering text at point sizes before 8 points is torture.

    In terms of setting up your scene, scaling, etc... that is a lot of ground to cover. I recommend finding / watching a bunch or tutorials on this. Here is a good one which although related to pixel art text, it does cover a lot of the information from about about 1:1 rendering / scaling multiples, etc.
     
    star4z and JoNax97 like this.
  11. tccbryant

    tccbryant

    Joined:
    Aug 6, 2016
    Posts:
    10
    @Stephan_B Thank you for the detailed response, this answers many of my questions! The main thing that I didn't understand was how many pixels I was working with. I assumed that I could fit maybe 4x as many pixels in that button as I actually could and that is what caused the issue.

    I will make sure all of my text is 8pt or above and I will take some time to research how all of this works, thank you for providing a resource.

    The only question I have is how do I change the GlyphRenderMode? I found a list of all of the possible modes here but I do now know how to apply those modes to my project.
     
  12. Stephan_B

    Stephan_B

    Unity Technologies

    Joined:
    Feb 26, 2017
    Posts:
    6,588
    When using TMP, I would recommend to first test the SDF modes (SDFAA) to see if you are satisfied with the text rendering quality at the target point sizes. Unlike bitmap text rendering where you need a representation of the glyphs for each point size, with SDF you only need one sample for all point size and resolution which is more efficient plus the benefit of being able to add dynamic styling like outline, shadow, texturing, etc.

    I would make sure that the scale of these text objects is always uniform and (1, 1, 1) where the scaling potentially occurs at the parent level or as a result of using a Canvas Scaler. You will likely end up using text auto-sizing to dynamically adjust the point size of the text for various target resolutions / scaling. Text auto-size has significant performance overhead and as such, you should read the following post to get a better understanding of how to use text auto-sizing efficiently.

    In terms of glyph rendering mode, this is set when you create the font assets which can be done via the Font Asset Creator or using the context menu create - TextMesh Pro - Font Asset as seen in below.

    upload_2020-11-7_13-48-36.png

    By default font assets created via the context menu will use SDFAA mode which will assign an SDF shader to the Font Material that is a child of the font asset as seen below.

    upload_2020-11-7_13-50-56.png

    If you were to change the render more to one of the bitmap modes, you will need to change the shader assigned to the material to use one of the TMP bitmap shaders as seen below. You need to use one of the Distance Fields shaders for SDF modes and one of the bitmap shaders for the none SDF render modes.

    upload_2020-11-7_13-53-34.png

    I would suggest watching the following two videos which although cover localization still provide great insight on how to using Dynamic Font Assets, Fallbacks, Multi Atlas texture, etc.





    Should also take a look at these older videos which cover the Font Asset Creator and Creating and Working with Material Presets which is another important concept.

    This is a lot of stuff to review / digest but nonetheless all important to get the most out of TMP. Similar to what I said above, just start by creating a dynamic SDF font asset with the default settings, build your UI / scenes at some at some baseline target resolution relying on the Canvas Scaler to handle the other resolutions. There should be several posts and tutorials on how to setup your scene to handle various resolutions using the Canvas Scaler. Start there and let's see how everything goes :)
     
    star4z likes this.
  13. tccbryant

    tccbryant

    Joined:
    Aug 6, 2016
    Posts:
    10
    I have learned an incredible amount of useful information today @Stephan_B, thank you so much!



    Unifying the PPU and importing a new font asset with raster hinted made everything look way better! (ignore the sprite)
     
    JoNax97 and Stephan_B like this.
  14. HernandoNJ

    HernandoNJ

    Joined:
    May 13, 2018
    Posts:
    75
    I had an issue while editing the project, in case it happens to someone else.

    If you are editing the project (not in play mode) and the UI appears blurry in the scene tab, you need to increase the size of the game tab. Game tab bigger, scene tab UI clearer.
     
  15. benevolent01

    benevolent01

    Joined:
    Jul 22, 2021
    Posts:
    1
    OK so, my text looks FINE at the scene mode, and in game mode it looks BLURRY, I tried the things above, nothing seems to work. Shouldn't everything look exactly the same like in the scene mode? Is everything okay ? Or that's normal
     

    Attached Files:

    Last edited: Feb 7, 2022