Author Topic: Render Q and Non-NGUI Draw Calls  (Read 10872 times)

AtomicBob

  • Jr. Member
  • **
  • Thank You
  • -Given: 3
  • -Receive: 0
  • Posts: 69
    • View Profile
Render Q and Non-NGUI Draw Calls
« on: January 06, 2014, 11:34:38 AM »
I'm currently in the process of updating from 2.6.3 to 3.0.8 and I'm running into a little bit of trouble. Our game is fully 2D and we use a series of UIPanels with different Z values to create 'layers'. We use some dynamic, non-atlased UITextures and some ParticleSystems which require the layering things draw in the proper order. In pre-3.0 versions of NGUI this has been dead simple to accomplish. For example, we could have 3 UIPanels: "Panel - Low" at Z = 0, "Panel - Medium" at Z = -10, and "Panel - High" at Z = -20. Then, whenever we needed something that required a new, non-NGUI draw call we just had to make sure it had a Z value above the UIPanel it needed to be drawn above and below the next UIPanel. I don't know how it worked in the background, but everything was automatic. As long as the objects Z value was set appropriately, things drew in the correct order.

Now that we're upgrading to >3.0, this approach appears to have fallen apart. I'm having a hard time obtaining similar functionality as before. The only information I've been able to find so far basically says to create custom shaders for everything that lets us set the render queue for non-NGUI objects. We'll go this route if we have to, but I'd rather skip messing with shaders for now and just have a simple system like we had before.

This leads me to a few questions:

  • Is there any built-in way to see render queue on stuff in the editor? I'm assuming from this post that there is not, and I'll have to modify the shaders we're using. We're using the ones included with NGUI, so I'll have to re-modify them each time we update, which is an annoyance.
  • How did it work automatically before? This documentation page mentions that everything except the Geometry queue is ordered by distance from the camera, so I suspect this is how it was able to order UIPanels and ParticleSystems automatically in the past. Maybe the new NGUI system interferes with this.
  • What is the correct way to handle this sort of layering in NGUI now?
  • Most importantly, is there a simple way to make this automatic again?

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Render Q and Non-NGUI Draw Calls
« Reply #1 on: January 06, 2014, 12:00:33 PM »
In NGUI 3 everything is based on depth rather than Z. Z is no longer used. Panel depth supercedes widget depth.

You can specify explicit render queues on your panels if you like, and there is a helper script in the Useful Stuff sticky post that can let you modify render queues of particle systems and other 3D objects, helping you insert things in between of draw calls.

AtomicBob

  • Jr. Member
  • **
  • Thank You
  • -Given: 3
  • -Receive: 0
  • Posts: 69
    • View Profile
Re: Render Q and Non-NGUI Draw Calls
« Reply #2 on: January 06, 2014, 03:22:32 PM »
I realize Z is no longer used. That is why I'm asking for information about how best to deal with the change. I've been playing around in a test scene and realized why we've been able to position ParticleSystems between NGUI panels in the past. Unity sorts draw calls by distance when the render queue is the same. Since NGUI always used 3000 in the past, Z value determined the draw order. The change causes a huge headache for us moving forward. Currently, I see three options:

  • Change the render queue on a per-object basis. There is significant time investment associated with this. The script you mentioned breaks batching as it stands now, which we can't have. I'd have to extend it to deal with that in some way, plus go through every non-NGUI object in the game and set an appropriate value.
  • Stop updating NGUI. This is obviously not desirable. We shouldn't have to miss out on future improvements and bug fixes to avoid having to make sweeping changes to our project.
  • Force NGUI to use render queue = 3000. This is looking like the best option at the moment. It means no changes to our project and minimal time investment.

ArenMook, would you be willing to add support for option 3? This would allow people who don't want to make the switch to the render queue system to keep the old Z-ordering functionality. Personally, I find Z ordering to be the easiest way to handle situations where non-NGUI draw calls need to exist between NGUI panels. This is critical to 2D games made with NGUI where Unity ParticleSystems are used. Currently, setting a UIPanel's Render Q to Explicit will still auto-increment the render queue for each draw call. What I propose is just being able to disable the increment so it always sets the render queue to 3000.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Render Q and Non-NGUI Draw Calls
« Reply #3 on: January 06, 2014, 05:18:43 PM »
You already can use option 3. Select your panels, force them to use a render queue of 3000.

AtomicBob

  • Jr. Member
  • **
  • Thank You
  • -Given: 3
  • -Receive: 0
  • Posts: 69
    • View Profile
Re: Render Q and Non-NGUI Draw Calls
« Reply #4 on: January 06, 2014, 05:56:25 PM »
As it stands, this option does not work in the way I'm talking about. Currently, the UIPanel will auto-increment the render queue on every draw call. Thus, only the first draw call will actually have a render queue of 3000.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Render Q and Non-NGUI Draw Calls
« Reply #5 on: January 06, 2014, 09:31:09 PM »
Hmm, if that's the case then that's a bug. Try changing line 1159 of UIPanel.cs from this:
  1. dc.renderQueue = startingRenderQueue + i;
...to this:
  1. dc.renderQueue = (renderQueue == RenderQueue.Explicit) ? startingRenderQueue : startingRenderQueue + i;

AtomicBob

  • Jr. Member
  • **
  • Thank You
  • -Given: 3
  • -Receive: 0
  • Posts: 69
    • View Profile
Re: Render Q and Non-NGUI Draw Calls
« Reply #6 on: January 06, 2014, 10:04:50 PM »
Haha, that's precisely what I did to work around the issue in the short term. Thanks for the help.