How to play Alpha video in unity ?

hi,

i want to play video in unity with alpha channel.
i tried with this shader to play main video and mask to remove bg.

Shader "MovieWithSeperateAlpha" { 
Properties 
{ 
_MainTex ("Base (RGB)", 2D) = "white" {} 
_Mask ("Culling Mask", 2D) = "white" {} 
_Cutoff ("Cutoff", Range (0,1)) = .5 
}

 SubShader 
 {
     Tags {"Queue"="Transparent"}
 
     ZWrite Off
     Blend SrcAlpha OneMinusSrcAlpha
 
     Pass 
     {    
         CGPROGRAM 
// Upgrade NOTE: excluded shader from OpenGL ES 2.0 because it does not contain a surface program or both vertex and fragment programs.
#pragma exclude_renderers gles
             #pragma fragment frag 
             #include "UnityCG.cginc"  
 
             sampler2D _MainTex; 
             sampler2D _Mask; 
 
             struct v2f 
             { 
                 float4 pos : POSITION; 
                 float4 uv : TEXCOORD0; 
             }; 
 
             half4 frag (v2f i) : COLOR 
             { 
                 half4 color = tex2D(_MainTex, i.uv.xy); 
                 half4 color2 = tex2D(_Mask, i.uv.xy); 
 
                 return half4(color.r, color.g, color.b, color2.r); 
             } 
         ENDCG         
     }    
 }
 
 Fallback "Transparent/Diffuse" 
}

And then i use this script to play both main and mask channel at the same time.

 var maintexture : MovieTexture;
    var mask : MovieTexture;
    
    function Start () 
    { 
    maintexture = renderer.material.GetTexture ("_MainTex"); 
    mask = renderer.material.GetTexture ("_Mask"); 
    
    }
    
    function Update () 
    { 
    	if (Input.GetButtonDown ("Jump")) 
    	{ 
    	
    	maintexture.Play();
    	mask.Play();
    	} 
    	
    }

this code and Shader is working fine but my problem is i am getting bit of delay in playing both movie texture simultaneously.

is there anyway that i can sync both at the same time. or execute play at the same time.

thanx

yes, you must use the color and mask in the same video, for example you have two videos 512x512, then you put the color up and the mask down in a 512x1024 video.


attached you can find a pic of this kind of video.
the shader used is:
Shader “Custom/alpha1” {

 Properties{ 
      _MainTex("Color (RGB)", 2D) = "white" 
 } 

 SubShader{ 
      Tags{ "Queue" = "Transparent" "RenderType" = "Transparent" } 

      CGPROGRAM 
      #pragma surface surf NoLighting alpha 

      fixed4 LightingNoLighting(SurfaceOutput s, fixed3 lightDir, fixed atten) { 
           fixed4 c; 
           c.rgb = s.Albedo; 
           c.a = s.Alpha; 
           return c; 
      } 

      struct Input { 
           float2 uv_MainTex; 
      }; 

      sampler2D _MainTex; 

      void surf(Input IN, inout SurfaceOutput o) { 
           o.Emission = tex2D(_MainTex, IN.uv_MainTex).rgb; 
                       
          if(IN.uv_MainTex.y <= 0.5){ 
		    o.Alpha=0; 
		  }
		  
		  else{ 
		    o.Alpha = tex2D(_MainTex, float2(IN.uv_MainTex.x, IN.uv_MainTex.y-0.5)).rgb; 
		  }
		  
      } 

      ENDCG 
 } 

}

if your video has alpha, you can use the FX/Flare shader to do this

Really? A picture of a “babe” woman is what you chose to show here? Are we out of pictures?

Bump…

How to add different layers of transparent video in Unity3D?