basic: added ryb example
This commit is contained in:
49
basic/ryb_and_beyond.glsl
Normal file
49
basic/ryb_and_beyond.glsl
Normal file
@@ -0,0 +1,49 @@
|
||||
#ifdef GL_ES
|
||||
precision mediump float;
|
||||
#endif
|
||||
|
||||
#define TAU 6.28318530718
|
||||
|
||||
uniform vec2 u_resolution;
|
||||
|
||||
vec3 hsb2rgb( 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 );
|
||||
rgb = rgb*rgb*(3.0-2.0*rgb);
|
||||
return c.z * mix( vec3(1.0), rgb, c.y);
|
||||
}
|
||||
|
||||
float scale_with(float hue, vec2 begin, vec2 end) {
|
||||
return (((end.y-begin.y)/(end.x-begin.x))*(hue-begin.x)+begin.y);
|
||||
}
|
||||
|
||||
// if you find the right values for bbend and ebend, you can scale parts of the color spectrum
|
||||
float scale(float hue) {
|
||||
vec2 bbend = vec2(0.250,0.330);
|
||||
vec2 ebend = vec2(0.340,0.390);
|
||||
|
||||
if (hue < bbend.x) {
|
||||
return scale_with(hue, vec2(0,0), bbend);
|
||||
} else if (hue < ebend.x) {
|
||||
return scale_with(hue, bbend, ebend);
|
||||
}
|
||||
return scale_with(hue, ebend, vec2(1.0, 1.0));
|
||||
}
|
||||
|
||||
void main(){
|
||||
vec2 st = gl_FragCoord.xy/u_resolution;
|
||||
vec3 color = vec3(0.0);
|
||||
|
||||
// Use polar coordinates instead of cartesian
|
||||
vec2 toCenter = vec2(0.5)-st;
|
||||
float angle = atan(toCenter.y, toCenter.x)/TAU;
|
||||
float radius = length(toCenter)*2.0;
|
||||
|
||||
// Map the angle (-PI to PI) to the Hue (from 0 to 1)
|
||||
// and the Saturation to the radius
|
||||
color = hsb2rgb(vec3(scale(angle+0.5)+0.5,radius,1.0));
|
||||
|
||||
gl_FragColor = vec4(color,1.0);
|
||||
}
|
Reference in New Issue
Block a user