Skip to content

Instantly share code, notes, and snippets.

@cmdr2
Last active July 16, 2025 10:12
Show Gist options
  • Save cmdr2/29395dc687c96b3a8942f39598969a3f to your computer and use it in GitHub Desktop.
Save cmdr2/29395dc687c96b3a8942f39598969a3f to your computer and use it in GitHub Desktop.
// can run on https://thebookofshaders.com/edit.php
#ifdef GL_ES
precision mediump float;
#endif
uniform vec2 u_resolution;
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() {
vec2 coord = gl_FragCoord.xy/u_resolution.xy;
coord = coord * 2.0 - 1.0;
float r = length(coord);
if (r > 1.0) {
gl_FragColor = vec4(0.0);
return;
}
float angle = atan(coord.y, coord.x);
float hue = angle / (2.0 * 3.14) + 0.5;
float saturation = r;
float value = 1.0; // 0.0 to 1.0
gl_FragColor = vec4(hsv2rgb(vec3(hue, saturation, value)), 1);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment