Author Topic: 3.0.8 f7 UITexture Draw Order Oddity  (Read 5180 times)

AtomicBob

  • Jr. Member
  • **
  • Thank You
  • -Given: 3
  • -Receive: 0
  • Posts: 69
    • View Profile
3.0.8 f7 UITexture Draw Order Oddity
« on: January 07, 2014, 04:08:03 PM »
When using an Explicit Render Q on UIPanels that have more than one draw call causes some strange behavior that could probably be considered a bug. In short, both depth and z-value have to be set for things to draw correctly.

I have a few UISprites and a UITexture that draws on top of the sprites. In the past, all I had to do was set the z-value for the UITexture to be above the UISprites. Now, if the UITexture is above the UISprites, but it's depth is lower than any of the UISprites, none of the UISprites with a depth higher than the UITexture will draw. This was pretty difficult to figure out as a bunch of seeming unrelated UISprites simply disappeared when upgrading.

Similarly, if the UITexture has a depth higher than the UISprites, but the same z-value, it simply doesn't draw. All the UISprites with lower depths will show up.

So, in order to get UISprites and UITextures on the same UIPanel to all draw properly, you have to position all the UITextures on a different Z and set the depth on all the UITextures higher than the UISprites.

It seems like the relative depth of widgets in different draw calls should be ignored.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: 3.0.8 f7 UITexture Draw Order Oddity
« Reply #1 on: January 08, 2014, 01:14:11 PM »
"Explicit" means that all draw calls created by the panel will have their render queue value equals to the value you specified.

This means that just like in NGUI 2, draw order of draw calls is based on Z instead of depth.

AtomicBob

  • Jr. Member
  • **
  • Thank You
  • -Given: 3
  • -Receive: 0
  • Posts: 69
    • View Profile
Re: 3.0.8 f7 UITexture Draw Order Oddity
« Reply #2 on: January 08, 2014, 01:24:31 PM »
You would think. If you read what I wrote, however, you have to set both z and depth or things don't draw.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: 3.0.8 f7 UITexture Draw Order Oddity
« Reply #3 on: January 08, 2014, 01:26:50 PM »
With explicit mode, Depth controls the order of widgets within the panel. Z will control the order of draw calls. So yes, you need to set both.

AtomicBob

  • Jr. Member
  • **
  • Thank You
  • -Given: 3
  • -Receive: 0
  • Posts: 69
    • View Profile
Re: 3.0.8 f7 UITexture Draw Order Oddity
« Reply #4 on: January 08, 2014, 06:17:46 PM »
I'm getting some really crazy ordering behavior that definitely doesn't match how things worked, and worse doesn't seem to make sense at all. I like to think I've gotten pretty good with NGUI and have a good understanding of what's going on under the hood in most cases. My point is, I don't believe this is purely user error.

I'm trying my best to create some sort of simple way to reproduce this, but I'm realizing it's not consistent. It's almost non-deterministic from the users point of view. Depending on the order things are enabled or disabled, the outcome is completely different. Mind you, this is with depth and z-values set appropriately such that nothing is overlapping the the draw calls should be well defined. Further, the few times I have gotten it down to something reproducible in our own project, as soon as I try to copy it over to a new, smaller project so I can post it here, the problems stop.

My initial description of the problem isn't correct because it can't be easily reproduced. I believe it's a side effect of an underlying problem that I ended up in that situation. Unfortunately, as I said, it's been impossible to reproduce this reliably. The best information I have right now is that it seems to be related to the combination of using UITextures, Render Q set to Explicit and the algorithm for splitting up draw calls automatically. Whenever the UITextures are present, objects start disappearing. Sometimes things disappear after a completely different panel changes.

The main things I have been seeing:
  • When disabling and enabling widgets the order of draw calls changes.
  • When objects are enabled on one panel, objects on another panel disappear.
  • Several Unity crashes when playing with UIPanels.

Here's a short video with an example. Forgive the quality.

I'm been banging my head against the wall on this for hours and I'm still at a loss as to what the problem really is. I could really use some help to get to the bottom of this. I don't want to post my entire project on the forum, but I'm open to other ways to figure this out.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: 3.0.8 f7 UITexture Draw Order Oddity
« Reply #5 on: January 08, 2014, 09:50:08 PM »
I don't see any different Z values in your video. Same Z means Unity will randomly pick one object to be in front.

AtomicBob

  • Jr. Member
  • **
  • Thank You
  • -Given: 3
  • -Receive: 0
  • Posts: 69
    • View Profile
Re: 3.0.8 f7 UITexture Draw Order Oddity
« Reply #6 on: January 09, 2014, 12:03:27 PM »
z-values are set appropriately.

BackgroundFiller (UITexture)Material Az = 2depth = 0
Background (UITexture)Material Bz = 1depth = 1
All UISpritesMaterial Cz = 0depth = 2-10
Digits 0-7 (UITextures)Material Dz = -1depth = 11-18

AtomicBob

  • Jr. Member
  • **
  • Thank You
  • -Given: 3
  • -Receive: 0
  • Posts: 69
    • View Profile
Re: 3.0.8 f7 UITexture Draw Order Oddity
« Reply #7 on: January 09, 2014, 03:11:50 PM »
I finally managed to reproduce this in a small project. [link removed]. To see the issue, simply start disabling and reenabling Sprites or Textures. You'll see the draw order changing in strange ways. The z values are set appropriately, as are all the depths.

Stranger still, if you simply move all the widgets one unit closer to the camera (i.e. z => z-1) different things happen.
« Last Edit: January 09, 2014, 06:18:29 PM by ArenMook »

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: 3.0.8 f7 UITexture Draw Order Oddity
« Reply #8 on: January 09, 2014, 06:19:52 PM »
I am in Jamaica for a week, away from my office so I can't view your project here. Just a thought, but are you using perspective cameras? Unless the camera is orthographic, Z is going to behave differently based on the position on the screen due to the varying distance from the eye point to the center of the drawn object.

AtomicBob

  • Jr. Member
  • **
  • Thank You
  • -Given: 3
  • -Receive: 0
  • Posts: 69
    • View Profile
Re: 3.0.8 f7 UITexture Draw Order Oddity
« Reply #9 on: January 09, 2014, 06:34:44 PM »
Nope, I have the project set to 2D. Enjoy your vacation. Hopefully it's a relatively easy fix when you get time.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: 3.0.8 f7 UITexture Draw Order Oddity
« Reply #10 on: January 09, 2014, 06:38:44 PM »
You also posted NGUI's copyrighted source code in public...

AtomicBob

  • Jr. Member
  • **
  • Thank You
  • -Given: 3
  • -Receive: 0
  • Posts: 69
    • View Profile
Re: 3.0.8 f7 UITexture Draw Order Oddity
« Reply #11 on: January 09, 2014, 06:42:03 PM »
Apologies. Just trying to bring an issue to light.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: 3.0.8 f7 UITexture Draw Order Oddity
« Reply #12 on: January 09, 2014, 06:45:40 PM »
Next time please send me a private PM or an email to the link. Public forum, private content...

AtomicBob

  • Jr. Member
  • **
  • Thank You
  • -Given: 3
  • -Receive: 0
  • Posts: 69
    • View Profile
Re: 3.0.8 f7 UITexture Draw Order Oddity
« Reply #13 on: January 09, 2014, 06:47:28 PM »
Absolutely.