Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

How to pass data to custom TMP shader?

Discussion in 'UGUI & TextMesh Pro' started by snw, Mar 21, 2019.

  1. snw

    snw

    Joined:
    Mar 13, 2014
    Posts:
    42
    Hi,

    I want to pass additional data to a customized TMP shader.
    For the data, I would want to utilize an unused UV channel, e.g. TEXCOORD2.

    I tried various ways to assign the data to the mesh by script:
    • setting the meshInfo's mesh UVs: textfield.textInfo.meshInfo[0].mesh.SetUVs(2, uvs);
    • setting the mesh's UVs: textfield.mesh.SetUVs(2, uvs);

    in combination with updating the mesh via:
    • textfield.UpdateGeometry(textfield.mesh)
    • textfield.UpdateGeometry(textfield.textInfo.meshInfo[0].mesh)
    • textfield.mesh.UploadMeshData();
    • textfield.textInfo.meshInfo[0].mesh.UploadMeshData();

    No success. TMP seems to wipe out all data channels that it doesn't use by default (POSITION, NORMAL, COLOR, TEXCOORD0, TEXCOORD1).


    Is there any way to accomplish passing custom data to a TMP shader?


    Cheers.
     
    Last edited: Mar 21, 2019
  2. Stephan_B

    Stephan_B

    Unity Technologies

    Joined:
    Feb 26, 2017
    Posts:
    6,588
    Are you using the Canvas System / Canvas Renderer or the normal TMP component that uses the Mesh Renderer?

    If using the Canvas System, the Canvas controls what channels are actually used / available.

    TMP uses uv and uv2 where uv contains the coordinates of the glyph in the font atlas texture and uv2 contains the x, y texture coordinates for texture mapping on the face and outline of the text packed in x and SDF Scale in the y.

    Other uv channels should be free to use.
     
  3. snw

    snw

    Joined:
    Mar 13, 2014
    Posts:
    42
    Hi,

    I did some further testing.

    Mesh Renderer based TMP works out of the box.
    To pass data to Canvas based TMP shaders, you have to:
    1. enable the appropriate additional shader channel(s) on the Canvas component
    2. after having set the data on the mesh, call one of these methods on your tmp reference:
      • ForceMeshUpdate()
      • UpdateGeometry()

    Cheers.
     
    Stephan_B likes this.