I'm currently playing a movie in Unity using MovieTexture and applying a custom shader to allow an alpha channel. Problem is I need to have the top half of the video masked and nothing seems to work. I believe it's the shader preventing it (correct me if I'm wrong).
I tried 3 different masking techniques:
- Standard Mask component on the video layer (quad) with a black and transparent PNG image as mask.
- DepthMask applied to a 3D object intersecting video layer - Uses a special shader that affects render queue or draw calls (I forget) to prevent anything from being drawn that is behind or within the 3D object.
- Putting the quad inside a Canvas and Panel UI layer and adjusting them so canvas and panel are half the size of the video layer. (Had to use a quad as I don't believe you can add a materiel to a UI element?)
None of these are blocking any of the video, unfortunately.
(This is the alpha shader I'm using: https://github.com/keijiro/AotsMovieTexture)
Here's the code for the shader as well:
Shader "Custom/Aots Movie Texture" {
Properties
{
_MainTex("Base Texture", 2D) = "" {}
_ColorTint("Color Tint", Color) = (0.5, 0.5, 0.5, 1)
}
CGINCLUDE
#include "UnityCG.cginc"
sampler2D _MainTex;
half4 _ColorTint;
struct v2f
{
float4 position : SV_POSITION;
float2 texcoord : TEXCOORD0;
};
v2f vert(appdata_base v)
{
v2f o;
o.position = mul(UNITY_MATRIX_MVP, v.vertex);
o.texcoord = v.texcoord;
return o;
}
float4 frag(v2f i) : SV_Target
{
float2 uv1 = i.texcoord;
float2 uv2 = i.texcoord;
uv1.x *= 0.5f;
uv2.x *= 0.5f;
uv2.x += 0.5f;
half4 color = tex2D(_MainTex, uv1);
half4 mask = tex2D(_MainTex, uv2);
color.rgb *= _ColorTint.rgb * 2;
color.a = mask.r * _ColorTint.a;
return color;
}
ENDCG
SubShader
{
Tags { "RenderType"="Transparent" "Queue"="Transparent" }
Pass
{
ZTest Always Cull Off ZWrite Off
Fog { Mode off }
Blend SrcAlpha OneMinusSrcAlpha
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
ENDCG
}
}
}
Edit:
Just explain in more details what I'm looking to do, we have a 4K video divided into quads. Top two quads will be independent videos and bottom two will be used for the alpha videos. I just need the top two quads (top half of the 4k video) hidden, so you only see the alpha channel when the video is layered on top like the shader I linked to.