-
-
Save baron/499595 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
uniform float uValue; // Value/brighness component. | |
const float kPi = 3.141592653589793; | |
vec3 hsv2rgb(float h, float s, float v) | |
{ | |
float hi = h * 3.0 / kPi; // Sector, [-3..3) | |
float f = hi - floor(hi); // Fractional part. | |
vec4 components = vec4 | |
( | |
1.0, | |
(1.0 - s), | |
(1.0 - s * f), | |
(1.0 - s * (1.0 - f)) | |
) * v; | |
#if 0 | |
if (hi < -2.0) | |
{ | |
return components.xwy; | |
} | |
else if (hi < -1.0) | |
{ | |
return components.zxy; | |
} | |
else if (hi < 0.0) | |
{ | |
return components.yxw; | |
} | |
else if (hi < 1.0) | |
{ | |
return components.yzx; | |
} | |
else if (hi < 2.0) | |
{ | |
return components.wyx; | |
} | |
else | |
{ | |
return components.xyz; | |
} | |
#else | |
return (hi < 0.0) ? | |
( | |
(hi < -2.0) ? components.xwy : | |
(hi < -1.0) ? components.zxy : | |
components.yxw | |
) : | |
( | |
(hi < 1.0) ? components.yzx : | |
(hi < 2.0) ? components.wyx : | |
components.xyz | |
); | |
#endif | |
} | |
void main() | |
{ | |
vec2 coords = gl_TexCoord[0].st * 2.0 - 1.0; | |
float theta = atan(coords.y, -coords.x); | |
float r = length(coords); | |
vec3 rgb = hsv2rgb(theta, r, uValue); | |
// Clamp to a circle. Anti-aliasing left as an exercise for the reader. | |
vec4 rgba = vec4(rgb, step(r, 1.0)); | |
gl_FragColor = rgba; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment