Author Topic: Regular model in between NGUI layers?  (Read 17040 times)

schwarzenego

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 30
    • View Profile
Regular model in between NGUI layers?
« on: December 16, 2013, 05:39:16 PM »
Hello, how are you?

I've noticed that since NGUI 3.0 the Z vs Depth has changed quite a lot, which on one side I find good and on the other it is causing me a bit of trouble.

Truth is I dont use NGUI for everything HUD related in my scene. The extra drawcalls I get from using primitive shapes with textures sometimes compensate for the UIPanel.Update when things are moving, so I actually try to avoid using NGUI for (mostly) static stuff. However, the real problem is when I try to have something in the middle of NGUI sprites... I have a plane which gets a texture from Resources.Load (to use less memory and since it can be one in many images I cant have that on an Atlas), and it is a background image of an NGUI Popup. No problem there... however, there are a few NGUI elements that I wish were BEHIND this primitive plane... but since NGUI now ignores Z somehow, I dont know how to put this plane behind the NGUI popup and in front of the other NGUI HUD going behind...

Any ideas?

On the image bellow, I want the highlighted stuff behind the white plane.

kitgui

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 26
    • View Profile
Re: Regular model in between NGUI layers?
« Reply #1 on: December 16, 2013, 08:17:51 PM »
Have you tried using another separate NGUI camera and layer for the NGUI Popup?

schwarzenego

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 30
    • View Profile
Re: Regular model in between NGUI layers?
« Reply #2 on: December 17, 2013, 11:17:00 AM »
I havent but really, Id like to avoid doing that. I would need 3 cameras... one for the back GUI, one only for the plane, and one for the front GUI... or at least 2 with the plane on the popup Camera... I suppose that multiple cameras have some overhead on performance (to be honest Im not sure but I would guess so), and it would make a total of 3-4 cameras... for this specific case I dont think performance would be a problem, but I might need to do this in other scenarios where it is a problem... is there no solution to this?

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Regular model in between NGUI layers?
« Reply #3 on: December 17, 2013, 11:32:24 AM »
You can explicitly specify a render queue used by the panel's draw calls (specified on UIPanel), which is something you'd want to do in order to insert a 3D object into your UI.

I generally don't recommend this however. Rendering to texture then displaying that texture using UITexture is the better approach.

schwarzenego

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 30
    • View Profile
Re: Regular model in between NGUI layers?
« Reply #4 on: December 17, 2013, 11:40:24 AM »
Oh cool, I didnt knew UITexture at all...

In this specific case it does solve my problem, thank you. However, due to the overhead of UIPanel.Update I try to reduce the usage of widgets as much as I can (if im going to move them around and not change alpha/color (which I do using your Tween class)) for example, I have a kind of Talent Tree in my game where the user can navigate around, its more like a map than a tree... at first I was doing it fully with NGUI, background image, everything, but once the user moved around the map, the FPS decreased drastically due to UIPanel.Update. I then switched the background tiled sprite to a primitive plane with a tiled unlit texture, and a few other elements which I would not change at all... and performance drastically increased (from 10 to 60 fps on some devices)... What would be your counsel, was I doing something wrong in the first place or I should really avoid NGUI for some kind of stuff?

Well, once again thanks for your help.
Best regards,
Allan

schwarzenego

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 30
    • View Profile
Re: Regular model in between NGUI layers?
« Reply #5 on: December 17, 2013, 12:25:17 PM »
So... ran into this problem again, now with a shuriken particle... I want it to be behind some of the elements and ahead of others... and Im unable to place it correctly... Actually not even if I wanted it in front of other stuff, its just not possible...

By changing the Render Queue to "Start At" and using a low value, I can get the particle system ahead of NGUI elements, but then I suppose I would need 2 panels to have stuff on different render queue positions...

Usually I try to have panels as "layers", so if everything is roughly the same layer of hud they are all in the same panel... would you recommend having more panels and things more divided or only when needed for some reason?

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Regular model in between NGUI layers?
« Reply #6 on: December 17, 2013, 12:32:09 PM »
Yes, if you want to sandwich a particle system in between of UI elements, then you have no choice but to create more than one panel.

And looking at panels as layers is precisely the correct approach to take. Calling them "UI Layers" would actually be the more correct terminology... if I didn't have to worry about backwards compatibility, I'd change them. :)

schwarzenego

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 30
    • View Profile
Re: Regular model in between NGUI layers?
« Reply #7 on: December 17, 2013, 12:41:19 PM »
Alright, good to know im not doing EVERYTHING wrong =P

