Search Unity

  1. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

any way to force canvas (or TMPro) to draw always on top of just ONE other mesh?

Discussion in 'UGUI & TextMesh Pro' started by JoeStrout, May 14, 2022.

  1. JoeStrout

    JoeStrout

    Joined:
    Jan 14, 2011
    Posts:
    9,859
    I'm making a book that will have a number of pages. Each page consists of an ordinary mesh, plus a world-space Canvas containing a TextMeshProUGUI. I curl both the page and the text mesh using the same bezier function. I also add a small Y offset to the text mesh so that it draws on top of the page.

    upload_2022-5-14_10-21-10.png

    Works fine at moderate amounts of curl, but when the curl gets more intense, I often have the page clipping through the text mesh, as shown above. This happens because the page is a much lower-resolution mesh (currently 8x8 quads) than the text mesh.

    I could sort of work around this by using a higher resolution page mesh, or by bending the text mesh to match the actual page mesh instead of the mathematical bezier function. But the former solution is heavy and the latter is likely to make the low-poly nature of the page more apparent than I would like.

    Is there any way to say: draw this (text) mesh always on top of that (page) mesh, but otherwise sort them normally with respect to everything else in the scene?
     
  2. JoeStrout

    JoeStrout

    Joined:
    Jan 14, 2011
    Posts:
    9,859
    OK, how about this: normally the TextMeshPro renderer is transparent around the "ink" part of the glyphs. Is it possible to have that render as a solid color instead? And maybe apply some simple mobile-diffuse style shading to it?

    My thinking is: don't render the page at all; render just the text, but with some additional fake glyphs to fill in around the characters somehow... and then have that rendering serve as the text and the page, all at once. This would eliminate the clipping problem and probably be more efficient, too.

    But it would require (1) some way to add additional quads to the mesh the TextMeshProUGUI creates, to fill in around the characters (or I suppose that could be a separate mesh); and (2) an altered version of the standard TMPro shader, which renders the "paper" around the glyphs within each quad.

    Anybody know if something like this already exists? (@Stephan_B ?)