Debian Codegraph @

code/renderergl2/glsl/greyscale_fp.glsl

raw
1 uniform sampler2D u_TextureMap;
2 uniform float u_Greyscale;
3 varying vec2 var_TexCoords;
4
5 // From Rec. 709-1 4.2 "Derivation of luminance signal"
6 const vec3 LUMA = vec3(0.2125, 0.7154, 0.0721);
7
8 void main() {
9 vec4 color = texture2D(u_TextureMap, var_TexCoords);
10 if (u_Greyscale > 0.0) {
11 float y = dot(color.rgb, LUMA);
12 color.rgb = mix(color.rgb, vec3(y), clamp(u_Greyscale, 0.0, 1.0));
13 }
14 gl_FragColor = color;
15 }