title: Unity3D - Shader for sprite clipping
body: <p>I am trying to create a shader that can be used to clip 2D sprites in a game, I found this shader in  <a href="https://stackoverflow.com/questions/16397023/unity3d-a-shader-that-will-clip-a-texture-on-ios-device">another question</a></p>
  
  <pre><code>Shader "Sprites/ClipArea"
  {
  Properties
  {
      _MainTex ("Base (RGB), Alpha (A)", 2D) = "white" {}
      _Length ("Length", Range(0.0, 1.0)) = 1.0
      _Width ("Width", Range(0.0, 1.0)) = 0.5
   }
  
  SubShader
  {
      LOD 200
  
      Tags
      {
          "Queue" = "Transparent"
          "IgnoreProjector" = "True"
          "RenderType" = "Transparent"
      }
  
      Pass
      {
          Cull Off
          Lighting Off
          ZWrite Off
          Offset -1, -1
          Fog { Mode Off }
          ColorMask RGB
          Blend SrcAlpha OneMinusSrcAlpha
  
          CGPROGRAM
          #pragma vertex vert
          #pragma fragment frag
  
          #include "UnityCG.cginc"
  
          sampler2D _MainTex;
          float4 _MainTex_ST;
          float _Length;
          float _Width;
  
          struct appdata_t
          {
              float4 vertex : POSITION;
              float2 texcoord : TEXCOORD0;
          };
  
          struct v2f
          {
              float4 vertex : POSITION;
              float2 texcoord : TEXCOORD0;
          };
  
          v2f vert (appdata_t v)
          {
              v2f o;
              o.vertex = mul(UNITY_MATRIX_MVP, v.vertex);
              o.texcoord = v.texcoord;
              return o;
          }
  
          half4 frag (v2f IN) : COLOR
          {
              if ((IN.texcoord.x&lt;0) || (IN.texcoord.x&gt;_Width) || (IN.texcoord.y&lt;0) || (IN.texcoord.y&gt;_Length))
  
              {
                  half4 colorTransparent = half4(0,0,0,0) ;
                  return  colorTransparent ;
              }
              return tex2D(_MainTex, IN.texcoord);
          }
          ENDCG
      }
  }
  }
  </code></pre>
  
  <p>which works perfectly on single sprites, but I am using sprite sheets, divided by Unity Sprite editor.</p>
  
  <p>The _Width variable in the shader is covering the whole sprite sheet, not the sprite I am working on. I searched for a way to get the current sprite rect inside the shader but couldnt find anything.</p>