Tasharen Entertainment Forum

Support => NGUI 3 Support => Topic started by: alexhy on July 13, 2017, 01:24:44 AM

Title: "soft clip" or "texture mask" option in UIPanel make the material become invalid
Post by: alexhy on July 13, 2017, 01:24:44 AM
If I choose "soft clip" or "texture mask" option in UIPanel,the material in UI2DSprite or UITexture under the UIPanel will lost his effect,such as gray effect.
the NGUI Version is newest 3.11.4
Title: Re: "soft clip" or "texture mask" option in UIPanel make the material become invalid
Post by: alexhy on July 13, 2017, 01:28:24 AM
my gray shader:
Shader "FragShader/Gray" {
   Properties {      
      _MainTex ("Albedo (RGB)", 2D) = "white" {}      
   }
   SubShader {

      Blend SrcAlpha OneMinusSrcAlpha

      pass
      {
         CGPROGRAM
         #pragma vertex vert
         #pragma fragment frag
         #include "UnityCG.cginc"
         

         sampler2D _MainTex;
         float4 _MainTex_ST;
         struct v2f {
            float4  pos : POSITION;
            float2  uv : TEXCOORD0;
         } ;


         v2f vert(appdata_base v)
         {         
            v2f o;
            o.pos = mul(UNITY_MATRIX_MVP,v.vertex); //顶点3D坐标转换为屏幕2D坐标
            o.uv = TRANSFORM_TEX(v.texcoord,_MainTex); //计算tile和offset            
            return o;
         }
         float4 frag(v2f i) : COLOR
         {
            float4 texCol = tex2D(_MainTex,i.uv); //从uv坐标获取贴图对应位置的像素颜色         
            
            //to gray
            float4 total= texCol[0] * 0.3 + texCol[1] * 0.4 + texCol[2]* 0.3;
            texCol[0]=total;
            texCol[1]=total;
            texCol[2]=total;
            
            float4 outp = texCol;         
            return outp;
         }
         ENDCG         
      }
   }
   FallBack "Diffuse"
}
Title: Re: "soft clip" or "texture mask" option in UIPanel make the material become invalid
Post by: alexhy on July 13, 2017, 01:32:38 AM
If I choose "none" option in UIPanel,the UI2dSprite's gray material will be available.
Title: Re: "soft clip" or "texture mask" option in UIPanel make the material become invalid
Post by: alexhy on July 13, 2017, 08:45:52 PM
I have found solution,add shader like Unlit - Transparent Colored (SoftClip).shader.
Title: Re: "soft clip" or "texture mask" option in UIPanel make the material become invalid
Post by: ArenMook on July 15, 2017, 06:39:01 AM
Yes, NGUI does clipping by replacing the shader, so if you have a custom shader you will need to have a custom clipped version of it as well.