Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

Question Alpha transparency in video not working

Discussion in 'Audio & Video' started by ivoras, Jul 23, 2021.

  1. ivoras

    ivoras

    Joined:
    May 21, 2020
    Posts:
    66
    I have a webm movie encoded with alpha transparency hosted on a server, it's available here:

    https://media.equinox.vision/generic/alpha_vp8.webm

    I've verified it contains transparency by loading that URL in Chrome, then adding "background: green" to the BODY element in Inspector, and it behaves as expected: everything outside the shape is green.

    I'm loading this movie onto a gameObject with this code:

    Code (CSharp):
    1.  
    2.                 var photoGo = _photoCanvas.gameObject;
    3.                 var rendTex = new RenderTexture(1024, 1024, 16, RenderTextureFormat.ARGB32);
    4.  
    5.                 _videoPlayer = photoGo.AddComponent<VideoPlayer>();
    6.                 _videoPlayer.renderMode = VideoRenderMode.RenderTexture;
    7.                 _videoPlayer.targetTexture = rendTex;
    8.                 _photoRawImage.texture = rendTex;
    9.  
    10.                 _videoPlayer.playOnAwake = false;
    11.                 _videoPlayer.url = url;
    12.                 _videoPlayer.isLooping = true;
    13.                 _videoPlayer.waitForFirstFrame = false;
    14.                 _videoPlayer.aspectRatio = VideoAspectRatio.FitInside;
    15.                 _videoPlayer.audioOutputMode = VideoAudioOutputMode.AudioSource;
    16.                 if (_videoPlayer.controlledAudioTrackCount > 0 ) {
    17.                     _videoPlayer.SetTargetAudioSource(0, getAudioSource());
    18.                 }
    19.                 _videoPlayer.Play();
    20.  
    In the code, `_photoRawImage` contains a `RawImage` and a `Canvas`, nested under the `_photoCanvas` gameObject, which contains a `CanvasGroup` and a `Canvas` (used if there's no video).

    However, I get the movie playing, but with a black colour where it should be transparent. So the video *is* playing, the content of the video is fine *except* it disregards the alpha channel. This is an AR app on Android, if it makes any difference.

    Any ideas why the alpha channel isn't being used?
     
    Last edited: Jul 25, 2021
  2. LaurentGibert

    LaurentGibert

    Unity Technologies

    Joined:
    Jan 23, 2020
    Posts:
    170
    Hi @ivoras the documentation points out that:
    One notable exception is Android. This platform’s native VP8 support does not include transparency support, which means transcoding must be enabled so Unity uses its internal alpha representation.
    To enable transcoding it seems you need to have the video locally.

    I am checking with the team what's up with this topic.
     
  3. RaviNSwami

    RaviNSwami

    Joined:
    May 27, 2022
    Posts:
    7
     
  4. RaviNSwami

    RaviNSwami

    Joined:
    May 27, 2022
    Posts:
    7
    Hi,

    I discovered a solution to this that doesn't require any additional scripts.

    I am using a QT movie (Apple ProRes 4444) with transparency, transcoded in Unity.

    It should work with both "Planes" or "Quads".

    You need to create a new material set to the following :
    Shader: Particles/Standard Unit
    Rendering Mode: CutOut
    Color Mode: Multiply

    Add this to the plane/quad settings by dragging into the respective SETTINGS window - NOT onto the plane/quad in the Hierarchies window, which I found doesn't add the material in the expected fashion.

    This then displays your video content with 100% transparency where intended.

    Setting the Rendering Mode to "Transparent" (instead of "Cut Out") does not work as expected - the video will be 50% transparent in areas that are intended to be 100% transparent.
     
  5. menguzar

    menguzar

    Joined:
    Jan 31, 2022
    Posts:
    10
    does this work on android?