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:- Red squares (+1 set pass call)
- Text "1" and yellow squares (+2 set pass call)
- Text "2" and pink square (+2 set pass call)
- Text "3" (+1 set pass call)
Or, it might be a little better:
- Red squares (+1 set pass call)
- Yellow squares and then text "1" (+1 set pass call)
- 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:- TextMeshPro UI material (mobile-overlay) doesn't help here.
- Unity 2019.3.12.f1
- All texts are actually placed as last layers (e.g. there is nothing drawing on top of them).
- 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?
- Z-order makes drawing order even worse and switching between materials happens more frequently.
