Unity UI Canvas & SetPass calls & TextMeshProUGUI order

Viewed 452

I am trying to minimize SetPass calls in Unity canvas.

Consider the following example:

The rendering in canvas happens layer by layer. The rendering sequence can be like the following:

  1. Red squares (+1 set pass call)
  2. Text "1" and yellow squares (+2 set pass call)
  3. Text "2" and pink square (+2 set pass call)
  4. Text "3" (+1 set pass call)

Or, it might be a little better:

  1. Red squares (+1 set pass call)
  2. Yellow squares and then text "1" (+1 set pass call)
  3. Pink square and then texts "2" and "3" (+2 set pass calls)

Because of this, drawing is switching from default image material to text material and back. The result of this drawing will produce at least 4 draw calls, instead of 2. Even though only 2 materials are in use. This example also assumes that Red, Yellow, and Pink squares weren't batched.

Question: is there a way to ensure that text will be always drawn on top?

Notes:

  1. TextMeshPro UI material (mobile-overlay) doesn't help here.
  2. Unity 2019.3.12.f1
  3. All texts are actually placed as last layers (e.g. there is nothing drawing on top of them).
  4. Batching helps sometimes. However, complex UI might use several materials. Since my intention is to always draw text over everything, isn't there a general solution for this?
  5. Z-order makes drawing order even worse and switching between materials happens more frequently.
0 Answers
Related