So, im trying to do something which is probably not the most recommended stuff but due to how my hierarchy is and how my scripts go, I have one panel for the general menu layer... what I am looking for is to have a particle that goes behind one of the buttons, but ahead of the buttom`s background frame. So, before, I had only one panel with a ton of stuff.

Now, since I make some tweenings of a lot of stuff, I wanted the buttons to stay in the same panel as the background, so I can tween em all together. Since I HAVE to add another panel for the sandwich, I just added a UIPanel to an empty game object, which holds the button. However, in the hierarchy it is a child of the original panel, basically one panel inside the other. Is this a problem?

Also, by toying with the Render Queue number of both panels... Ive noticed there is some stuff not even related to NGUI (my scenario model) that is actually changing... some misterious shadows are appearing out of nowhere by changing this number... and still I am not being able to have the particle in between the two panels, either its in front of everything or its behind everything... is it because I have a panel inside a panel?

And... should my scenario be changing based on the gui panel render queue? =P Man I gotta say... I am starting to miss my beloved Z axis...

Edit: Even taking the inside panel outside of the hierarchy of the first panel... I cant get the particle system behind one and ahead of the other panel... its either behind both or in front of both... as if the Render Queue was not by panel but by whole UI... by Camera... something like that...

Edit2: Ok, I managed to get the particle system behind one panel and ahead of another... problem was that ALL panels in the scene must be "Render Queue: Start At", or else they all just start at 3000 anyways. However....................... What if I need to play ANOTHER particle system, but this time ABOVE the buttom and everything? In other words... Panel -> Particles -> Panel -> Particles... is it even possible?
« Last Edit: December 17, 2013, 01:23:29 PM by schwarzenego »

schwarzenego

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 30
    • View Profile
Re: Regular model in between NGUI layers?
« Reply #8 on: December 18, 2013, 10:26:49 AM »
So... is it possible to have this:

NGUI -> Particle System -> NGUI -> Particle System?

Should I just row back to 2.7 (or whatever was the last 2.x version)?

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Regular model in between NGUI layers?
« Reply #9 on: December 18, 2013, 11:53:03 AM »
If you really want NGUI 3 to behave exactly as NGUI 2 and use Z for sorting, force your Render Queue on panels to 3000.

schwarzenego

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 30
    • View Profile
Re: Regular model in between NGUI layers?
« Reply #10 on: December 18, 2013, 12:33:18 PM »
Alright, setting all panels to Explicit 3000 worked great for the sorting I was looking for.

However.... now I can't get consistent results using the Depth of UISprites as in NGUI 2, by changing the values sometimes things completely switch positions, sometimes the depth has no effect... and I could just ignore depth and use Z for everything, but Z is having a weird effect on sorting for UISprites/Labels/Etc, by changing the Z of one sprite, other sprites disappear/reappear... so now Z works on NGUI vs Models, but depth and Z are broken for NGUI only components =/

Any thoughts?

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Regular model in between NGUI layers?
« Reply #11 on: December 18, 2013, 12:38:58 PM »
And this is precisely why I moved away from using Z in NGUI 3 -- too many sorting issues. If you're using explicit render queues, depth won't matter, and you're back to having to create extra panels and adjusting Z to make sure that things are drawn in the correct order. It's a mess, and is exactly why I canned this approach.

As I mentioned, your best bet is to do something like this:

Background Panel (RQ starting at 2600)
- Particle system (RQ 3000 by default)
-- Overlay panel (RQ starting at 3001)
--- Overlay particles (make a shader with RQ of 4000)

This ensures that the draw order will be correct. All other approaches will be more difficult.

Keep in mind, the difficulty here comes from the fact that you're mixing NGUI, which is depth-based, with a rendered object, which is Z-based. Different systems, so some difficulty is to be expected.

schwarzenego

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 30
    • View Profile
Re: Regular model in between NGUI layers?
« Reply #12 on: December 18, 2013, 03:06:07 PM »
I understand your point, I am an absolute noob at shaders so I guess Im rolling back to NGUI 2.

I just like to ask, isnt it somehow common to have particle effects over the UI? Isnt that possibly a problem? I mean, I use particles as a lot of things, clicking feedback, rewarding feedback, etc etc... I am the only one? Isnt it... well... important?

Anyway, thank you for your attention ArenMook, I wish I could use NGUI 3 but who knows at another time? Also, Id like to suggest over to you to add on to your tweening class a PingPongOnce, I always add it (its very simple), and its quite useful.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Regular model in between NGUI layers?
« Reply #13 on: December 18, 2013, 05:38:28 PM »
To have a ping pong once effect, change the curve so that it's shaped like an inverted U.

Changing the render queue inside the shader is a trivial thing. Download Unity's default shaders and look at the source of one of them -- such as "Particle Add" shader (Particles/Additive). Line #9 is the following:
  1. Tags { "Queue"="Transparent" "IgnoreProjector"="True" "RenderType"="Transparent" }
Change it to:
  1. Tags { "Queue"="Transparent+1000" "IgnoreProjector"="True" "RenderType"="Transparent" }
Explanation: "Transparent" is 3000 (consult Unity's docs). By adding +1000 to it, it effectively becomes 4000. You can now rename this shader to something like "Particles/My Additive", and have your own version to use for your particle emitter's material.

Learning the absolute basics of shaders like this is something you are going to have to do sooner or later, so reverting back to an archaic version of a UI system because you don't want to take the plunge is a strange decision.