Search Unity

Unity UI Include font's texture to the Sprite Atlas

Discussion in 'UGUI & TextMesh Pro' started by arkogelul, Nov 20, 2017.

  1. arkogelul

    arkogelul

    Joined:
    Nov 14, 2016
    Posts:
    105
    Hi everyone,

    I'm using a lot of panels in my game and would like to reduce the number of draw calls by including the font's texture in a Sprite Atlas.

    I made my own custom font and packed it (the texture) with the rest of my graphic elements but it didn't change anything. The draw calls show that the text is rendered separately from the rest of my graphic elements regardless of the font's texture being included in the Sprite Atlas.

    Thanks !
     
  2. Johannski

    Johannski

    Joined:
    Jan 25, 2014
    Posts:
    825
    Well if the text is on top of a graphical element it can't be batched. You might want to take a look at TextMesh Pro. https://assetstore.unity.com/packages/essentials/beta-projects/textmesh-pro-84126

    It will need an own draw call. But one or two drawcalls are not killing your performance. If you have a lot of panels that are changing often, consider putting them in own subcanvases in order to regulate redraws.
     
  3. arkogelul

    arkogelul

    Joined:
    Nov 14, 2016
    Posts:
    105
    Thanks for you answer.
    I know about TextMesh Pro, but it doesn't fill my needs.

    That's what I noticed. But according to the frame debugger the batch breaks because of a different texture.
    Thus I was wondering if there would be a way to use the atlas as texture for the font. That way everything would be on the same texture and there would be just one batch.
     
  4. Johannski

    Johannski

    Joined:
    Jan 25, 2014
    Posts:
    825
    Hm, I actually would have guessed that in the transparent queue batching of overlapping quads is not possible at all.

    Did you check the unity Guide: https://unity3d.com/learn/tutorials/temas/best-practices/unity-ui-profiling-tools?playlist=30089

    Maybe you ran into this problem:
     
  5. arkogelul

    arkogelul

    Joined:
    Nov 14, 2016
    Posts:
    105
    Yes, that's exactly my problem.

    And, as it is said, it's actually possible, as long as the quads share the same material/texture.

    My panels are composed of 2 elements (image components) :
    - a tileable plank texture.
    - a border texture.
    Those 2 elements (quads) that completely overlap each other (they are superposed using a vertical layout and a content fitter), and as their texture is stored in the sprite atlas, they are rendered in the same batch.

    The thing is, there is some text on top of this panel (here comes our problematic overlapping quads), and as the text has its own texture, it can't be rendered along with the panel. So the batch breaks in order to render it. And it breaks again to render the next panel of my UI (that uses the panel texture I talked earlier).

    I actually found a workaround to this problem, I'm rendering all the panels in one group and all the texts in another.
    Thus all the panels are rendered in 1 batch and all the text in another. It's not as visually organized in the hierarchy tab, but it reduces the draw calls a lot.

    I wish there'd be a way to use the Sprite Atlas for the font's texture though.
     
    abegue likes this.
  6. Mese

    Mese

    Joined:
    Dec 13, 2015
    Posts:
    41
    Hi, arkogelul

    I stumbled upon this thread.
    What do you mean when you said :
    You mean: grouping them under the same parent in the hierarchy?