-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCellularNoise1g.frag
82 lines (58 loc) · 2.03 KB
/
CellularNoise1g.frag
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#ifdef GL_ES
precision highp float;
#endif
uniform vec2 u_resolution;
uniform vec2 u_mouse;
uniform float u_time;
//---------------------------------------------------------------------
#define MAX_POINTS 7
float circle(in vec2 _st, in float _radius) {
vec2 dist = _st - vec2(0.5);
return 1. - smoothstep(_radius - (_radius * 0.01),
_radius + (_radius * 0.01),
dot(dist, dist) * 4.0);
}
float shapeBorder(vec2 st, float radius, float width) {
return circle(st, radius) - circle(st, radius - width);
}
float random(in float x) {
return fract(sin(x) * 1e4);
}
// YUV to RGB matrix
mat3 yuv2rgb = mat3(1.0, 0.0, 1.13983,
1.0, -0.39465, -0.58060,
1.0, 2.03211, 0.0);
// RGB to YUV matrix
mat3 rgb2yuv = mat3( 0.2126, 0.7152, 0.0722,
-0.09991, -0.33609, 0.43600,
0.615, -0.5586, -0.05639);
//---------------------------------------------------------------------
void main() {
vec2 st = gl_FragCoord.xy/u_resolution.xy;
st.x *= u_resolution.x/u_resolution.y;
// Use polar coordinates instead of cartesian
vec2 toCenter = vec2(0.5) - st;
float angle = atan(toCenter.y, toCenter.x);
float radius = length(toCenter) * 2.0;
vec3 color = vec3(.0);
st *= radius * 14.;
st -= .7;
vec2 circularMotion = vec2(sin(u_time), cos(u_time));
vec2 point[MAX_POINTS];
for (int i = 0; i < MAX_POINTS; i++) {
point[i] = vec2(radius * float(i) - sin(abs(u_time - 3. + float(i))),
radius * float(i) + cos(abs(u_time + 3. + float(i))));
}
float m_dist = 1.; // minimun distance
// Iterate through the points positions
for (int i = 0; i < MAX_POINTS; i++) {
float dist = distance(st, point[i]);
// Keep the closer distance
m_dist = min(m_dist, dist);
}
color += shapeBorder(vec2(m_dist), m_dist, .7);
color += step(.7, abs(sin(7. * m_dist)));
color -= vec3(st, .7);
color -= rgb2yuv[0];
gl_FragColor = vec4(color, 1.0);
}