Search Unity

Resolved Entire project text has become blurry

Discussion in 'UGUI & TextMesh Pro' started by dragonalumni, Sep 30, 2022.

  1. dragonalumni

    dragonalumni

    Joined:
    Jun 25, 2021
    Posts:
    31
    I've been able to google some similar problems but mine seems to be somewhat different.

    Over the last several days I've built up a UI for a couple of scenes and it was looking fine. Today I needed add some UI and the only difference I can think of is that I used script to do so and now my entire project, different scenes, with various fonts and sizes has all become blurry. It effects every character printed to the screen in the entire project. The blur effect is in both game and scene modes.

    I'm not sure how this happened (just today) and I'm not sure how to fix it, but if anyone has some insight into that I would appreciate your input.
     
    Last edited: Sep 30, 2022
  2. dragonalumni

    dragonalumni

    Joined:
    Jun 25, 2021
    Posts:
    31
    Well, ironically I found the solution pretty quick after posting this, switching shaders to
    Textmeshpro/Mobile/Distance Field SSD cleared up the entire project. I remember experimenting a bit with different shaders and thinking the "mobile" one must be low quality. -.-
     
  3. Stephan_B

    Stephan_B

    Joined:
    Feb 26, 2017
    Posts:
    6,595
    In order for SDF text to render correctly, we need to pass scale to the shader.

    This SDF Scale represents the relationship between the rendered text size and the sampling point size of the glyphs in the atlas texture. For instance, if the sampling point size of the font asset was 90pts and the text component point size 90 as well with the scale of the RectTransform being (1, 1, 1) then our SDF Scale would be 1.

    This scale information is passed per character in UV0.w when using version 3.2.0-pre.x of the TMP package.

    Now if something was to affect the resulting rendered size of the text like a Canvas Scaler, or some script modifying the scale of the parent text object or anything similar where the text component has no idea this was done, then you would get fuzzy or overly sharp text as this SDF Scale would no longer be correct.

    To try to catch these potential scale changes, the Text Component does check if the scale has changed every frame and if it has, will update the SDF Scale. However, checking if scale has changed from frame to frame does add some overhead which is inconsequential when you have few text objects but for scenes where you might have 100's or 1000's of text objects this becomes more significant.

    It is important to note that it is only necessary to check if this SDF Scale has changed if you know these text objects scale might be affected by some animation, scripts, canvas scaler, etc. In cases where the text object scale will be static, you can disabled the SDF Scale check in the Extra Settings of the text component inspector.

    Having to set the SDF Scale per character requires paying attention to potential scale changes and kind of annoying having to deal with but it does yield the best overall performance in terms of shader efficiency. The alternative to having to set the SDF Scale is to use Screen Space Derivative (SSD) which is handled in the shader but this comes at a higher cost as these scale computation are done per pixel as opposed to the SDF Scale being set per vertices. On low end mobile devices, using SSD would have a greater impact whereas on Desktop or newer mobile devices a marginal and not necessarily measurable impact.

    Hopefully, the above information helps you understand / uncover what might have caused your text objects to suddenly become blurry and why.