Search Unity

Not see TextMeshPro rendering from the back?

Discussion in 'UGUI & TextMesh Pro' started by Karsnen_2, Oct 27, 2019.

  1. Karsnen_2

    Karsnen_2

    Joined:
    Nov 28, 2011
    Posts:
    89
    Scenario

    Right-click on the hierarchy panel -> 3D Object -> Text - TextMeshPro





    It default's with a text called "Sample Text". Now I would like to disable/hide or (not see) the rendering if you move your camera from behind.

    Request

    I don't want to see this below screenshot :



    Can this be achieved by adjusting the settings from TextMeshPro component rather than any other unity components?

    Thank you.
     
  2. Stephan_B

    Stephan_B

    Joined:
    Feb 26, 2017
    Posts:
    6,595
    This is controlled via the Shader / Material. Use to following property to control this.

    /// <summary>
    /// Sets the culling on the shaders. Note changing this value will result in an instance of the material.
    /// </summary>
    public bool enableCulling
     
  3. Karsnen_2

    Karsnen_2

    Joined:
    Nov 28, 2011
    Posts:
    89
    Hello @Stephan_B .

    First, TextMeshPro is a wonderful piece of work. Thank you very much.

    Your answer worked well. However, I have two follow up questions.

    1) Is there a way to toggle that boolean value through the inspector?

    2) Now let's say I have "Hello" as the initial string. In Awake() I set enableCulling to be TRUE. Now during runtime, if I add an emoji to it, say [https://emojipedia.org/grinning-face/] - which in turn uses the default emoji sprite. The culling is absent for that emoji as it creates a new child called as "TMP SubMesh [TextMeshPro/Sprite]" with TMP_SubMesh component to it. How do I deal with it?

    Do I have to set enableCulling to TRUE every time I change the text in for the TextMeshPro ?
     
  4. Stephan_B

    Stephan_B

    Joined:
    Feb 26, 2017
    Posts:
    6,595
    There is not.

    The challenge with adding this as some property of the text object is because it is related to Culling which is material specific. As such this would affect all text objects that share this material.

    When changing this property via scripting, an instance of the material is created and assigned to that specific text object. In the Editor / outside of play mode, we don't want to be creating material instances. So the challenge in exposing this in the inspector is more resource management related. Maybe this should be exposed as a material property.

    That is something I need to look into. As you pointed out the culling mode is only changed when this flag is set so if the text changes afterwards resulting in additional submesh objects being created, then these submesh objects won't have that flag set correctly.

    Until I make changes to properly handle this, you would have to check the culling setting is correct on those submesh objects.
     
  5. Karsnen_2

    Karsnen_2

    Joined:
    Nov 28, 2011
    Posts:
    89
    @Stephan_B Thank you for your response.

    What I will do is, in runtime if a new emoji is being added - then I will
    GetComponentsInChildren<> for TMP_SubMesh. I will iterate the returned array to set enableCulling to TRUE on all of them.

     
  6. Stephan_B

    Stephan_B

    Joined:
    Feb 26, 2017
    Posts:
    6,595
    I added support for Culling modes to the Material Inspector. This can now be set per material in the Debug Settings of the Material Inspector.

    upload_2019-10-27_15-2-40.png

    In the Editor via the Inspector, this will automatically sync culling mode between the parent text object and sub objects.

    In terms of Workflow, instead of setting this property via the text object "enableCulling" property, this should be set on the material now. Culling mode will mirror those of the parent text object.

    I still need to address culling modes not getting automatically synced with the parent text object when using the "enableCulling" property and then adding a sprite or fallback but given culling can now more easily be controlled via the Material Inspector, I am not even sure I should continue to expose that property. Thoughts?

    This new feature requires updating all TMP shaders and as such will require re-importing the TMP Essential Resources when this is available in the next release.
     
    Last edited: Oct 27, 2019
    jdmcgraw, DicoLeeChernWai and PolyMad like this.
  7. Karsnen_2

    Karsnen_2

    Joined:
    Nov 28, 2011
    Posts:
    89
    @Stephan_B

    Thank you for your response. When you say added, should I just update the package manager? I am on Unity 2018.4.10f1 (LTS version)

    As for suggestion is concerned, as you're only exposing in debug mode - I would suggest that to be an API call.
    But however, if a user does explicitly set the culling mode on a parent - it should comply to that boolean value for any or all of its children. Also when the user modifies the text(string) or any other properties on that TMP component, it should adhere to that boolean value till the end of its lifecycle.
     
  8. Stephan_B

    Stephan_B

    Joined:
    Feb 26, 2017
    Posts:
    6,595
    This will be in the next release which will be version 1.5.0-preview.2 for 2018.4 and 2.1.0-preview.2 for 2019.x or newer. These new releases will be out this week.

    It is not debug mode but in the Debug Settings section of the Material Inspector as seen below.

    upload_2019-10-27_22-44-11.png

    The Cull Mode of the parent text object will be automatically mirrored on the child sub text objects.
     
    Karsnen_2 likes this.
  9. Karsnen_2

    Karsnen_2

    Joined:
    Nov 28, 2011
    Posts:
    89
    @Stephan_B

    Hmmm sure but I would still stick with an API call rather than inspector. I am suggesting based on assumptions.
    Those assumptions are
    1. It is very rare (like my case) for someone to have bare back TextMeshPro component without any 3D mesh behind.
    2. It is not as common as someone would use TextMeshPro in 3D with respect to 2D
    If the usage is very limited then you will have to appeal to those "super-users" through API call with clear documentation.
     
  10. Stephan_B

    Stephan_B

    Joined:
    Feb 26, 2017
    Posts:
    6,595
    It is rare for users to use Back culling.

    Since control over Culling is functionality specific to shaders and materials, I think it is more intuitive and easier for users to access this functionality via the Material Inspector. Furthermore, I believe in the vast majority of use cases, users would typically want to do this in the Editor / Scene Hierarchy as opposed to changing culling modes at runtime.

    It is also important to note that culling modes are accessed via the material which in the end is how TMP handles this via this enableCulling property. As such, users can always access the material of the text object to control culling modes on that material.

    Code (csharp):
    1.  
    2. // Sets the culling mode to "cullingMode" value on the shared material.
    3. renderer.sharedMaterial.SetFloat(ShaderUtilities.ShaderTag_CullMode, cullingMode);
    4.  
    5. // Creates an instance of the material and sets the culling mode to "cullingMode" value.
    6. renderer.material.SetFloat(ShaderUtilities.ShaderTag_CullMode, cullingMode);
    7.  
    P.S. I won't remove this enableCulling property from the API since users are already using it.
     
  11. Karsnen_2

    Karsnen_2

    Joined:
    Nov 28, 2011
    Posts:
    89
    @Stephan_B

    Yeah sure. Thank you for your efforts with TextMesh Pro. It is an amazing improvement on top of the existing default Unity UI Text.
     
  12. mryasaremir

    mryasaremir

    Joined:
    Aug 16, 2018
    Posts:
    2
    Hi, I updated TMP to 2.1 version and I'm getting this error my materials doesnt have Cull Mode property upload_2019-11-12_14-48-49.png
     
  13. Karsnen_2

    Karsnen_2

    Joined:
    Nov 28, 2011
    Posts:
    89
    @mryasaremir

    If I am correct -> You're trying to change the cullmode property from a script. If that is the case please check the property "_CullMode". I think it should be just "CullMode".
     
  14. Stephan_B

    Stephan_B

    Joined:
    Feb 26, 2017
    Posts:
    6,595
    Here is the Important Note that I posted related to this in the following stick thread.

    IMPORTANT NOTE:
    As a result of adding support for setting culling mode in the material in the Debug Settings of the material inspector, users should update the TMP Essential Resources via the "Window - TextMeshPro - Import TMP Essential Resources" menu option to import the revised shaders.

    There is also a minor fix available in this post for another potential issue related to this change.
     
    Karsnen_2 likes this.
  15. Karsnen_2

    Karsnen_2

    Joined:
    Nov 28, 2011
    Posts:
    89
    @Stephan_B : Thank you for letting us know on this thread.
     
  16. mryasaremir

    mryasaremir

    Joined:
    Aug 16, 2018
    Posts:
    2
    I imported resources and it fixed. Thanks
     
  17. Stephan_B

    Stephan_B

    Joined:
    Feb 26, 2017
    Posts:
    6,595
    Since the shaders rarely get edited unlike font assets and other TMP resources, I am exploring moving the shaders into the TMP package for the next release. This would ensure that future shaders changes do not require updating of the TMP Essential Resources.
     
  18. PolyMad

    PolyMad

    Joined:
    Mar 19, 2009
    Posts:
    2,350
    Ohhhhh I like this SO MUCH! Thank you!