- Home /
Video Player WebGl Transparency problem - previous frames doesn't clear
I'm playing .webm video file with URL.
Video File: https://dynamicgamesdeveloper.github.io/Video/Bear.webm
Demo: https://dynamicgamesdeveloper.github.io/index.html
Tested Browser: Google Chrome
It should look:
But looks like:
First I tried to use other shader and even not transparent. Effect is the same, so I've decided problem is related to texture.
I've tried to clear renderTexture where it's going from VideoPlayer:
void OnPreRender() //Or OnPostRender()
{
RenderTexture current = RenderTexture.active;
RenderTexture.active = myRenderTexture;
GL.Clear(true, true, Color.blue);
RenderTexture.active = current;
}
The same. It looks like it's encapsulated in Video Player. What to do?
Hi Radiys Thanks for the reply. Here you go: https://dynamicgamesdeveloper.github.io/Video/Bear.webm And here the Demo: https://dynamicgamesdeveloper.github.io/index.html Tested Browser: Google Chrome
I'm seeing this same problem with webGL and alpha'd video did you ever find a solution?
No, you have to report it's to Unity. $$anonymous$$aybe they fix it in next releases.
No. It is Skybox on first scene and Solid Color on second one.
It works when I use just VideoClip on Android $$anonymous$$ode.
Is it just have this problem on WebGL?
Another way is use $$anonymous$$P4, with no alpha like this with shader on your RawImage.
$$anonymous$$p4 :
Shader:
Shader "Unlit/VideoAlpha"
{
Properties
{
_$$anonymous$$ainTex ("Texture", 2D) = "white" {}
}
SubShader
{
Tags { "Queue" = "Transparent" }
LOD 100
zwrite off
blend srcalpha one$$anonymous$$ussrcalpha
Pass
{
CGPROGRA$$anonymous$$
#pragma vertex vert
#pragma fragment frag
// make fog work
#pragma multi_compile_fog
#include "UnityCG.cginc"
struct appdata
{
float4 vertex : POSITION;
float2 uv : TEXCOORD0;
};
struct v2f
{
float2 uv : TEXCOORD0;
UNITY_FOG_COORDS(1)
float4 vertex : SV_POSITION;
};
sampler2D _$$anonymous$$ainTex;
float4 _$$anonymous$$ainTex_ST;
v2f vert (appdata v)
{
v2f o;
o.vertex = UnityObjectToClipPos(v.vertex);
o.uv = TRANSFOR$$anonymous$$_TEX(v.uv, _$$anonymous$$ainTex);
UNITY_TRANSFER_FOG(o,o.vertex);
return o;
}
fixed4 frag (v2f i) : SV_Target
{
// sample the texture
fixed4 col = tex2D(_$$anonymous$$ainTex, i.uv);
//fixed4 col = tex2D(_$$anonymous$$ainTex, half2(i.uv.x*0.5 , i.uv.y));
//fixed4 mask = tex2D(_$$anonymous$$ainTex, half2(0.5 + i.uv.x*0.5 , i.uv.y));
// apply fog
return float4( col.rgb , 1 - step( col.r , 0));
}
ENDCG
}
}
}
And it will looks like this:
Thanks for the comment. It seems like Unity bug on Web GL. On Android Video Alpha works fine. You shader is cutout and drops black pixels, so it wont't work if background is some color ins$$anonymous$$d of black either with semi-transparency. It would be cool if Unity Video Transparency work on Web GL.
Answer by OPfeifferBweez · Jan 29, 2019 at 10:38 AM
Same problem here. .webm with alpha channel in WebGL builds seem to give weird results. I noticed that in Firefox it plays correctly, when in Chrome the artifact you shown appear. Also on both navigators the video is way more pale/contrastless than the original. I found no concrete solution online, any help from the Unity dev would be greatly appreciated !
The best alternative that I found so far is to use chroma key (the shader they share in this thread is free and works like a charm) : https://forum.unity.com/threads/chroma-key-in-unity-5.359119/
About the washed out effect on the video, this is a known issue and is due to the linear color space : https://issuetracker.unity3d.com/issues/video-the-videoplayer-component-doesnt-color-correct-under-linear-color-space
Hope it will help a bit..