title: Add alpha support to fragment shader (GLSL)
body: <p>I got the code from <a href="http://unitycoder.com/blog/2012/01/20/wipe-transition-shader/" rel="nofollow noreferrer">here</a>. This shader cycles through 2 textures over time, with a "wipe" effect (see source for a demo). Now that I've learned and kind of understand most of it, I'm trying to change it to be able to use textures with alpha.</p>
  
  <p>Here's the shader code :</p>
  
  <pre><code>Shader "Wipe" {
  
  Properties{
      _tex0 ("Texture1", 2D) = "white" {}
      _tex1 ("Texture2", 2D) = "white" {}
  }
  
  SubShader{
      Tags {"Queue"="Geometry"}
  
      Pass{
      CGPROGRAM
      #pragma target 3.0
      #pragma vertex vert
      #pragma fragment frag
      #include "UnityCG.cginc"
  
      sampler2D _tex0;
      sampler2D _tex1;
      float4 _tex0_ST;
  
      struct v2f {
          float4 pos : POSITION;
          float4 color : COLOR0;
          float4 fragPos : COLOR1;
          float2 uv : TEXCOORD0;
      };
  
      v2f vert (appdata_base v){
          v2f o;
          o.pos = mul (UNITY_MATRIX_MVP, v.vertex);
          o.fragPos = o.pos;
          o.uv = TRANSFORM_TEX (v.texcoord, _tex0);
          o.color = float4 (1.0, 1.0, 1.0, 1);
          return o;
      }
  
      half4 frag (v2f i) : COLOR{
          float animtime = _Time*10.0;
          float2 q = i.uv.xy / float2(1,1);
          float3 oricol = tex2D (_tex0,float2(q.x,q.y)).xyz;
          float3 col = tex2D (_tex1,float2(i.uv.x,i.uv.y)).xyz;
          float comp = smoothstep( 0.2, 0.7, sin(animtime) );
          col = lerp(col,oricol, clamp(-2.0+2.0*q.x+3.0*comp,0.0,1.0));
  
          // custom alpha bit
          float4 textureColor = float4(col,1);
          if(textureColor.a &lt; 1.0){
              discard;
          }
  
          return textureColor;
      }
      ENDCG
      }
  }
  //FallBack "VertexLit"
  }
  </code></pre>
  
  <hr>
  
  <p>I tried to implement a small code snippet in the last function for alpha support. I tried changing Tags to {"Queue"="Transparent" "IgnoreProjector"="True" "RenderType"="Transparent"}, setting Cull and ZWrite to Off, adding Blend SrcAlpha OneMinusSrcAlpha... basically tried discarding transparent fragments, alpha testing, and blending, but I must be doing something wrong.</p>
  
  <p>I set my two textures (which are PSDs, Photoshop file format with Alpha) to "Advanced" Texture Type, with "Generate Mip Maps" turned off, "Alpha is Transparency" turned on, and "Format" to "RGBA 32 bit". With these settings and the shader above, my textures preview as they should, but my textured plane is black...</p>
  
  <p>Anyone could either help me out or tip me in the right direction?</p>
  
  <hr>
  
  <p>EDIT :
  (sorry for the links, I don't have enough reputation yet to post them all)</p>
  
  <p>This is what I get with the unedited shader from <a href="http://unitycoder.com/blog/2012/01/20/wipe-transition-shader/" rel="nofollow noreferrer">here</a> + PSD set to normal (no advanced texture settings) : 
  http: //answers.unity3d.com/storage/temp/22441-unity_base.jpg</p>
  
  <p>This is what I get with current shader (code above) + a PSD as a texture, set to RGBA 32-bit, no Mip Maps, and 'Alpha is Transparency' turned on :
  http: //answers.unity3d.com/storage/temp/22442-unity_black.jpg</p>
  
  <p>And this is what I'm trying to achieve (but not with a still image, I want to keep the original "Wipe" effect) :
  http: //nicolasraspail.com/unity_achieve.png</p>
  
  <hr>
  
  <p>EDIT : <strong>Here's the shader working properly</strong> (thanks @nwellnhof !)</p>
  
  <pre><code>    Shader "Wipe" {
  
          // Editor controllers
          Properties{
          _tex0 ("Texture1", 2D) = "white" {}
          _tex1 ("Texture2", 2D) = "white" {}
          }
  
      SubShader{
          Tags {"Queue"="Transparent" "IgnoreProjector"="True" "RenderType"="Transparent"}
          ZWrite Off
          Blend SrcAlpha OneMinusSrcAlpha
  
          Pass{
          CGPROGRAM
              #pragma target 3.0
              #pragma vertex vert
              #pragma fragment frag
              #include "UnityCG.cginc"
  
              sampler2D _tex0;
              sampler2D _tex1;
              float4 _tex0_ST;
  
              struct v2f {
                  float4 pos : POSITION;
                  float4 color : COLOR0;
                  float4 fragPos : COLOR1;
                  float2  uv : TEXCOORD0;
              };
  
              v2f vert (appdata_base v){
                  v2f o;
                  o.pos = mul (UNITY_MATRIX_MVP, v.vertex);
                  o.fragPos = o.pos;
                  o.uv = TRANSFORM_TEX (v.texcoord, _tex0);
                  o.color = float4 (1.0, 1.0, 1.0, 1);
                  return o;
              }
  
              half4 frag (v2f i) : COLOR{
                  float4 oricol   = tex2D(_tex0, i.uv);
                  float4 col      = tex2D(_tex1, i.uv);
                  float  animtime = _Time * 10.0;
                  float  comp     = smoothstep(0.2, 0.7, sin(animtime));
                  float  coeff    = clamp(-2.0 + 2.0 * i.uv.x + 3.0 * comp, 0.0, 1.0);
                  float4 result   = lerp(col, oricol, coeff);
  
                  return result;
              }
          ENDCG
  }
  }
  //FallBack "VertexLit"
  }
  </code></pre>