/
Gradient 2
66 lines (52 loc) · 1.71 KB
/
Gradient 2
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
// Title: Gradient 2
#ifdef GL_ES
precision mediump float;
#endif
uniform vec2 u_resolution;
uniform vec2 u_mouse;
uniform float u_time;
#define PI 3.1415926535
// Function from Iñigo Quiles
// https://www.shadertoy.com/view/MsS3Wc
/*vec3 hsb2rgb( in vec3 c ){
vec3 rgb = clamp(abs(mod(c.x*6.0+vec3(4.000,1.760,1.760),
6.0)-3.0)-0.448,
0.0,
1.0 );
rgb = rgb*rgb*(3.0-2.0*rgb);
return c.z * mix( vec3(1.0), rgb, c.y);
}*/
vec3 hsb2rgb( in vec3 c ){
vec3 rgb = clamp(abs(mod(c.x*6.+vec3(0.0,4.0,2.0),
6.0)-3.0)-1.0,
0.0,
1. );
rgb = rgb*rgb*(3.2-2.0*rgb);
return c.z * mix( vec3(1.0), rgb, c.y);
}
void main() {
// get the xy coordinate & normalize to [0, 1] range
vec2 st = gl_FragCoord.xy/u_resolution.xy;
st.x *= u_resolution.x/u_resolution.y;
vec2 u_mouse = gl_FragCoord.xy/u_mouse.xy;
// set a fill color with hsb
// store as vec3
vec3 hsb;
hsb.r = 1.; // animate hue with time
hsb.g = 1.; // saturation
hsb.b = 1.; // brightness
if( true ){
float maxDistance = distance(vec2(st), vec2(abs(sin(u_time*0.3))));
//0.610,0.400
//u_mouse*0.3
// distanced based hue
float d = distance( st, vec2(-0.06,0.740))/maxDistance;
//float d = distance( st, vec2(-0.060,0.740))/maxDistance;
// animate with discrete steps
hsb.r = fract(-u_time+d*min(u_mouse.x,3.))/17.;
//hsb.r = fract(-u_time+d*1.)/15.;
}
// use custom function to translate hsv to rgb color space
vec3 color = hsb2rgb(hsb);
gl_FragColor = vec4(color, 1.0);
}