#version 330 core
// Video cutout composite pass. Structure mirrors chromakey.fs.
//
// Input (TU0): the clip rendered into a scratch FBO (RGBA8, premultiplied).
// Input (TU1): the alpha matte rendered into a SECOND scratch FBO with the
//              exact same fit / orientation / dst rect, so both scratches
//              share one UV space. R == G == B == alpha there.
// Output: the clip with its background alpha-ed out.
//
// Uses blur.vs as the vertex shader (Y-flipped, u_texScale applied in VS).
//
// Neither Feather nor Expand is applied here -- both are baked into the
// matte scratch before this pass (cutout_matte_blur.fs's separable blur,
// then cutout_matte_expand.fs's separable dilate/erode), so Feather = 0 /
// Expand = 0 leaves the model's native edge untouched instead of
// re-hardening or re-expanding it.

out vec4 FragColor;
in  vec2 TexCoord;

uniform sampler2D tex_rgba;    // TU0 -- clip scratch (premultiplied)
uniform sampler2D tex_matte;   // TU1 -- feathered AND expanded matte scratch
uniform float     u_opacity;   // final layer opacity

void main() {
    vec4  src = texture(tex_rgba, TexCoord);
    float a   = texture(tex_matte, TexCoord).r;
    // src is premultiplied: scale RGB and A by the same factor.
    FragColor = src * a * u_opacity;
}
