Author Topic: NGUI and depth buffer  (Read 3282 times)

kittikun

  • Newbie
  • *
  • Thank You
  • -Given: 2
  • -Receive: 5
  • Posts: 46
    • View Profile
NGUI and depth buffer
« on: February 09, 2014, 10:47:17 PM »
Hi all,

I was wondering if it was possible for NGUI to write to the depth buffer.
The idea would be to save some fill-rate by rendering the non-transparent UI first so and fill the depth buffer so that no rendering is occurring below.

I would like to know the following points:
  • If I have one UIPanel, only one quad is generated ?
  • If it is the case, having multiple drawcall would mean that the whole screen quad is drawn multiple times ?That would seem totally inefficient..

I suppose my question is more about how the NGUI rendering pipeline works.

To achieve the effect I want, the current approach would dictate using multples panels and write a custom shader to write to the depth buffer where the alpha is == 1.

For widgets requiring alpha, they would be drawn as usual after the scene has been rendered.

Any insights on this ?

Thank you

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: NGUI and depth buffer
« Reply #1 on: February 10, 2014, 04:50:13 PM »
There is very little reason to use depth writes in UI. NGUI 2 used to have this feature, but after some performance testing on mobile devices I canned it. It wasn't gaining any. Quite the opposite (as I was drawing things twice).

The only feasible performance gain you can possibly obtain from this is if your UI and game world share the same depth buffer -- which is rarely ever the case as the UI is generally drawn using a separate camera. In this approach you'd draw the UI to depth first, which would Z-fail the game geometry.

Long story short -- it's not worth it.