Author Topic: How the UISprite to gray?  (Read 4257 times)

yiran

  • Newbie
  • *
  • Thank You
  • -Given: 3
  • -Receive: 0
  • Posts: 2
    • View Profile
How the UISprite to gray?
« on: November 26, 2014, 04:38:56 AM »
Hi,I Modify NGUI built-in Shader “Unlit/Transparent Colored”, Use it to make UISprite gray.
 
Code:
   fixed4 frag (v2f IN) : COLOR
   {
             fixed4 col = tex2D(_MainTex, IN.texcoord);
             col.rgb = dot(col.rgb, fixed3(.222,.707,.071));
             return col;
   }

Normal use there is no problem,But when UIPanel Use the Clipping function, An Error Has Occurred!

Error : Unlit/Transparent Colored gray shader doesn't have a clipped shader version for 1 clip regions

Or what better way to solve the problem?Thank you very much!

bac9

  • Full Member
  • ***
  • Thank You
  • -Given: 2
  • -Receive: 4
  • Posts: 113
    • View Profile
Re: How the UISprite to gray?
« Reply #1 on: November 26, 2014, 05:44:54 AM »
Look at the standard NGUI shaders, notice the postfixes like " 1" and " 2" in shader names, check the code that handles NGUI materials. As clipping is done through shaders, you must prepare clipping compatible duplicates of any custom shader you use in UI, and name them in the same way so that NGUI can find them.

I'm not sure I understand why would you want to use custom shaders at all, though. What's wrong with using standard vertex color driven coloration from NGUI tools?

yiran

  • Newbie
  • *
  • Thank You
  • -Given: 3
  • -Receive: 0
  • Posts: 2
    • View Profile
Re: How the UISprite to gray?
« Reply #2 on: November 26, 2014, 08:06:12 AM »
Look at the standard NGUI shaders, notice the postfixes like " 1" and " 2" in shader names, check the code that handles NGUI materials. As clipping is done through shaders, you must prepare clipping compatible duplicates of any custom shader you use in UI, and name them in the same way so that NGUI can find them.

I'm not sure I understand why would you want to use custom shaders at all, though. What's wrong with using standard vertex color driven coloration from NGUI tools?

Can you tell me where to use NGUI tools? Thank you very much

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: How the UISprite to gray?
« Reply #3 on: November 26, 2014, 08:29:35 PM »
He means changing the color of the sprite in inspector.

I also don't understand what you're trying to do there, or what the dot product is supposed to accomplish. Why would you dot product a color? That's ridiculously weird.

NGUI does clipping by replacing your shader with one that supports clipping. So if your shader is called "Yiran", then NGUI will try to find a shader called "Yiran 1" when it's time to do clipping. If you don't make that shader, there won't be any clipping. This is why NGUI has many versions of "Unlit - Transparent Colored" such as "Unlit - transparent Colored 1", etc.

BeShifty

  • Jr. Member
  • **
  • Thank You
  • -Given: 5
  • -Receive: 7
  • Posts: 52
    • View Profile
Re: How the UISprite to gray?
« Reply #4 on: November 26, 2014, 08:45:48 PM »
The shader renders the UI in grayscale. The (.222,.707,.071) is an empirical value often used to preserve more detail than simply averaging all 3 channels.