Side-by-side Alpha Video Remover
This shader is meant to use with video, the video must be like this:
50% left: original object, any background color is okay, but black recommended
50% right: object with pure white color, on black background
For example, the original video is 1920×1080:
when combining, its width must be doubled: 3840×1080
It will use the white color on the right side to remove the alpha on the left side.
Shader code
shader_type canvas_item;
render_mode blend_mix;
uniform float threshold : hint_range(0.0, 1.0) = 0.5;
uniform float softness : hint_range(0.0, 0.5) = 0.05;
void fragment() {
vec2 color_uv = vec2(UV.x * 0.5, UV.y);
vec4 original = texture(TEXTURE, color_uv);
vec2 mask_uv = vec2(0.5 + UV.x * 0.5, UV.y);
vec3 mask_color = texture(TEXTURE, mask_uv).rgb;
float mask = dot(mask_color, vec3(0.299, 0.587, 0.114));
float alpha = smoothstep(
threshold - softness,
threshold + softness,
mask
);
COLOR = vec4(original.rgb, original.a * alpha);
}
