2020-08-30 20:19:37 +00:00
|
|
|
//
|
|
|
|
// desaturate.glsl
|
|
|
|
//
|
|
|
|
// Desaturates textures such as game images.
|
2020-09-04 16:59:19 +00:00
|
|
|
// The uniform variable 'saturation' sets the saturation intensity.
|
2020-08-30 20:19:37 +00:00
|
|
|
// Setting this to the value 0 results in complete desaturation (grayscale).
|
|
|
|
//
|
|
|
|
|
|
|
|
#if defined(VERTEX)
|
2020-09-04 16:59:19 +00:00
|
|
|
// Vertex section of code:
|
2020-08-30 20:19:37 +00:00
|
|
|
|
|
|
|
varying vec2 vTexCoord;
|
|
|
|
|
|
|
|
void main(void)
|
|
|
|
{
|
2020-09-04 16:59:19 +00:00
|
|
|
vTexCoord = gl_MultiTexCoord0.xy;
|
|
|
|
gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;
|
2020-08-30 20:19:37 +00:00
|
|
|
}
|
|
|
|
|
2020-09-04 16:59:19 +00:00
|
|
|
#elif defined(FRAGMENT)
|
2020-08-30 20:19:37 +00:00
|
|
|
// Fragment section of code:
|
|
|
|
|
2020-09-04 16:59:19 +00:00
|
|
|
uniform float saturation = 1.0;
|
2020-08-30 20:19:37 +00:00
|
|
|
uniform sampler2D myTexture;
|
|
|
|
varying vec2 vTexCoord;
|
|
|
|
|
|
|
|
void main()
|
|
|
|
{
|
|
|
|
vec4 color = texture2D(myTexture, vTexCoord);
|
|
|
|
vec3 grayscale = vec3(dot(color.rgb, vec3(0.2125, 0.7154, 0.0721)));
|
|
|
|
|
|
|
|
vec3 blendedColor = mix(grayscale, color.rgb, saturation);
|
|
|
|
gl_FragColor = vec4(blendedColor, color.a);
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|