Author Topic: Dynamic font always in front  (Read 7027 times)

hjbaard

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 9
    • View Profile
Dynamic font always in front
« on: November 28, 2013, 09:05:25 AM »
Hi,
I don't if it's a bug in the latest version but I use dynamic fonts for labels and it appears always in front.
I've added 2 screenshots to make it clear.

What is going wrong here?

npritchard

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 17
    • View Profile
Re: Dynamic font always in front
« Reply #1 on: November 28, 2013, 10:04:18 AM »
Camera rendering order?

Check the 'Depth' component on the standard Unity Camera class. Perhaps your UI camera should be set to a lower depth than the camera rendering your 3D world.

hjbaard

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 9
    • View Profile
Re: Dynamic font always in front
« Reply #2 on: November 28, 2013, 10:23:42 AM »
Camera rendering order?

Check the 'Depth' component on the standard Unity Camera class. Perhaps your UI camera should be set to a lower depth than the camera rendering your 3D world.

I've tried to change that but nothing happened. Also keep in mind that only the dynamic font text is in front. The rest of the NGUI elements are in the right depth (see screenshot of the butten background sprites).

npritchard

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 17
    • View Profile
Re: Dynamic font always in front
« Reply #3 on: November 28, 2013, 10:30:14 AM »
Yes sorry I see now... not sure then.

I've had this kind of problem in older versions (2.6 I think) where, depending on which UILabel happened to be rendered first, it's depth (taken from Z position in the transform) would be applied to all subsequent labels within that panel. Not sure how this applies to 3.0+ as I haven't encountered it.

You could try throwing a panel onto their shared parent and see if that has any effect.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Dynamic font always in front
« Reply #4 on: November 28, 2013, 02:23:39 PM »
Check the shader used by the dynamic font. Did you specify some custom one or did you move the shaders that come with NGUI from their original location in the Resources folder?

hjbaard

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 9
    • View Profile
Re: Dynamic font always in front
« Reply #5 on: November 29, 2013, 02:26:34 AM »
Check the shader used by the dynamic font. Did you specify some custom one or did you move the shaders that come with NGUI from their original location in the Resources folder?

I didn't do anything with the shaders. I just imported NGUI and selected Arial as Dynamic font (it was already available).

Update:
To be sure I added the Arial.ttf to Unity to see if this makes any difference, but the result is the same. Also I've tried another font but is didn't matter.
The shader it uses is GUI/Text Shader
« Last Edit: November 29, 2013, 02:44:35 AM by hjbaard »

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Dynamic font always in front
« Reply #6 on: November 29, 2013, 09:30:08 AM »
The way NGUI draws things is by placing them on depth of 3000 and higher. So if you happen to draw a transparent object with the UI camera, its placement is going to be undetermined. You shouldn't be drawing non-UI objects with your UI camera. If you do, make sure they are using a shader that's using a higher render queue. Can I ask what you're trying to do with your UI there, and why you have that image drawn without using UITexture to do so?

hjbaard

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 9
    • View Profile
Re: Dynamic font always in front
« Reply #7 on: November 29, 2013, 02:43:25 PM »
The way NGUI draws things is by placing them on depth of 3000 and higher. So if you happen to draw a transparent object with the UI camera, its placement is going to be undetermined. You shouldn't be drawing non-UI objects with your UI camera. If you do, make sure they are using a shader that's using a higher render queue. Can I ask what you're trying to do with your UI there, and why you have that image drawn without using UITexture to do so?

I don't think I understand. I have a monitor in my scene and I'm using NGUI for the 'screens' on that monitor.
So I added a UICamera script to my main camera (just as you suggested when I bought NGUI a couple of month ago).

This is the structure of the monitor:
- GameObject monitor
   - UIRoot
      - UIPanel
         - Empty GameObject
             - UIButton
                - UISprite
                - UILabel
             - UIButton
                - UISprite
                - UILabel

etc.

The UILabel has a Dynamic font (Arial).
This worked fine until now. I've updated to 3.0.6f6 and now only the dynamic fonts are in front of everything else.
I don't have any transparent objects in front of the monitor in the scene.

But if I understand you correctly I can't do this setup anymore? Or is the Dynamic font the only problem in this setup?


ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Dynamic font always in front
« Reply #8 on: November 29, 2013, 07:39:23 PM »
Which version did you update from? This particular behaviour hasn't changed since 3.0.2 I think. NGUI stuff will appear on top if your shaders don't write to depth. So for example if your wall is drawn using a transparent shader, then NGUI will show up on top of it. What shader are they using?

hjbaard

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 9
    • View Profile
Re: Dynamic font always in front
« Reply #9 on: November 30, 2013, 05:23:00 AM »
Which version did you update from? This particular behaviour hasn't changed since 3.0.2 I think. NGUI stuff will appear on top if your shaders don't write to depth. So for example if your wall is drawn using a transparent shader, then NGUI will show up on top of it. What shader are they using?

You mean what shader is the dynamic font using?
The is the default shader if you import a ttf font in unity: GUI/Text Shader

But I can't (or don't know how to) change this shader.... :-\

UPDATE: I've got it working! I used the Dynamic Arial font. Created a new material with the Unlit/Text shader and the texture in the imported ttf font and added the material to the UILabel scripts (one by one).
Now its working the way I want it to work :-)
« Last Edit: November 30, 2013, 06:13:46 AM by hjbaard »