Author Topic: Custom Multiply shader with Soft clipping panel  (Read 10140 times)

amal_sh

  • Newbie
  • *
  • Thank You
  • -Given: 1
  • -Receive: 0
  • Posts: 2
    • View Profile
Custom Multiply shader with Soft clipping panel
« on: April 09, 2014, 08:06:22 AM »
I'm trying to create multiply shader to be used in panel list item the shader work fine without scrolling but when I scroll the list the clipped parts of the shown items are still visible and I can't understand why

here is the shader I use its taken from Mobile/Particles/Multiply from unity I want to make it work with the scrolling list

Shader "Custom/CustomMultiply" {
   Properties {
   _MainTex ("Particle Texture", 2D) = "white" {}
}

Category {
   Tags { "Queue"="Transparent" "IgnoreProjector"="True" "RenderType"="Transparent" }
   Blend Zero SrcColor
   Cull Off Lighting Off ZWrite Off Fog { Mode Off }
   
   BindChannels {
      Bind "Color", color
      Bind "Vertex", vertex
      Bind "TexCoord", texcoord
   }
   
   SubShader {
      
      Pass {
         SetTexture [_MainTex] {
            combine texture * primary
         }
         SetTexture [_MainTex] {
            constantColor (1,1,1,1)
            combine previous lerp (previous) constant
         }
      }
   }
}
}

Nicki

  • Global Moderator
  • Hero Member
  • *****
  • Thank You
  • -Given: 33
  • -Receive: 141
  • Posts: 1,768
    • View Profile
Re: Custom Multiply shader with Soft clipping panel
« Reply #1 on: April 09, 2014, 08:49:42 AM »
So, NGUI does clipping in the shader. Since you've put in your own custom shader, it doesn't account for clipping. Take a look at the Transparent Alpha (softclip) shader, to see what it does to clip.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Custom Multiply shader with Soft clipping panel
« Reply #2 on: April 10, 2014, 08:01:45 AM »
I think Nicki meant the "Unlit - Transparent Colored 1" shader. ;) That's the shader for a single clip rect.

amal_sh

  • Newbie
  • *
  • Thank You
  • -Given: 1
  • -Receive: 0
  • Posts: 2
    • View Profile
Re: Custom Multiply shader with Soft clipping panel
« Reply #3 on: April 17, 2014, 10:09:13 AM »
I don't understand much about shaders but I looked at Unlit/Transparent Colored (SoftClip) and I changed my shader to use vertix and fragment

the code below is the one responsible for clipping
// Softness factor
   float2 factor = abs(IN.worldPos);
   float val = 1.0 - max(factor.x, factor.y);
   if (val < 0.0) col.a = 0.0;

and this one is responsible for multiply
col = lerp(half4(1,1,1,1), col, col.a);

and I have no clue how to combine the two to work together the last one make its effect either multiply or mask

this is the full current version

Properties
      {
          _MainTex ("Particle Texture", 2D) = "white" {}
      }

      Category {
         
          Blend Zero SrcColor
           
          BindChannels {
              Bind "Color", color
              Bind "Vertex", vertex
              Bind "TexCoord", texcoord
          }

          // ---- Fragment program cards
          SubShader {
                LOD 200
                
                 Tags { "Queue"="Transparent500" "IgnoreProjector"="True" "RenderType"="Transparent" }
              Pass {
             
              Cull Off
               Lighting Off
                ZWrite Off
                Offset -1, -1
              // Fog { Color (1,1,1,1) }
              Fog { Mode Off }
              ColorMask RGB
             
         AlphaTest Greater .1
         Blend SrcAlpha OneMinusSrcAlpha
             
                  CGPROGRAM
                  #pragma vertex vert
                  #pragma fragment frag
                  #pragma fragmentoption ARB_precision_hint_fastest

                  #include "UnityCG.cginc"

                  sampler2D _MainTex;
                  float4 _TintColor;
                  float4 _MainTex_ST;
                  float2 _ClipSharpness = float2(20.0, 20.0);

                  struct appdata_t {
                      float4 vertex : POSITION;
                      float4 color : COLOR;
                      float2 texcoord : TEXCOORD0;
                  };

                  struct v2f {
                      float4 vertex : POSITION;
                      float4 color : COLOR;
                      float2 texcoord : TEXCOORD0;
                      //amal
                      float2 worldPos : TEXCOORD1;
                  };

                  v2f vert (appdata_t v)
                  {
                      v2f o;
                      o.vertex = mul(UNITY_MATRIX_MVP, v.vertex);
                      o.color = v.color;
                      o.texcoord = TRANSFORM_TEX(v.texcoord,_MainTex);
                     
                      o.worldPos = TRANSFORM_TEX(v.vertex.xy, _MainTex);
                      return o;
                  }

                  half4 frag (v2f IN) : COLOR
                  {      
                  // Sample the texture
                  half4 col = IN.color * tex2D(_MainTex, IN.texcoord);
                  col = lerp(half4(1,1,1,1), col, col.a);
                  // Softness factor
                  float2 factor = abs(IN.worldPos);
                  float val = 1.0 - max(factor.x, factor.y);
                  if (val < 0.0) col.a = 0.0;
                  return col;
                  }
                  ENDCG
              }
          }

          // ---- Dual texture cards
          SubShader {
              Pass {
                  SetTexture [_MainTex] {
                      combine texture * primary
                  }
                  SetTexture [_MainTex] {
                      constantColor (1,1,1,1)
                      combine previous lerp (previous) constant
                  }
              }
          }

          // ---- Single texture cards (does not do particle colors)
          SubShader {
              Pass {
                  SetTexture [_MainTex] {
                      constantColor (1,1,1,1)
                      combine texture lerp(texture) constant
                  }
              }
          }
      }

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Custom Multiply shader with Soft clipping panel
« Reply #4 on: April 17, 2014, 01:13:50 PM »
Unlit/Transparent Colored (SoftClip) doesn't exist anymore. You need to update your NGUI...