24 lines
545 B
GLSL
24 lines
545 B
GLSL
#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.g) {
|
|
FragColor = vec4(luma, c.g, luma, c.a);
|
|
} else {
|
|
FragColor = vec4(c.r, luma, luma, c.a);
|
|
}
|
|
// FragColor = vec4(c.r, c.g, luma, c.a);
|
|
}
|