#version 300 es
precision highp float;
in vec2 v_texcoord;
uniform sampler2D tex;
out vec4 fragColor;
// Function to convert RGB to HSV
vec3 rgb2hsv(vec3 c) {
vec4 K = vec4(0.0, -1.0 / 3.0, 2.0 / 3.0, -1.0);
vec4 p = mix(vec4(c.bg, K.wz), vec4(c.gb, K.xy), step(c.b, c.g));
vec4 q = mix(vec4(p.xyw, c.r), vec4(c.r, p.yzx), step(p.x, c.r));
float d = q.x - min(q.w, q.y);
float e = 1.0e-10;
return vec3(abs(q.z + (q.w - q.y) / (6.0 * d + e)), d / (q.x + e), q.x);
}
void main() {
vec4 pix = texture(tex, v_texcoord);
vec3 hsv = rgb2hsv(pix.rgb);
// Grayscale base
float gray = dot(pix.rgb, vec3(0.2126, 0.7152, 0.0722));
// RED DETECTION LOGIC:
// Red in HSV is at 0.0 (and wraps at 1.0).
// This looks for a very narrow range around 0 (True Red).
// Orange/Yellow (0.1 - 0.2) will now be ignored.
float dist = min(abs(hsv.x - 0.0), abs(hsv.x - 1.0));
float isRed = smoothstep(0.05, 0.02, dist); // 0.05 is the threshold
// Optional: Only show red if it's actually saturated (ignores faint pinks)
isRed *= smoothstep(0.2, 0.4, hsv.y);
vec3 finalColor = mix(vec3(gray), pix.rgb * 1.3, isRed);
fragColor = vec4(finalColor, pix.a);
}