Skip to content

Instantly share code, notes, and snippets.

@bergwerf
Created January 29, 2022 16:24
Show Gist options
  • Save bergwerf/e67badeef837f7c10b03cc0856a09dbe to your computer and use it in GitHub Desktop.
Save bergwerf/e67badeef837f7c10b03cc0856a09dbe to your computer and use it in GitHub Desktop.
Hue cycling over grayscale
// Try on: https://www.shadertoy.com/new
// With: https://github.com/andrewhills/ShadertoyCustomTextures
// https://www.shadertoy.com/view/XljGzV
vec3 hsl2rgb( in vec3 c )
{
vec3 rgb = clamp( abs(mod(c.x*6.0+vec3(0.0,4.0,2.0),6.0)-3.0)-1.0, 0.0, 1.0 );
return c.z + c.y * (rgb-0.5)*(1.0-abs(2.0*c.z-1.0));
}
// CCIR 601
float rgb2gray( in vec3 c )
{
return 0.2989*c.x + 0.5870*c.y + 0.1140*c.z;
}
void mainImage( out vec4 fragColor, in vec2 fragCoord )
{
vec2 uv = fragCoord/iResolution.xy;
vec4 col = texture(iChannel0, uv);
float v = rgb2gray(col.xyz);
vec3 hsl = vec3(v*3.0 + iTime/3.0, 0.5, 0.5);
fragColor = vec4(hsl2rgb(hsl), 1.0);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment