#version 300 es precision mediump float; in vec2 v_texcoord; uniform sampler2D tex; out vec4 FragColor; // Values obtained from: http://en.wikipedia.org/wiki/Grayscale#Luma_coding_in_video_systems vec3 LumaFactors = vec3(0.299, 0.587, 0.114); void main() { vec4 c = texture(tex, v_texcoord); // average brightness float luma = dot(vec3(c.r, c.g, c.b), LumaFactors); if (c.r < c.b) { FragColor = vec4(luma, luma, c.b, c.a); } else { FragColor = vec4(c.r, luma, luma, c.a); } // FragColor = vec4(c.r, luma, c.b, c.a); }