thebookofshaders/06/hsb-colorwheel.frag

36 lines
915 B
GLSL
Raw Normal View History

2015-03-15 15:35:14 +00:00
#ifdef GL_ES
precision mediump float;
#endif
#define TWO_PI 6.28318530718
uniform vec2 u_resolution;
uniform float u_time;
2017-08-19 10:11:58 +00:00
// Function from Iñigo Quiles
2015-03-15 15:35:14 +00:00
// https://www.shadertoy.com/view/MsS3Wc
vec3 hsb2rgb( in vec3 c ){
vec3 rgb = clamp(abs(mod(c.x*6.0+vec3(0.0,4.0,2.0),
2017-08-19 10:11:58 +00:00
6.0)-3.0)-1.0,
0.0,
2015-03-15 15:35:14 +00:00
1.0 );
rgb = rgb*rgb*(3.0-2.0*rgb);
return c.z * mix( vec3(1.0), rgb, c.y);
}
void main(){
vec2 st = gl_FragCoord.xy/u_resolution;
vec3 color = vec3(0.0);
2015-03-22 16:49:04 +00:00
// Use polar coordinates instead of cartesian
2015-03-15 15:35:14 +00:00
vec2 toCenter = vec2(0.5)-st;
float angle = atan(toCenter.y,toCenter.x);
float radius = length(toCenter)*2.0;
2017-08-19 10:11:58 +00:00
2015-03-22 16:49:04 +00:00
// Map the angle (-PI to PI) to the Hue (from 0 to 1)
2015-03-15 15:35:14 +00:00
// and the Saturation to the radius
color = hsb2rgb(vec3((angle/TWO_PI)+0.5,radius,1.0));
gl_FragColor = vec4(color,1.0);
2017-08-19 10:11:58 +00:00
}