// @name Cinema Bars — 2.39:1
// @group Letterbox
// @param uBarOpacity "Bar Opacity" 1.0 0.0 1.0 0.01
// @param uFeather "Edge Softness" 0.0 0.0 0.03 0.0005
// @param uVerticalOffset "Vertical Framing" 0.0 -0.15 0.15 0.001

#define TARGET_ASPECT 2.39

void mainImage(out vec4 fragColor, in vec2 fragCoord) {
    vec2 uv = fragCoord / uResolution;
    vec4 source = texture(uTexture, uv);

    float viewportAspect = uResolution.x / max(uResolution.y, 1.0);
    float visibleHeight = min(1.0, viewportAspect / TARGET_ASPECT);
    float halfHeight = visibleHeight * 0.5;
    float edgeDistance = halfHeight - abs(uv.y - 0.5 - uVerticalOffset);
    float feather = max(uFeather, 0.000001);
    float barMask = 1.0 - smoothstep(-feather, feather, edgeDistance);
    float amount = barMask * uBarOpacity * uIntensity;

    fragColor = vec4(mix(source.rgb, vec3(0.0), amount), source.a);
}
