Author Topic: UIlabels and alpha - shader problem?  (Read 23384 times)

Nicki

  • Global Moderator
  • Hero Member
  • *****
  • Thank You
  • -Given: 33
  • -Receive: 141
  • Posts: 1,768
    • View Profile
UIlabels and alpha - shader problem?
« on: April 18, 2012, 05:32:19 AM »
When you change the alpha on a text, for instance to fade it out, it tends to fade towards black before alpha-ing out. It does the same on scrollviews with soft clipping.

The actualy color value on the UILabel is still white, but it looks dark grey, no matter the background, that is, it's not fading into the background color. The font atlas I'm using, uses the Unlit/Transparent Colored shader. Is this something you have seen as well? Is there a possible fix to it? (I'm not very good at shaders).

I can post a few pictures to show you as well.

Nicki

  • Global Moderator
  • Hero Member
  • *****
  • Thank You
  • -Given: 33
  • -Receive: 141
  • Posts: 1,768
    • View Profile
Re: UIlabels and alpha - shader problem?
« Reply #1 on: April 18, 2012, 05:43:04 AM »



ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: UIlabels and alpha - shader problem?
« Reply #2 on: April 18, 2012, 06:51:03 AM »
I fixed this issue weeks ago. I just did a quick check -- outline option on text, faded the main color's alpha, and it affects the outline's color properly.

Nicki

  • Global Moderator
  • Hero Member
  • *****
  • Thank You
  • -Given: 33
  • -Receive: 141
  • Posts: 1,768
    • View Profile
Re: UIlabels and alpha - shader problem?
« Reply #3 on: April 18, 2012, 06:57:13 AM »
Strange.

I think it alphas the outline fine here too, but the actual white text itself just turns grey and only starts blending with the color below 60(/255).

When I turn off the outline, it fades the white as it should. '

It has the same issue with Shadow effect on, but less pronouced - it starts fading properly at around 130-150 (/255).

I'm using the newest (or not the one from today, next-newest version) so it should be fixed here as well :S

What did you do to fix it back then?

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: UIlabels and alpha - shader problem?
« Reply #4 on: April 18, 2012, 07:07:28 AM »
Before the background was not affected by the main color's alpha. I think what you're seeing is just the effect of blending here. To do the outline, the text is drawn 5 times, offset by a pixel each time. It's why I don't recommend using the outline much. For the shadow it's the same, but text is drawn twice. In case of the outline, the text is drawn 4 times using the background color, then the foreground is slapped on top. Since there are 4 times as many background pixels applied as there are foreground, what you see is foreground being drowned in the background.

Nicki

  • Global Moderator
  • Hero Member
  • *****
  • Thank You
  • -Given: 33
  • -Receive: 141
  • Posts: 1,768
    • View Profile
Re: UIlabels and alpha - shader problem?
« Reply #5 on: April 18, 2012, 07:20:57 AM »
Ah nuts. Ok, I gotta see if I can find a smart solution to it then.

newnixon

  • Guest
Re: UIlabels and alpha - shader problem?
« Reply #6 on: April 25, 2012, 03:42:25 PM »
Hey guys I am trying to alpha a label to certain percent once you click an object. What code do I use for that?

Nicki

  • Global Moderator
  • Hero Member
  • *****
  • Thank You
  • -Given: 33
  • -Receive: 141
  • Posts: 1,768
    • View Profile
Re: UIlabels and alpha - shader problem?
« Reply #7 on: April 25, 2012, 03:48:26 PM »
Have a reference to you UILabel in your code and just use the property alpha.

Like so

  1. public UILabel myLabel;
  2.  
  3. public void myClick()
  4. {
  5.    myLabel.alpha = 0.5f;
  6. }
  7.  

or something similar.

All UIWidgets have alpha that you can set, it just works less good if you use shadow or outline on labels.