Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice

Some characters appear blurry when text generated at runtime

Discussion in 'UGUI & TextMesh Pro' started by antoined73, Sep 8, 2020.

  1. antoined73

    antoined73

    Joined:
    Feb 23, 2014
    Posts:
    24
    Hi,
    I have an issue with text mesh pro which make some characters appear blurry in texts that are created at runtime. The text appears like this :
    upload_2020-9-8_15-9-52.png

    This seems to be a bug, since, when I do some actions on the canvas, the text reappears properly :
    upload_2020-9-8_15-18-42.png

    - When i change from the editor or by code with a coroutine the pixel per reference of the root canvas
    - When i disable / enable the root canvas from the editor
    - When i disable / enable the text mesh pro component from the editor
    - When the game window changes in size

    It seems like the text display the characters and does not recalculate the appropriate size for some ?

    The root canvas is set as screen space overlay with a canvas scaler "scale with screen size" set to 1920*1080.
    Unity version is 2019.3.13f1. tried with 2019.4.9f1 : same results.
    Text mesh pro version : 2.1.1

    I tried with liberation and roboto fonts.
    I tried to recalculate a lot of times the font asset creator window and tried differents resolutions for the atlas. The blur is avoided when the font atlas res is superior to 2048*2048 but then the text has a lot of aliasing i'd like to avoid :
    upload_2020-9-8_15-26-51.png

    Do you have any ideas what's going on and how I could have nice and sharp text please ?

    Thank you :)
     
  2. Stephan_B

    Stephan_B

    Joined:
    Feb 26, 2017
    Posts:
    6,595
    This appears to be related to the SDF Scale being incorrect on some of those characters or possibly an issue related to Perspective Filtering.

    First, set the perspective filtering to 0 in the debug section of the material inspector of that text object. Does the issue persist?

    If the issue persists, are all the characters in those text objects coming from the same font asset or is a fallback used for some of them? For instance, the x, f, o and e?

    Can you submit a bug report with the above for me to look at?
     
  3. antoined73

    antoined73

    Joined:
    Feb 23, 2014
    Posts:
    24
    Hi Stephan, Thanks for the answer !

    So I tested to set 0 the perspecive filtering in the font debug dection and it does not work, still blurry.
    But I found that, when I open the debug section of the font material while in play mode, the text updates by itself and becomes totally normal ! https://i.imgur.com/tLRSqeo.gif

    No fallback font used, I am using the default font LiberationSans SDF, which does not have any.
    Here is the font asset I used :
    upload_2020-9-9_9-44-38.png
    upload_2020-9-9_9-44-59.png

    Sure, I'll submit a bug report right now.
     
  4. Stephan_B

    Stephan_B

    Joined:
    Feb 26, 2017
    Posts:
    6,595
    Yes. Please be sure to include the project and steps to reproduce.

    Once you get the Case # via email please post it here.
     
  5. antoined73

    antoined73

    Joined:
    Feb 23, 2014
    Posts:
    24
    Case 1276349 : https://fogbugz.unity3d.com/default.asp?1276349_krdc6lifh2fe10ld
    I did include only the font. The text object is not included since they are part of a company project I'm working on.
    But I explained the steps to reproduce.
    If it's really a problem, I could create a really small project showcasing only this bug.

    EDIT :
    I can't reproduce the bug outside of my project...
    So I suppose this bug is caused by the context my project the text is put into.
    In my project generate a huge HMI at runtime with lot of canvases, layout elements, horizontal/vertical layouts, custom ui resizer and ui placers.
    I'll try to deactivate one element by one to see if the bug disappears.
    It'll be really though to guess

    EDIT 2 :
    I don't know if this could have an impact or not on the bug, but my prefabs are actually in a Resources package located in a custom package. The fonts are generated in the assets, and then moved to my custom package.
     
    Last edited: Sep 9, 2020
  6. antoined73

    antoined73

    Joined:
    Feb 23, 2014
    Posts:
    24
    For the moment, I didn't suceeded to isolate the bug in a little scene.

    I tried to change the material shader with the mobile > distance field : the texts are not displaying correctly either. But the glitches are differents. It could, then, be a shader problem ?

    Anyway, It seems to have a link with the canvas that I enable / disable to show / hide parts of my UI.
    It seems that instead of that, enabling / disabling the canvases does the trick and the texts update themselves correctly.

    Since I don't want to do that in my UI and I'm constrained to enabling / disabling the canvases, I enable and disable all the texts components that I found in the childs; it does the trick to. Its really not beautiful but hey, I can't find what's going on.

    Don't you have any more insight on your side ?
    By opening the debug section of the font material in the inspector, which methods are triggered ?
    Is there any shader update when doing this ?
    I would be curious to trigger this methods by hand, when i'm opening a part of my HMI to see if the texts appear without glitches.
     
  7. Stephan_B

    Stephan_B

    Joined:
    Feb 26, 2017
    Posts:
    6,595
    Thank you for submitting the bug report.

    I'll take a look as soon as possible.

    In the meantime and until I get back to you on this and since this is SDF Scale related, I would suggest switching over to using one of the new SSD Shaders included in the latest release of the TMP package and contained in the TMP Essential Resources. Those shaders have the suffix SSD in their name.

    Let me know if the issue persists after switching to an SSD shader.
     
  8. antoined73

    antoined73

    Joined:
    Feb 23, 2014
    Posts:
    24
    Oh yes ! With this new shader it works as intended !
    Thank you !
     
    Stephan_B likes this.
  9. antoined73

    antoined73

    Joined:
    Feb 23, 2014
    Posts:
    24
    I have now a new problem with this SSD shader, when building and launching a linux build, all the texts are now not rendered at all !

    Found in the Player.log this trace :
    Code (CSharp):
    1. Material Roboto-Regular SDF Material doesn't have _Stencil property
    Which is weird because I found in the SSD Shader that the _Stencil is indeed there and the texts work properly on the Editor and Windows build.

    I als found out that when I imported the ssd shaders from tmp essential ressources I got this problem where the shader can't find the TMP_properties, but it is in the same folder :
    upload_2020-9-21_11-50-31.png

    So I guess, since I did the compiling of the linux build on a linux machine that got the project from git; the shader for any reasons, is working on my machine but will not for every persons who downloads my project.
    Do you have a fix for this ? Tried to delete the whole folder and reimported the tmp essential ressources, still same results. The mobile SSD shader seems to compile though, I will try to use it for the moment.

    EDIT : I tested it whit the mobile shaders that are compiling, its working. So now, my only problem is to find a way to compile the normal SSD shader that says, it does not find the TMP_properties.cginc file
     
    Last edited: Sep 21, 2020
  10. Stephan_B

    Stephan_B

    Joined:
    Feb 26, 2017
    Posts:
    6,595
    I have run into similar issues in the past where Shader compilation seems to get confused for some odd reason. In the Editor, re-importing the TMP_properties.cginc usually resolves that issue.

    Perhaps, the TMP_properties.cginc was not imported / compiled correctly in the build?

    I know you can include pre-compiled shaders in a build, perhaps that could work?
     
  11. lucidniht

    lucidniht

    Joined:
    Jul 25, 2017
    Posts:
    1
    Same issue here.
    After 2 days, I've found that 'Canvas.addtionalShaderChannels' should enable 'TexCood1'.
    Now everything is ok.
     

    Attached Files:

    rockin likes this.
  12. karliss_coldwild

    karliss_coldwild

    Joined:
    Oct 1, 2020
    Posts:
    599
    Recently implemented a workaround for this problem. In my case it only affected objects which where created in scene using editor, not the one which are later dynamically created. The problem seems to also disapear when objects are hidden and then reenabled. As a workaround I call `ForceMeshUpdate()` one frame after the Awake, the disabling and enabling of object probably also triggers `ForceMeshUpdate`. My scene also contains some custom canvas scaling logic.

    Observations I made while debugging it also pointed me at incorrect scaling factor.
    I recorded render calls using QRendereDoc, only diference between good and bad text was TEXCOORD1.y which supposedly contains scaleRatio. This matches with lucidniht observation that disabling corresponding shader channel produces similar effect, but I assume that in his case the cause was simpler.

    I couldn't quite follow where exactly it's supposed to be initialized in C# code since uv2 and uvs2 appears in many places. UpdateSDFScale is guarded by
    Code (CSharp):
    1. if (abs(oldscale-newscale) > eps)
    so if it doesn't get set right in the first frame it probably keeps drawing it wrong until something else like ForceMeshUpdate causes a refresh.
     
    rockin likes this.
  13. rockin

    rockin

    Joined:
    Dec 11, 2013
    Posts:
    26
    Awesome find, thanks!
    In my case it was because I was using a runtime added canvas that did not have TexCoord1 enabled.