Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Need help with TMPro API

Discussion in 'UGUI & TextMesh Pro' started by kevdome3000, Jan 31, 2020.

  1. kevdome3000

    kevdome3000

    Joined:
    Jun 9, 2019
    Posts:
    17
    I am trying to select a character from a TMP Font Atlas at runtime and store the Glyph in a Texture2D for use with the VFX graph. How can I accomplish this? I'm stumped :(
     
  2. Stephan_B

    Stephan_B

    Joined:
    Feb 26, 2017
    Posts:
    6,595
    Can you provide more insight on the use case?

    Does VFX Graph modify the glyph in this texture or does it simply need reference to some shape in some texture?
     
  3. kevdome3000

    kevdome3000

    Joined:
    Jun 9, 2019
    Posts:
    17
    Hey Stephan,

    Thanks for getting back to me.

    Here is a link to a video of the use case POC:
    https://www.dropbox.com/s/9a5j7r5e79g0sb7/example.mov?dl=0

    Instead of random procedural characters though, I'd like to seed the graph with the shapes of font characters from a TMP font atlas.

    Here are images of my vfx graph and shader graph vfx asset setups: Screen Shot 2020-01-28 at 6.00.53 PM.png Screen Shot 2020-01-28 at 6.02.06 PM.png
     
  4. kevdome3000

    kevdome3000

    Joined:
    Jun 9, 2019
    Posts:
    17
    To answer your question directly, i believe the vfx graph just needs to reference a font character shape from a TMP font atlas texture
     
  5. Stephan_B

    Stephan_B

    Joined:
    Feb 26, 2017
    Posts:
    6,595
    In the Font Asset, you have the Character Table which contains character that include / point to a glyph which are contained in the Glyph Table. These glyphs contains the UV coordinates to the glyphs contains in the atlas texture.

    I guess the challenge is figuring out a way for shader graph to point to a glyph itself... hmm.
     
  6. kevdome3000

    kevdome3000

    Joined:
    Jun 9, 2019
    Posts:
    17
    Yes exactly. That's where I'm stuck :(
     
  7. sschaemUnity

    sschaemUnity

    Joined:
    Oct 13, 2019
    Posts:
    21
    From what I can tell you only need to change your custom function in the "Letters" subgraph to be the built in "Sample Texture 2D " input node and assign the TMPro font atlas texture and keep the default UV0. (Make sure you use a bitmap TMPro font)
    Assign this graph shader to any TMPro material and you should be good to go.
     
  8. kevdome3000

    kevdome3000

    Joined:
    Jun 9, 2019
    Posts:
    17
    Thanks for the suggestion! I gave it a shot but wasn't able to figure out how to sample the font atlas texture and only select one character at a time.

    Any ideas?