Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
3
Question by jack_sparrow · Nov 17, 2014 at 06:12 AM · videomaskmovietexturevideotextureplaymovie

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

Comment
Add comment · Show 1
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image thehobbit123 · Mar 25, 2016 at 09:36 AM 0
Share

would you help me in play an alpha channel video.

4 Replies

· Add your reply
  • Sort: 
avatar image
3

Answer by Lucas7CL · Nov 05, 2015 at 09:10 PM

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. alt text 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 
  } 

}


ale-sample.png (62.7 kB)
Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image ciarancarrick · Jun 01, 2017 at 03:24 PM 0
Share

Any idea why this only seems to work on Android? On iOS it loses transparency.

avatar image
0

Answer by Assustado · Nov 25, 2015 at 08:58 PM

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

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image thehobbit123 · Mar 28, 2016 at 11:17 AM 0
Share

@Assustado please guide a bit more step wise. i want to play an alpha channel video. how can i do that?

avatar image
0

Answer by Eco-Editor · Sep 16, 2018 at 07:42 PM

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

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
0

Answer by eMillion · Mar 10, 2019 at 06:48 PM

Bump....

How to add different layers of transparent video in Unity3D?

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

32 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Video Import failure after Unity update [5.4.1p1] 0 Answers

Short looping videos on Mobile platforms 0 Answers

how to execute two line of code simultaneously.??? 0 Answers

Play, seek a video 1 Answer

Unity VideoPlayer on Android Lags 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges