Author Topic: Texture fill in Label with Dynamic font  (Read 3286 times)

justjuank

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 2
    • View Profile
Texture fill in Label with Dynamic font
« on: September 01, 2014, 09:24:18 PM »
Hello everyone,
I have a Label using dynamic fonts and I need to set a texture instead of a solid color(tint) to the Label, is it possible?

I checked the Material option but it looks like is not meant for that or I'm not sure how to use it.

Any hints are greatly appreciated.

Thanks in advance,

Juan.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Texture fill in Label with Dynamic font
« Reply #1 on: September 02, 2014, 11:50:15 AM »
You can change the material used by the label. Make sure to specify the dynamic font's texture as the main texture. Secondary texture is up to you, as are secondary texture coordinates. NGUI doesn't provide any, so you will need to generate them from screen space or something similar.

justjuank

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 2
    • View Profile
Re: Texture fill in Label with Dynamic font
« Reply #2 on: September 02, 2014, 04:03:15 PM »
Thank you very much. I managed to finally fill the font color with my texture but now I have a problem:
I had to create a shader based on the GUI/Text shader code, just changed a few lines and got my texture in the font, the problem is that it's now affecting the Effects like "Outline" or "Shadow" check the screenshots attached.

The first screenshot has a red outline, and the second one has a white outline but as you can see it's mixing with the texture, so no white outlines allowed (same happnes with Shadow).

Can anyone give me a hand? I'm not a shader expert so here's the code:

(I placed a comment on the lines I added)

  1. Shader "Custom/TexturedText" {
  2.         Properties {
  3.                 _MainTex ("Font Texture", 2D) = "white" {}
  4.                 _DetailTex ("Detail Texture", 2D) = "white" {} //added by justjuank
  5.                 _Color ("Text Color", Color) = (1,1,1,1)
  6.         }
  7.  
  8.         SubShader {
  9.  
  10.                 Tags {
  11.                         "Queue"="Transparent"
  12.                         "IgnoreProjector"="True"
  13.                         "RenderType"="Transparent"
  14.                         "PreviewType"="Plane"
  15.                 }
  16.                 Lighting Off Cull Off ZTest Always ZWrite Off Fog { Mode Off }
  17.                 Blend SrcAlpha OneMinusSrcAlpha
  18.  
  19.                 Pass { 
  20.                         CGPROGRAM
  21.                         #pragma vertex vert
  22.                         #pragma fragment frag
  23.  
  24.                         #include "UnityCG.cginc"
  25.  
  26.                         struct appdata_t {
  27.                                 float4 vertex : POSITION;
  28.                                 fixed4 color : COLOR;
  29.                                 float2 texcoord : TEXCOORD0;
  30.                         };
  31.  
  32.                         struct v2f {
  33.                                 float4 vertex : POSITION;
  34.                                 fixed4 color : COLOR;
  35.                                 float2 texcoord : TEXCOORD0;
  36.                         };
  37.  
  38.                         sampler2D _MainTex;
  39.                         uniform float4 _MainTex_ST;
  40.                         uniform fixed4 _Color;
  41.                         sampler2D _DetailTex; //added by justjuank
  42.                        
  43.                         v2f vert (appdata_t v)
  44.                         {
  45.                                 v2f o;
  46.                                 o.vertex = mul(UNITY_MATRIX_MVP, v.vertex);
  47.                                 o.color = v.color * _Color;
  48.                                 o.texcoord = TRANSFORM_TEX(v.texcoord,_MainTex);
  49.                                 return o;
  50.                         }
  51.  
  52.                         fixed4 frag (v2f i) : COLOR
  53.                         {
  54.                                 fixed4 col = i.color;
  55.                                 col.rgb *= tex2D(_DetailTex, i.texcoord).rgb; //added by justjuank
  56.                                 col.a *= tex2D(_MainTex, i.texcoord).a;
  57.                                 return col;
  58.                         }
  59.                         ENDCG
  60.                 }
  61.         }
  62. }
  63.  


Not sure if this will ever work by modifying the frag function, I tried to modify the vert function to achieve the same but I failed since I have no idea.

Thanks

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Texture fill in Label with Dynamic font
« Reply #3 on: September 03, 2014, 11:21:00 AM »
The way outline and shadow effects are done is the text is drawn multiple times. There isn't much you can do about it.

Nicki

  • Global Moderator
  • Hero Member
  • *****
  • Thank You
  • -Given: 33
  • -Receive: 141
  • Posts: 1,768
    • View Profile
Re: Texture fill in Label with Dynamic font
« Reply #4 on: September 03, 2014, 04:09:05 PM »
Can't really do anything in shader, but you can create your own outline by using 4 labels in the color you want, offset x pixels in all 4 directions. Those labels should use the regular guitext shader.