obs-studio/plugins/obs-transitions/data/stinger_matte_transition.effect
Stéphane Lepin 506434c5e6 obs-transitions: add track matte feature to the stinger transition
This adds the ability to use a secondary black-and-white video as a mask
between source A and B of the transition. The greyscale value of each
pixel is used as the "slider" value in a linear interpolation between the
corresponding pixels in source A and source B.
The track matte can either be in the same file as the stinger itself
(next to the stinger or under the stinger, doubling the width or height
of the stinger depending of the selected layout) or a in a separate
dedicated file.
The same file/separate file behavior is controlled by the
"Matte Layout" option in the stinger settings.
2021-02-06 17:14:07 -08:00

54 lines
1.1 KiB
Plaintext

uniform float4x4 ViewProj;
uniform texture2d a_tex;
uniform texture2d b_tex;
uniform texture2d matte_tex;
uniform bool invert_matte;
sampler_state textureSampler {
Filter = Linear;
AddressU = Clamp;
AddressV = Clamp;
};
struct VertData {
float4 pos : POSITION;
float2 uv : TEXCOORD0;
};
VertData VSDefault(VertData v_in)
{
VertData vert_out;
vert_out.pos = mul(float4(v_in.pos.xyz, 1.0), ViewProj);
vert_out.uv = v_in.uv;
return vert_out;
}
float4 PSStingerMatte(VertData v_in) : TARGET
{
float2 uv = v_in.uv;
float4 a_color = a_tex.Sample(textureSampler, uv);
float4 b_color = b_tex.Sample(textureSampler, uv);
float4 matte_color = matte_tex.Sample(textureSampler, uv);
// RGB -> Luma conversion using Rec. 709 factors
float matte_luma = (
(matte_color.x * 0.2126) +
(matte_color.y * 0.7152) +
(matte_color.z * 0.0722)
);
// if matte invert is enabled, invert the matte color
matte_luma = (invert_matte ? (1.0 - matte_luma) : matte_luma);
return lerp(a_color, b_color, matte_luma);
}
technique StingerMatte
{
pass
{
vertex_shader = VSDefault(v_in);
pixel_shader = PSStingerMatte(v_in);
}
}