Skip to content

Instantly share code, notes, and snippets.

@gre
Forked from gre/TEMPLATE.glsl
Last active January 4, 2016 10:09
Show Gist options
  • Save gre/8606647 to your computer and use it in GitHub Desktop.
Save gre/8606647 to your computer and use it in GitHub Desktop.
Fade to Grayscale
#ifdef GL_ES
precision highp float;
#endif
// General parameters
uniform sampler2D from;
uniform sampler2D to;
uniform float progress;
uniform vec2 resolution;
uniform float grayPhase; // if 0.0, the image directly turn grayscale, if 0.9, the grayscale transition phase is very important
vec3 grayscale (vec3 color) {
return vec3(0.2126*color.r + 0.7152*color.g + 0.0722*color.b);
}
void main() {
vec2 p = gl_FragCoord.xy / resolution.xy;
vec4 fc = texture2D(from, p);
vec4 tc = texture2D(to, p);
gl_FragColor = mix(
mix(vec4(grayscale(fc.rgb), 1.0), texture2D(from, p), smoothstep(1.0-grayPhase, 0.0, progress)),
mix(vec4(grayscale(tc.rgb), 1.0), texture2D(to, p), smoothstep( grayPhase, 1.0, progress)),
progress);
}
{
"grayPhase": 0.3
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment