Author Topic: Odd text rendering issues with 3.0.6  (Read 13753 times)

skullthug

  • Newbie
  • *
  • Thank You
  • -Given: 7
  • -Receive: 0
  • Posts: 37
    • View Profile
Odd text rendering issues with 3.0.6
« on: November 25, 2013, 04:30:13 PM »
Using 3.0.6 f1 with Unity 4.2.2f1.
Was using 3.0.5 before this with no problems, but since upgrading to 3.0.6 I've been having all sorts of weird issues.

I'm having an issue with text blinking/flickering on iOS/Android devices only (runs perfectly fine in Editor)
http://youtu.be/XtlQGZyhbu4
If I switch back to 3.0.5 the issue goes away.

I'm also having an issue with text (placed in the world) being rendered through geometry now.
For example I have a door with some text on it:


If I move forward, with a wall to block the door, the text now appears even through the wall.

If I switch back to 3.0.5 the issue goes away.


Uh, was there a major restructuring done in 3.0.6 or something?

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Odd text rendering issues with 3.0.6
« Reply #1 on: November 25, 2013, 06:46:15 PM »
Curious, on all accounts. Especially text rendering through geometry. Nothing has changed in render queues. Try this... UIDrawCall, line 407:
  1. if (mClipping != Clipping.None) mMesh.RecalculateBounds();
Change it to simply:
  1. mMesh.RecalculateBounds();

skullthug

  • Newbie
  • *
  • Thank You
  • -Given: 7
  • -Receive: 0
  • Posts: 37
    • View Profile
Re: Odd text rendering issues with 3.0.6
« Reply #2 on: November 26, 2013, 05:17:39 PM »
Gave that a try, but no change unfortunately.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Odd text rendering issues with 3.0.6
« Reply #3 on: November 26, 2013, 09:24:56 PM »

skullthug

  • Newbie
  • *
  • Thank You
  • -Given: 7
  • -Receive: 0
  • Posts: 37
    • View Profile
Re: Odd text rendering issues with 3.0.6
« Reply #4 on: November 29, 2013, 06:20:17 AM »
Was following it loosely, but wasn't sure if it was the same thing.

Anywho, I got 3.0.6f6 and the odd blinking issue appears to be gone now. However the text rendering through geometry issue is still present.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Odd text rendering issues with 3.0.6
« Reply #5 on: November 29, 2013, 08:52:32 AM »
Text rendering through geometry.. NGUI draws things with render queues that begin at 3000 and go up from there (Transparent, Transparent +1, etc). How are your walls drawn?

skullthug

  • Newbie
  • *
  • Thank You
  • -Given: 7
  • -Receive: 0
  • Posts: 37
    • View Profile
Re: Odd text rendering issues with 3.0.6
« Reply #6 on: January 07, 2014, 02:10:50 PM »
Sorry I fell off the earth on this topic. I noticed this issue is still happening in the latest version (3.0.8 f6)

To answer your question the walls are drawn using a vertex lit shader.


  1. Shader "Custom/Baked Vertex Lighting/Vertex Lit Custom" {
  2.  
  3. Properties {
  4.     _Color ("Main Color", Color) = (1,1,1,1)
  5.     _Emission ("Emmisive Color", Color) = (0,0,0,0)
  6.     _MainTex ("Base (RGB)", 2D) = "white" {}
  7. }
  8. SubShader {
  9.         Pass {
  10.                 Fog { Mode Off }
  11.                 CGPROGRAM
  12.                 #pragma vertex vert
  13.                 #pragma fragment frag
  14.                 #include "UnityCG.cginc"
  15.                
  16.                 float4 _Color;
  17.                 float4 _Emission;
  18.                 float4 _GlobalTint;
  19.                 sampler2D _MainTex;
  20.                
  21.                 struct v2f {
  22.                         float4 pos : SV_POSITION;
  23.                         fixed4 color : COLOR;
  24.                         float2 uv : TEXCOORD0;
  25.                 };
  26.                
  27.                 float4 _MainTex_ST;
  28.                
  29.                 v2f vert (appdata_full v) {
  30.                         v2f o;
  31.                         o.pos = mul( UNITY_MATRIX_MVP, v.vertex );
  32.                         o.uv = TRANSFORM_TEX(v.texcoord, _MainTex);
  33.                         o.color = v.color;
  34.                         return o;
  35.                 }
  36.                
  37.                 fixed4 frag (v2f i) : COLOR0
  38.                 {
  39.                         half4 texCol = tex2D(_MainTex, i.uv);
  40.                         return saturate(texCol * ( i.color * 1.1 * _Color * _GlobalTint + _Emission)  );
  41.                         //1.1 is in there to brighten slightly, as the raw colors looked too dark
  42.                 }
  43.                 ENDCG
  44.         }
  45. }
  46.  
  47. SubShader {
  48.     Pass {
  49.         Material {
  50.                         Shininess [_Shininess]
  51.                         Specular [_SpecColor]
  52.                         Emission [_Emission]    
  53.         }      
  54.         ColorMaterial Emission
  55.         Lighting On
  56.         SeparateSpecular On
  57.                
  58.                 SetTexture [_MainTex] {
  59.                         constantColor [_GlobalTint]
  60.             Combine primary * constant, constant * primary
  61.         }
  62.                
  63.         SetTexture [_MainTex] {
  64.             Combine texture * previous, texture * previous
  65.         }
  66.         SetTexture [_MainTex] {
  67.             constantColor [_Color]
  68.             Combine previous * constant DOUBLE, previous * constant
  69.                        
  70.         }
  71.     }
  72. }
  73. Fallback " VertexLit", 1
  74. }
  75.  

