- Home /
Why Is overlay(e.g. health bar) not rendered first since it can prevent overdraw?
In the Unity documents was said that overlay is rendered a the end. Why not at the begging to prevent overdraw? I noticed a render queue 3000 from my default UI material.
Answer by JonPQ · Aug 12, 2019 at 07:20 PM
because then you could not have semi transparency on your health bar, no nice soft alpha'd edges. only hard pix-elated(aliased) edges.
I don't need semi transparency on my health bar and I'am using mostly squares for my UI. So how can I change the Render queue value from my material because when I click on it the properties are grayed out. ( I think 1/4 of my screen is covered in UI overlay so wouldn't I get much more performance? I'am using the UI default material) @JonPQ
you could not use Overlay mode, switch to one of the other two modes. Put all your Ui you want drawn first in a 'UI-first' layer, then add another camera jsut to draw that Ui, set its render layer mask to just draw that layer, and it's depth (draw order) to be before the main camera(s) and make sure the other cameras do not draw that layer... and you should now have that layer drawing first.
..but for the trouble you are giving yourself.. make sure you really need to do it.... are your FPS too low, is there no other way to hit your FPS target ? are you using simplest mobile or legacy shaders (if you are not drawing anything fancy)
mobile can suffer badly from overdraw... I've occasionally gone as far as making a shader for a health bar, that can draw it in 1 call, with 0 overdraw for the fill bar.... but there are usually other ways to improve FPS before going so far.
Answer by Bunny83 · Aug 13, 2019 at 03:33 PM
UI is generally drawn after 3d scene geometry since the 3d scene as well es the UI has to use the same depth buffer. The camera maps the whole viewing frustum to the whole depth buffer range. If you draw UI first it would be possible that you get z fighting with geometry that clips into the near clipping plane.
I've seen some cases where they essentially mask out large opaque UI areas first by just writing into the depth buffer, then rendering the scene and finally rendering the UI on top of the mask regions. However depending on the size of the UI stuff it's usually not worth doing this. Some older strategy games actually had a seperate viewport for the 3d view and the UI around. So the viewport already clips everything the UI covers. However most modern UI design is an actual HUD over the game scene and often contains semi transparent elements.
How much performance overdraw costs highly depends on the platform and how complex the actual 3d scene behind the UI actually is. The screen space UI generally is drawn last and as far as i know starts with a completely cleared depth buffer.
Your answer
Follow this Question
Related Questions
Shader queue tags not working...? -3 Answers
What is the best way to render groups of flat planes using a shader 1 Answer
Should I concern myself with Render Queue since it's often made public in the inspector? 1 Answer
Making windows using renderqueues? 0 Answers
Always render object behind everything (not multiple cameras) 1 Answer