Author Topic: Material choice breaking dynamic fonts  (Read 5651 times)

Cwal

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 22
    • View Profile
Material choice breaking dynamic fonts
« on: January 06, 2014, 08:34:21 PM »
I just upgraded to the most recent version, and have encountered two errors.  When using 3d UI elements, labels aren't clipped by objects in the scene, but everything else is.  They are all dynamic.  If I assign them a material, they are clipped properly, but they become completely illegible, with each letter expanded into a blob.  Additionally, when the cameras are set up so that the UI camera only sees the UI and the main camera doesn't, nothing clips at all.  I feel like I'm probably missing something, but the only post I could find on the subject said to add a material, which hasn't helped.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Material choice breaking dynamic fonts
« Reply #1 on: January 06, 2014, 09:43:56 PM »
NGUI draw calls begin with render queue of 3000 and higher by default. This means that if your scene has transparent objects, chances are high that 3D UI elements will show up on top of them, even if they should be behind. Opaque objects should work fine. This happens because transparent objects don't write to depth.

You can force the render queue on each panel to a number of your choice, if necessary.

Cwal

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 22
    • View Profile
Re: Material choice breaking dynamic fonts
« Reply #2 on: January 07, 2014, 12:17:27 PM »
The labels are showing even through completely opaque objects as long as they don't have a material assigned, but assigning a material with a single pixel texture or no texture makes the text illegible.  I have tried playing with changing the depths of the involved cameras, but given some of the constraints I am dealing with, the GUI camera has to be at a higher depth than the game camera.

I've also tried moving the draw calls around in the queue with no effect.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Material choice breaking dynamic fonts
« Reply #3 on: January 08, 2014, 01:25:51 PM »
You should not be assigning a material to labels. The proper way of changing the render queue is on the UIPanel ("Render Q" field). Also note that the only way UI elements will be clipped by 3D objects is if they're drawn using the same camera.

Cwal

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 22
    • View Profile
Re: Material choice breaking dynamic fonts
« Reply #4 on: January 08, 2014, 09:09:30 PM »
I got the clipping working properly by setting the two cameras I am using to the same depth and giving the font a material with the texture from the ttf, although any attempt to use the font included in NGUI resulted in Unity massively slowing down.

Why is there a material slot on labels if it isn't intended to be used?

Also, how do I set up a secondary 2d portion of UI?  I need both elements in world space and elements that make up an on screen menu, and the option to have multiple UIs seems to have been removed, as the creation menu is grayed out once one is created.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Material choice breaking dynamic fonts
« Reply #5 on: January 08, 2014, 09:42:58 PM »
You can use the material, but you need to use a proper shader. Dynamic font textures only have the Alpha channel. RGB channels don't exist. You need a special shader to use those textures.

You should be using one camera, not two cameras. Get rid of one of the cameras. Setting the same depth won't do anything. It just means Unity will randomly pick one of the cameras to be drawn first.