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. Dismiss Notice

Question How to render text?

Discussion in 'High Definition Render Pipeline' started by TOES, Dec 12, 2022.

  1. TOES

    TOES

    Joined:
    Jun 23, 2017
    Posts:
    134
    I am rendering a cutscene using path tracing, it needs an overlay with text but my textmesh pro object attached to the camera no longer works when PT is enabled (it works fine using non PT, so the textmesh pro shader is not supported in PT apparently).

    As a workaround I suppose I need to render text directly to the target rendertexture somehow. Any idea how to do this, or any other workaround to get text rendered ?
     
  2. ElevenGame

    ElevenGame

    Joined:
    Jun 13, 2016
    Posts:
    143
    Have you tried using the UI version of TextMeshPro as well? maybe that one works..
     
  3. TOES

    TOES

    Joined:
    Jun 23, 2017
    Posts:
    134
    That doesnt render into the target rendertextture which I will output to the video generator
     
  4. TOES

    TOES

    Joined:
    Jun 23, 2017
    Posts:
    134
    Ok, I figured it out, given the target rendertexture in tex:

    Code (CSharp):
    1.  
    2.         Vector2 size = new Vector2(192, 108);
    3.         //Save settings
    4.         GL.PushMatrix();
    5.         GL.LoadIdentity();
    6.         Matrix4x4 proj = Matrix4x4.Ortho(-size.x / 2.0f, size.x / 2.0f, -size.x / 2.0f, size.y / 2.0f, -10, 100);
    7.         GL.LoadProjectionMatrix(proj);
    8.         RenderTexture currentActiveRT = RenderTexture.active;
    9.  
    10.         Graphics.SetRenderTarget(tex);
    11.         textmeshPro.renderer.material.SetPass(0);
    12.         Graphics.DrawMeshNow(textmeshPro.mesh, Matrix4x4.identity);
    13.        
    14.         //Restoresettings
    15.         GL.PopMatrix();
    16.         RenderTexture.active = currentActiveRT;
    17.  
    Renders whatever is in the given textmeshpro object into the rendertexture
     
    ElevenGame likes this.