Skip to content

Instantly share code, notes, and snippets.

@Ape
Last active August 29, 2015 14:17
Show Gist options
  • Save Ape/b7744573094105b04333 to your computer and use it in GitHub Desktop.
Save Ape/b7744573094105b04333 to your computer and use it in GitHub Desktop.
Kuku Kube Compositing Shader
// Run this with Compton
// compton --backend glx --force-win-blend --glx-fshader-win "$(cat hash-shader.glsl)"
uniform float opacity;
uniform bool invert_color;
uniform sampler2D tex;
// HSV conversion taken from http://stackoverflow.com/a/17897228
vec3 rgb2hsv(vec3 c) {
vec4 K = vec4(0.0, -1.0 / 3.0, 2.0 / 3.0, -1.0);
vec4 p = mix(vec4(c.bg, K.wz), vec4(c.gb, K.xy), step(c.b, c.g));
vec4 q = mix(vec4(p.xyw, c.r), vec4(c.r, p.yzx), step(p.x, c.r));
float d = q.x - min(q.w, q.y);
float e = 1.0e-10;
return vec3(abs(q.z + (q.w - q.y) / (6.0 * d + e)), d / (q.x + e), q.x);
}
vec3 hsv2rgb(vec3 c) {
vec4 K = vec4(1.0, 2.0 / 3.0, 1.0 / 3.0, 3.0);
vec3 p = abs(fract(c.xxx + K.xyz) * 6.0 - K.www);
return c.z * mix(K.xxx, clamp(p - K.xxx, 0.0, 1.0), c.y);
}
void main() {
vec4 c = texture2D(tex, gl_TexCoord[0]);
if (invert_color)
c = vec4(vec3(c.a, c.a, c.a) - vec3(c), c.a);
c = vec4(rgb2hsv(vec3(c.r, c.g, c.b)), c.a);
float x = mod(gl_TexCoord[0].x, 0.02);
if (x > 0.01) {
c.g = mod(1678.0*c.g, 1.0);
c.b = mod(5382.0*c.b, 1.0);
}
float l = mod(2134.0*c.g + 8432.0*c.b, 1.0);
c.r = mod(3521.0*c.g + 4272.0*c.b, 1.0);
c.g = 0.2 + 0.8*l;
c.b = 1.0 - 0.8*l;
c = vec4(hsv2rgb(vec3(c.r, c.g, c.b)), c.a);
c *= opacity;
gl_FragColor = c;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment