Author Topic: 2.6.1 - Dynamic Fonts - Changing the Material  (Read 9933 times)

Ferazel

  • Full Member
  • ***
  • Thank You
  • -Given: 1
  • -Receive: 2
  • Posts: 150
    • View Profile
2.6.1 - Dynamic Fonts - Changing the Material
« on: May 06, 2013, 11:20:00 AM »
Sorry if I missed this, or even if this is possible or not. I'm switching over to dynamic fonts in 2.6.1. However, I'm running into a problem. I want to use a custom shader for the dynamic font that uses backface culling. It seems that Unity automatically creates a material and texture object in the project hierarchy when the .ttf font is set to dynamic.

I created a new material, and set the texture property on the material to the texture that the dynamic font generates. Regardless if I drag and drop or select the new material, the UIFont automatically resets back to the Unity Dynamic font material. Is there a reason why this behavior is not allowed? Is there something that I'm missing?

Seems like if we can't use a different material/shader than the default one, dynamic fonts are significantly less useful.

Nicki

  • Global Moderator
  • Hero Member
  • *****
  • Thank You
  • -Given: 33
  • -Receive: 141
  • Posts: 1,768
    • View Profile
Re: 2.6.1 - Dynamic Fonts - Changing the Material
« Reply #1 on: May 06, 2013, 12:26:27 PM »
You can. You just have to make your own material and use the generated texture from the font inside that.

Ferazel

  • Full Member
  • ***
  • Thank You
  • -Given: 1
  • -Receive: 2
  • Posts: 150
    • View Profile
Re: 2.6.1 - Dynamic Fonts - Changing the Material
« Reply #2 on: May 06, 2013, 12:38:59 PM »
Hi Nicki, that's what I tried, but the NGUI UIFont doesn't appear to accept the new material. I have attached some screenshots. Have you tried to do this under 2.6.1 and it works properly?

Irin1178

  • Guest
Re: 2.6.1 - Dynamic Fonts - Changing the Material
« Reply #3 on: May 06, 2013, 03:47:48 PM »
I tracked this issue down to the material property in UIFont.cs

Summary: There is some special case code in the get that handles dynamic fonts, but there was not logic in the set for that same special case. I simply added the extra else if at the end there.

code:
  1. public Material material
  2. {
  3.         get
  4.         {
  5.                 if (mReplacement != null) return mReplacement.material;
  6.  
  7.                 if (isDynamic)
  8.                 {
  9.                         if (mMat != null) mMat.mainTexture = mDynamicFont.material.mainTexture;
  10.                         return mDynamicFont.material;
  11.                 }
  12.                 return (mAtlas != null) ? mAtlas.spriteMaterial : mMat;
  13.         }
  14.         set
  15.         {
  16.                 if (mReplacement != null)
  17.                 {
  18.                         mReplacement.material = value;
  19.                 }
  20.                 else if (mAtlas == null && mMat != value)
  21.                 {
  22.                         mPMA = -1;
  23.                         mMat = value;
  24.                         MarkAsDirty();
  25.                 }
  26.                 else if (isDynamic && mDynamicFont.material != value)
  27.                 {
  28.                         mDynamicFont.material = value; 
  29.                         MarkAsDirty();
  30.                 }                      
  31.         }
  32. }
  33.  

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: 2.6.1 - Dynamic Fonts - Changing the Material
« Reply #4 on: May 06, 2013, 04:06:54 PM »
And that works fine without any issues? Font's material is not something you can change on the TTF font itself, which is why I didn't include a setter for it. The correct change would be:
  1.                         else if (mMat != value)
  2.                         {
  3.                                 mPMA = -1;
  4.                                 mMat = value;
  5.                                 MarkAsDirty();
  6.                         }

Irin1178

  • Guest
Re: 2.6.1 - Dynamic Fonts - Changing the Material
« Reply #5 on: May 06, 2013, 06:49:05 PM »
ah, i wasn't sure about the premultiplied alpha line, so i did not include it in my post. Thanks for the correction

maoguo.zhang

  • Guest
Re: 2.6.1 - Dynamic Fonts - Changing the Material
« Reply #6 on: May 06, 2013, 11:05:26 PM »
Sorry! I also need to change the font's material. Could you tell me whether my change is correct?

   public Material material
   {
      get
      {
         if (mReplacement != null) return mReplacement.material;

         if (isDynamic)
         {
            if (mMat != null) mMat.mainTexture = mDynamicFont.material.mainTexture;
            return mDynamicFont.material;
         }
         return (mAtlas != null) ? mAtlas.spriteMaterial : mMat;
      }
      set
      {
         if (mReplacement != null)
         {
            mReplacement.material = value;
         }
         else if (mMat != value)
         {
            mPMA = -1;
            mMat = value;
            MarkAsDirty();
         }
         else if (isDynamic && mDynamicFont.material != value)
           {
               mDynamicFont.material = value;   
               MarkAsDirty();
           }
      }
   }

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: 2.6.1 - Dynamic Fonts - Changing the Material
« Reply #7 on: May 06, 2013, 11:15:09 PM »
Just update, it's already a part of 2.6.1b.

galuodo

  • Jr. Member
  • **
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 65
    • View Profile
Re: 2.6.1 - Dynamic Fonts - Changing the Material
« Reply #8 on: May 07, 2013, 12:26:12 AM »
Just update, it's already a part of 2.6.1b.

Is it possible that we can set the filter either?

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: 2.6.1 - Dynamic Fonts - Changing the Material
« Reply #9 on: May 07, 2013, 12:28:44 AM »
I don't understand the question.

galuodo

  • Jr. Member
  • **
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 65
    • View Profile
Re: 2.6.1 - Dynamic Fonts - Changing the Material
« Reply #10 on: May 07, 2013, 12:59:07 AM »
the filter mode of texture of font's
Text shows well in point mode

maoguo.zhang

  • Guest
Re: 2.6.1 - Dynamic Fonts - Changing the Material
« Reply #11 on: May 07, 2013, 04:07:19 AM »
Just update, it's already a part of 2.6.1b.

I got 2.6.1c. But the isse which was raised by Ferazel still exists. Is there anything that I'am mising?

maoguo.zhang

  • Guest
Re: 2.6.1 - Dynamic Fonts - Changing the Material
« Reply #12 on: May 07, 2013, 10:43:31 PM »
Only I have this problem? :(

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: 2.6.1 - Dynamic Fonts - Changing the Material
« Reply #13 on: May 08, 2013, 02:06:19 AM »
It seems it's still broken in C. I will fix it in D.

ganqiang87

  • Guest
Re: 2.6.1 - Dynamic Fonts - Changing the Material
« Reply #14 on: May 08, 2013, 06:03:18 AM »
Use dynamic font, a large number of Chinese when the android will be messy.But are good for the win and ios
can you fix it?
you can see  one is ok,Another is not ok