Skip to content

Instantly share code, notes, and snippets.

@polyclick
Created December 18, 2017 10:24
Show Gist options
  • Save polyclick/7e06ef58e59da06e4e68b36a7f49fb8d to your computer and use it in GitHub Desktop.
Save polyclick/7e06ef58e59da06e4e68b36a7f49fb8d to your computer and use it in GitHub Desktop.
#ifdef GL_ES
precision lowp float;
#endif
#define TWO_PI 6.28318530718
uniform sampler2D videoTexture;
varying vec2 vUv;
uniform vec3 colorA;
uniform vec3 colorB;
float blendOverlay(float base, float blend) {
return base<0.5?(2.0*base*blend):(1.0-2.0*(1.0-base)*(1.0-blend));
}
vec3 blendOverlay(vec3 base, vec3 blend) {
return vec3(blendOverlay(base.r,blend.r),blendOverlay(base.g,blend.g),blendOverlay(base.b,blend.b));
}
vec3 blendOverlay(vec3 base, vec3 blend, float opacity) {
return (blendOverlay(base, blend) * opacity + base * (1.0 - opacity));
}
float luminance(vec3 c) {
return dot(c, vec3(0.22, 0.707, 0.071));
}
void main() {
vec2 st = vUv;
vec3 color = mix(colorA, colorB, st.x);
vec3 tex = texture2D(videoTexture, vUv).rgb;
float lum = luminance(tex);
tex = mix(tex, vec3(lum), 1.0);
vec3 mixed = blendOverlay(tex, color, 0.5);
gl_FragColor = vec4(mixed, 1.0);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment