Search Unity

video texture with alpha channel works but....

Discussion in 'Editor & General Support' started by david_jd, Feb 15, 2010.

  1. david_jd

    david_jd

    Joined:
    Feb 12, 2010
    Posts:
    4
    I’m trying to import some QT video in unity , but I saw in the forum all people faced problem with alpha channel, and they were saying that unity is not supporting the alpha channel.
    the first time when I applied the QT video to a transparent shader the alpha channel was not working ,then I changed the shader to FX/Flare . the alpha channel is working but the video is placed on the top of all 3d objects, so for example if you place the video behind a 3d wall, you will still see the video.
    so the question is ; if the unity is not supporting alpha channel , why the alpha channel is working with FX/Flare shader ? and is it possible to fix this problem with FX/FLARE shader?
     

    Attached Files:

  2. tomvds

    tomvds

    Joined:
    Oct 10, 2008
    Posts:
    1,028
    The flare shader appears to work because it is an additive shader. This means that black areas in the texture don't contribute to the color and bright areas do.

    Since the transparent areas in your movie also happen to be black, it appears the blending works, but in reality, the movies alpha channel is completely ignored. Examine dark areas on your polar bear, for instance, and you'll see you can look through it there.

    Anyway, on your actual question: you could replace the flare shader with Particles/Additive to make the movie appear 'inside' the scene.
     
  3. david_jd

    david_jd

    Joined:
    Feb 12, 2010
    Posts:
    4
    Thanks for your fast and useful respond. Actually with particles/additive shader, the movie is inside the scene. By the way, is there other way to apply the movie with alpha channel in unity? As you mentioned , the alpha channel is completely ignored and I can see through the dark area of the polar bear
     
  4. Dreamora

    Dreamora

    Joined:
    Apr 5, 2008
    Posts:
    26,601
    The theora version used in unity does not support alpha at all. when you drop the movie in it loses its alpha channel during the conversion, independent of the shader later.

    What you would have to do is use 2 movies and a shader that uses a specific color channel of the second movie as alpha channel for the whole blend operation.

    the depth sorting problem though wouldn't change due to that as that has to do with alpha not being able to depth sort on a pixel base, its depth sorted basing on the 0,0,0 point of the mesh (the transform handle)
     
  5. farid

    farid

    Joined:
    Apr 11, 2010
    Posts:
    5
    Hi! I have similar problem. In order to do blending operation, do you know which kind of shader should I use for these two movies,
     
  6. any_user

    any_user

    Joined:
    Oct 19, 2008
    Posts:
    374
    interesting topic, i would also be interested in having a solution for movies with alpha channels... is it possible to do this blend operation by using texture combiners?

    btw.: awesome forum here, i'm using unity for about 1.5 years now and until now i found nearly every answer to my questions in this forum without ever asking anything.. :)
     
  7. farid

    farid

    Joined:
    Apr 11, 2010
    Posts:
    5
    I found this shader script in unityAswers, in order to play a movie texture with the mask.
    I can play the main movie texture but I cannot play the mask with mainTexture.
    I’m using .Play (); to play the mask . But the Unity compiler say: "'Play' is not a member of 'UnityEngine.RenderTexture'." . for playing the mainTexture I use (renderer.material.mainTexture.Play ();) but how to play the mask ?



    ....................................................
    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
    #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"
    }

    ...................................................



    [/quote][/code]
     
  8. BFDesign

    BFDesign

    Joined:
    Mar 16, 2011
    Posts:
    214
    [/code][/QUOTE]

    I see this is quite old and you have probably figured out how to play your mask. But if you haven't you could try this.

    Has anyone figured out a coded solution for this yet that is efficient and works?
     
  9. sadiq@xstpl.com

    sadiq@xstpl.com

    Joined:
    Feb 27, 2013
    Posts:
    6
    Hello I want to play the green screen video with transparent background.Is this possible in unity 3d
     
  10. Bentoon

    Bentoon

    Joined:
    Apr 26, 2013
    Posts:
    98
    Hello Sadiq

    Remove the green screen and render out your movie RGB+Alpha
    Then use the Particles/Additive
    (Although this seems to make things slightly transparent )
    You probably found the answer by now
    Be