skullthug

  • Newbie
  • *
  • Thank You
  • -Given: 7
  • -Receive: 0
  • Posts: 37
    • View Profile
Re: Odd text rendering issues with 3.0.6
« Reply #7 on: January 07, 2014, 07:24:48 PM »
I noticed there's a Render Q setting now available. I tried setting the "CORE" text panel to Explicit and changing the number. If it's set to 2000 it renders on top of everything, but if I set it to 1999 it gets rendered underneath everything (doesn't appear at all)

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Odd text rendering issues with 3.0.6
« Reply #8 on: January 08, 2014, 12:59:45 PM »
If your walls are static objects, they will all be batched into a single draw call. If they are not static objects, then Unity will batch them dynamically in an arbitrary fashion. I don't know enough about your scene to make a good suggestion, so I'm going to venture a guess and say that your walls are on render queue of 2000 as well. You should put them on RQ of 3000 (use a Transparent shader). RQ of 2000 is drawn front to back. It's not what you want.

skullthug

  • Newbie
  • *
  • Thank You
  • -Given: 7
  • -Receive: 0
  • Posts: 37
    • View Profile
Re: Odd text rendering issues with 3.0.6
« Reply #9 on: January 08, 2014, 01:48:10 PM »
The walls are not dynamic due to the fact that I alter the lighting in the game as time passes. This is also an iOS game so I'm weary of using a transparent shader for so many objects. I've also never really managed render queues before. Is there anything I can do that would help you get a clearer idea of what might be occurring? Is putting text in the environment (outside of the UI camera object structure) just not possible anymore?

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Odd text rendering issues with 3.0.6
« Reply #10 on: January 08, 2014, 01:52:39 PM »
As I said, NGUI 2 uses to draw everything with Render Queue of 3000. Now by default things begin with Render Queue of 3000 and go up from there -- 3001, 3002, etc. +1 for each new draw call. You can force this by adjusting the Render Q option on the UIPanel, but unless your walls and your text uses the same type of shader, it's up to Unity to determine what's in front of what. Solid objects are drawn front to back, sorted by Z distance to the camera. Transparent objects are drawn back to front. NGUI's shaders don't write to depth, which means that you should use a back-to-front shader (read: transparent).

skullthug

  • Newbie
  • *
  • Thank You
  • -Given: 7
  • -Receive: 0
  • Posts: 37
    • View Profile
Re: Odd text rendering issues with 3.0.6
« Reply #11 on: January 08, 2014, 05:28:53 PM »
I added Tags { "Queue"="Transparent"  } on the shader to see if the back-to-front would work out. Unfortunately it seems to just open a can of worms (and still didn't resolve the problem exactly), so I guess I'm stuck with 3.0.5.

skullthug

  • Newbie
  • *
  • Thank You
  • -Given: 7
  • -Receive: 0
  • Posts: 37
    • View Profile
Re: Odd text rendering issues with 3.0.6
« Reply #12 on: January 12, 2014, 05:35:43 AM »
Just a FYI, switching my fonts back to Bitmap fixed the odd drawing order problem.

skullthug

  • Newbie
  • *
  • Thank You
  • -Given: 7
  • -Receive: 0
  • Posts: 37
    • View Profile
Re: Odd text rendering issues with 3.0.6
« Reply #13 on: January 20, 2014, 04:01:56 PM »
Ello again. I felt it's worth mentioning that 3.0.8 f7‏ fixed the text drawing issue for dynamic fonts, for at least the most part.

The new problem now is that the text on this door asset disappears when entering the concave space of the mesh. I'm also not sure what's going on with the rendering position, as the text is so far offset from it's actual coordinates as well as the panel's (the white box outline).


Anyways, if it enters the concave space, the text jumps far behind the actual panel/text coordinates- i have the door mesh hidden in this example to show.



Any thoughts on this one?

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Odd text rendering issues with 3.0.6
« Reply #14 on: January 21, 2014, 01:31:50 AM »
The offset is a side-effect of you not using a UIRoot and high depth values. You can fix it by changing UIWidget.OnDrawGizmos to this:
  1.         void OnDrawGizmos ()
  2.         {
  3.                 if (isVisible && NGUITools.GetActive(this))
  4.                 {
  5.                         if (UnityEditor.Selection.activeGameObject == gameObject && showHandles) return;
  6.  
  7.                         Color outline = new Color(1f, 1f, 1f, 0.2f);
  8.  
  9.                         float adjustment = (root != null) ? 0.25f : 0.001f;
  10.                         Vector2 offset = pivotOffset;
  11.                         Vector3 center = new Vector3(mWidth * (0.5f - offset.x), mHeight * (0.5f - offset.y), -mDepth * adjustment);
  12.                         Vector3 size = new Vector3(mWidth, mHeight, 1f);
  13.  
  14.                         // Draw the gizmo
  15.                         Gizmos.matrix = cachedTransform.localToWorldMatrix;
  16.                         Gizmos.color = (UnityEditor.Selection.activeGameObject == cachedTransform) ? Color.white : outline;
  17.                         Gizmos.DrawWireCube(center, size);
  18.  
  19.                         // Make the widget selectable
  20.                         size.z = 0.01f;
  21.                         Gizmos.color = Color.clear;
  22.                         Gizmos.DrawCube(center, size);
  23.                 }
  24.         }