// violet-chaton v2 — subtle glow shader for kitty
// Adds a soft bloom/glow around bright text characters
// Usage: kitty --override 'background_shader=~/.config/kitty/violet-chaton-glow.glsl'

void main() {
    // Sample the original pixel
    vec4 color = texture(image, texCoord);

    // Only glow on non-background pixels (bright enough)
    float brightness = dot(color.rgb, vec3(0.299, 0.587, 0.114));

    if (brightness > 0.15) {
        // Sample surrounding pixels for bloom
        vec2 pixel = 1.0 / textureSize(image, 0);
        vec4 glow = vec4(0.0);
        float total = 0.0;

        for (int x = -2; x <= 2; x++) {
            for (int y = -2; y <= 2; y++) {
                float weight = 1.0 / (1.0 + float(x*x + y*y));
                glow += texture(image, texCoord + vec2(float(x), float(y)) * pixel) * weight;
                total += weight;
            }
        }
        glow /= total;

        // Blend glow with original — subtle violet tint
        float glowBrightness = dot(glow.rgb, vec3(0.299, 0.587, 0.114));
        vec3 violetTint = vec3(0.85, 0.55, 1.0); // lilac-ish
        vec3 glowColor = glow.rgb * violetTint;

        // Mix: 85% original + 15% glow, only where text is
        color.rgb = mix(color.rgb, color.rgb + glowColor * 0.12, smoothstep(0.1, 0.4, glowBrightness));
    }

    gl_FragColor = color;
}
