Author Topic: Again, but not working anyway. GrayScale shader for NGUI 3.8.2  (Read 2800 times)

jeffscm

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 1
  • Posts: 2
    • View Profile
Hi All!

I updated my NGUI from 3.5.x to the latest 3.8.2

I use a gray scale shader found here on this forum:

  1. Shader "Custom/GreyScale (AlphaClip)"
  2. {
  3.   Properties
  4.   {
  5.     _MainTex ("Base (RGB), Alpha (A)", 2D) = "white" {}
  6.     _AlphaTex ("MaskTexture", 2D) = "white" {}
  7.   }
  8.  
  9.   SubShader
  10.   {
  11.     LOD 500
  12.  
  13.     Tags{
  14.       "Queue" = "Transparent"
  15.       "IgnoreProjector" = "True"
  16.       "RenderType" = "Transparent"
  17.     }
  18.      Pass
  19.         {
  20.             Cull Off
  21.             Lighting Off
  22.             ZWrite Off
  23.             Offset -1, -1
  24.             Fog { Mode Off }
  25.             ColorMask RGB
  26.             Blend SrcAlpha OneMinusSrcAlpha
  27.  
  28.             CGPROGRAM
  29.             #pragma vertex vert
  30.             #pragma fragment frag
  31.             #include "UnityCG.cginc"
  32.  
  33.             sampler2D _MainTex;
  34.             float4 _MainTex_ST;
  35.             sampler2D _AlphaTex;
  36.  
  37.             struct appdata_t
  38.             {
  39.                 float4 vertex : POSITION;
  40.                 half4 color : COLOR;
  41.                 float2 texcoord : TEXCOORD0;
  42.             };
  43.  
  44.             struct v2f
  45.             {
  46.                 float4 vertex : POSITION;
  47.                 half4 color : COLOR;
  48.                 float2 texcoord : TEXCOORD0;
  49.                 float2 worldPos : TEXCOORD1;
  50.             };
  51.  
  52.             v2f vert (appdata_t v)
  53.             {
  54.                 v2f o;
  55.                 o.vertex = mul(UNITY_MATRIX_MVP, v.vertex);
  56.                 o.color = v.color;
  57.                 o.texcoord = v.texcoord;
  58.                 o.worldPos = TRANSFORM_TEX(v.vertex.xy, _MainTex);
  59.                 return o;
  60.             }
  61.  
  62.             half4 frag (v2f IN) : COLOR
  63.             {
  64.  
  65.                 half4 col = tex2D(_MainTex, IN.texcoord) * IN.color;
  66.                 half4 a2 = tex2D(_AlphaTex, IN.texcoord);
  67.  
  68.                 float2 factor = abs(IN.worldPos);
  69.                 float val = 1.0 - max(factor.x, factor.y);
  70.                  
  71.                 if (val < 0.0) col.a = 0.0;
  72.                 if (a2.a < col.a) col.a = a2.a;
  73.                 col.rgb = dot(col.rgb, float3(0.3, 0.3, 0.4));
  74.  
  75.                 return col;
  76.             }
  77.             ENDCG
  78.         }
  79.   }
  80. }
  81.                
  82.  

But now it doesn't work anymore.

Anyone faced this problem too?

Any help will be highly appreciated!

Regards

Jefferson

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Again, but not working anyway. GrayScale shader for NGUI 3.8.2
« Reply #1 on: May 22, 2015, 04:08:09 PM »
It's your fragment shader code, and the absence of _Alpha texture. Getting rid of all the "ifs" in there works fine.
  1.             half4 frag (v2f IN) : COLOR
  2.             {
  3.  
  4.                 half4 col = tex2D(_MainTex, IN.texcoord) * IN.color;
  5.                 col.rgb = dot(col.rgb, float3(0.3, 0.3, 0.4));
  6.                 return col;
  7.             }