Author Topic: "soft clip" or "texture mask" option in UIPanel make the material become invalid  (Read 125 times)

alexhy

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 4
    • View Profile
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

alexhy

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 4
    • View Profile
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"
}

alexhy

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 4
    • View Profile
If I choose "none" option in UIPanel,the UI2dSprite's gray material will be available.

alexhy

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 4
    • View Profile
I have found solution,add shader like Unlit - Transparent Colored (SoftClip).shader.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 307
  • -Receive: 1144
  • Posts: 21,985
  • Toronto, Canada
    • View Profile
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.