Author Topic: Linear color space for UILabel effects  (Read 3034 times)

diederik

  • Newbie
  • *
  • Thank You
  • -Given: 1
  • -Receive: 2
  • Posts: 31
    • View Profile
Linear color space for UILabel effects
« on: October 08, 2015, 07:05:30 AM »
Hi all!

I was seeing some color inconsistencies when switching from gamme to linear color space.
So I came to the forum and saw there was some posts about how there's a fix using:

      if (QualitySettings.activeColorSpace == ColorSpace.Linear)
      {
         col.r = Mathf.GammaToLinearSpace(col.r);
         col.g = Mathf.GammaToLinearSpace(col.g);
         col.b = Mathf.GammaToLinearSpace(col.b);
         col.a = Mathf.GammaToLinearSpace(col.a);
      }

I've added this in a dirty hack to the ApplyShadow on the UILabel and it now seems to display those colors correctly as well.

@ArenMook: can you check if there are more places where the conversion needs to be implemented? Or is there some other fix that I'm not aware off?

Thanks in advance for your attention.

Diederik / Xform


ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Linear color space for UILabel effects
« Reply #1 on: October 10, 2015, 11:19:28 PM »
This seems like a valid change. I'll make it on my end as well, thanks.
  1.         public void ApplyShadow (BetterList<Vector3> verts, BetterList<Vector2> uvs, BetterList<Color32> cols, int start, int end, float x, float y)
  2.         {
  3.                 Color c = mEffectColor;
  4.                 c.a *= finalAlpha;
  5.                 if (bitmapFont != null && bitmapFont.premultipliedAlphaShader) c = NGUITools.ApplyPMA(c);
  6.  
  7.                 if (QualitySettings.activeColorSpace == ColorSpace.Linear)
  8.                 {
  9.                         c.r = Mathf.GammaToLinearSpace(c.r);
  10.                         c.g = Mathf.GammaToLinearSpace(c.g);
  11.                         c.b = Mathf.GammaToLinearSpace(c.b);
  12.                         c.a = Mathf.GammaToLinearSpace(c.a);
  13.                 }
  14.  
  15.                 Color32 col = c;
  16.  
  17.                 for (int i = start; i < end; ++i)
  18.                 {
  19.                         verts.Add(verts.buffer[i]);
  20.                         uvs.Add(uvs.buffer[i]);
  21.                         cols.Add(cols.buffer[i]);
  22.  
  23.                         Vector3 v = verts.buffer[i];
  24.                         v.x += x;
  25.                         v.y += y;
  26.                         verts.buffer[i] = v;
  27.  
  28.                         Color32 uc = cols.buffer[i];
  29.  
  30.                         if (uc.a == 255)
  31.                         {
  32.                                 cols.buffer[i] = col;
  33.                         }
  34.                         else
  35.                         {
  36.                                 Color fc = c;
  37.                                 fc.a = (uc.a / 255f * c.a);
  38.                                 if (QualitySettings.activeColorSpace == ColorSpace.Linear) fc.a = Mathf.GammaToLinearSpace(fc.a);
  39.                                 cols.buffer[i] = fc;
  40.                         }
  41.                 }
  42.         }