Search Unity

TextMesh Pro Material for fallback characters

Discussion in 'UGUI & TextMesh Pro' started by sidespin, Jun 20, 2019.

  1. sidespin

    sidespin

    Joined:
    Jun 22, 2018
    Posts:
    20
    The font I'm using for English letters has a material that has thicker outline/shadow compared to Chinese/Korean/Japanese. I have all Latin characters/numbers baked in the English font asset. So if Chinese/Korean/Japanese use them it can fallback to the English font asset.

    The problem I have is that when the fallback occurs, the material used for the Latin/Number characters are not the one defined in the English font asset. Rather, they have thinner outline/shadow as defined in the Chinese/Korean/Japanese font asset.

    Is there any way to make the fallback use the Material of the fallback font asset?

    I'm aware of <font="Arial" Material="Arial Shadow"> but it requires putting fallback font assets inside Resource folder. I've been trying to avoid Resource folder completely in favor of Addressable system.
     
    maxximme likes this.
  2. Stephan_B

    Stephan_B

    Joined:
    Feb 26, 2017
    Posts:
    6,595
    The ratio of sampling point size to padding is what determined the effective range / visual appearance of the thickness of things like Outline, etc.

    So when you create your font asset assets and more importantly fallbacks, make sure this ratio is the same between all of them. For instance, if the primary font asset has a sampling point size of 100 with padding of 10 or 10% ratio. Then the fallbacks could have a sampling point size of 80 with padding of 8 or sampling of 50 with padding of 5. Having the same ratio will ensure the outline thickness is visually consistent between them.
     
  3. sidespin

    sidespin

    Joined:
    Jun 22, 2018
    Posts:
    20
    Let me clarify myself.

    My English font asset and Asian font asset have different material settings which produces different outline/shadow. This is intentional because in my case the Latin characters simply need thicker outline.

    However, when the Latin characters are rendered by the fallback system, they are of the correct font but not the correct material.

    BlackSans SDF
    upload_2019-6-20_14-55-31.png

    SimSun SDF with ASCII characters fallback to BlackSans SDF
    upload_2019-6-20_14-55-51.png
     
  4. Stephan_B

    Stephan_B

    Joined:
    Feb 26, 2017
    Posts:
    6,595
    What is the Sampling Point size and padding of these two font assets?

    When the fallback is used, TMP creates a new material that uses the atlas texture of the fallback font asset but with the same properties as the primary font asset.

    If you need to preserve the material settings, you can disable Match Material Presets in the TMP Settings.
     
    Last edited: Jun 20, 2019
  5. sidespin

    sidespin

    Joined:
    Jun 22, 2018
    Posts:
    20
    BlackSans, 60/6, BlackSans Material: outline thickness 0.2
    SimSum, 40/4, SimSum Material: outline thickness 0.04
     
  6. Stephan_B

    Stephan_B

    Joined:
    Feb 26, 2017
    Posts:
    6,595
    If you need to preserve / make sure the default material and settings of the fallback font asset is ued, you can disable Match Material Presets in the TMP Settings. See if that works for your needs.

    P.S. I haven't played with this setting in a while so there appears to be a few potential issues when modifying the Primary font asset material where it also tries to modify the sub object which it should not when Match Material Presets is disabled. I'll fix that (Update - Already fixed on my end).
     
    Last edited: Jun 20, 2019
    Seromu likes this.
  7. sidespin

    sidespin

    Joined:
    Jun 22, 2018
    Posts:
    20
    It works. Thanks very much.
    On second thought, I decided to make the materials have values as close as possible.
    Because as suggested by your video, the default material preset should have no outline.
    In that in my case I want the fallback character to have a different material instead of the default material.
    Is that even possible without using multifont?
     
  8. Stephan_B

    Stephan_B

    Joined:
    Feb 26, 2017
    Posts:
    6,595
    Right now it is not possible to control what material preset gets used by the fallback as it always uses the default material.

    Control over what Material Preset is used by the fallback is something that has been requested in the past. I guess I need to revisit this.

    One suggestion that was made was to always use the same index of material preset between the Primary and Fallback. This would require adding perhaps a list of material presets per font asset where this list could be ordered and then kept synchronized with the fallbacks.

    Still not sure how to tackle this from a logic / intuitiveness point of view but the feature certainly has a use case.
     
  9. BigGameCompany

    BigGameCompany

    Joined:
    Sep 29, 2016
    Posts:
    112
    Stephan are you saying that a fallback font will never be displayed with a stroke, shadow etc?

    Thanks
     
  10. Stephan_B

    Stephan_B

    Joined:
    Feb 26, 2017
    Posts:
    6,595
    No. For SDF Font Assets, the fallback should inherit the material properties of the font asset it is a fallback of.
     
  11. BigGameCompany

    BigGameCompany

    Joined:
    Sep 29, 2016
    Posts:
    112
    It's not working for me. If the stylesheet I have the font asset and material set with

    <font="SerifGothicStd-Heavy SDF" material="SerifGothicStd-Heavy Heading">

    SerifGothicStd-Heavy Heading has a stroke. SerifGothicStd-Heavy SDF has a fallback font with additional characters, but when the fallback is used the stroke is missing.




    Would this be to do with the padding etc when creating the font assets? The default material for SerifGothicStd-Heavy SDF doesn't have any stroke etc but I assume the fallback system utilises the actual material used by the text box.

    Thanks again
     
  12. Stephan_B

    Stephan_B

    Joined:
    Feb 26, 2017
    Posts:
    6,595
    Can you provide me with the steps to reproduce this?

    More specifically, what primary font asset is assigned to the text object?

    What Text Style do you have assigned to that object or is the <style> tag inline in the text?

    Then how are those fallbacks assigned?

    It might be easier if you can create a simple reproduction scene for me with some font assets or those.

    I suspect the issue is related to the font assets being assigned / referenced via style.
     
  13. BigGameCompany

    BigGameCompany

    Joined:
    Sep 29, 2016
    Posts:
    112
    I just did a quick test and the same issue occurred with a text box that isn't using the stylesheet as well.



    1st Text box settings (stylesheet);





    2nd text box (no stylesheet)



    The fallback is assigned in the "Fallback Font Assets" section of the font asset used with both text boxes.




    Thanks again.
     
  14. Stephan_B

    Stephan_B

    Joined:
    Feb 26, 2017
    Posts:
    6,595
    This appears to be working as expected on my end.

    For testing, I created a dynamic font asset and added "ABC" to it. I then switched it to static to prevent adding any additional characters to it.

    I assigned a fallback that contains additional characters to this static font asset.

    I then created a text object. Assigned the static font asset that only contains "ABC" and typed ABCD in the text input box. This resulted in the D coming from the fallback (as expected).

    I subsequently created a new material preset with an outline for the static font asset. Applied the Preset and all characters including the D got the outline.

    See if the following steps produce the same result.

    Make sure you have Match Material Presets enabled in the TMP Settings as seen below.

    upload_2020-1-15_17-27-29.png

    P.S. Make sure that your fallback font asset has a Ratio of Sampling Point Size to Padding that is about the same as the Primary. If the fallback has a very small Ratio then the outline might not be visible for the same material property values.
     
    Last edited: Jan 16, 2020
    Thorax- likes this.
  15. BigGameCompany

    BigGameCompany

    Joined:
    Sep 29, 2016
    Posts:
    112
    Thanks again! I set it all up again from the start and it does seem to be working now. One difference I noticed between my tests is the main font asset in the first test (that didn't work) was missing the source font file under the generation settings.



    In my second test (that works) the source font is set and population mode is set to static.




    Not sure if that was the issue or not. In the working test I also closely followed your guide here: https://forum.unity.com/threads/character-set-for-multiple-languages.524511/

    so it could have been the difference in ratio that was also the problem.

    Thanks again.