-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathNoise3.frag
72 lines (55 loc) · 1.88 KB
/
Noise3.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
#ifdef GL_ES
precision highp float;
#endif
uniform vec2 u_resolution;
uniform vec2 u_mouse;
uniform float u_time;
//---------------------------------------------------------------------
#define SEED 43758.5453123
vec2 random2(vec2 st) {
st = vec2(dot(st, vec2(127.1, 311.7)),
dot(st, vec2(269.5, 183.3)));
#ifdef GL_ES
return -1.0 + 2.0 * fract(sin(st));
#else
return -1.0 + 2.0 * fract(sin(st) * SEED);
#endif
}
// Gradient Noise by Inigo Quilez - iq/2013
// https://www.shadertoy.com/view/XdXGW8
float noise(vec2 st) {
vec2 i = floor(st);
vec2 f = fract(st);
vec2 u = f * f * (3.0 - 2.0 * f);
return mix( mix( dot( random2(i + vec2(0.0, 0.0) ), f - vec2(0.0, 0.0) ),
dot( random2(i + vec2(1.0, 0.0) ), f - vec2(1.0, 0.0) ), u.x),
mix( dot( random2(i + vec2(0.0, 1.0) ), f - vec2(0.0, 1.0) ),
dot( random2(i + vec2(1.0, 1.0) ), f - vec2(1.0, 1.0) ), u.x), u.y);
}
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);
}
//---------------------------------------------------------------------
void main() {
vec2 st = gl_FragCoord.xy / u_resolution.xy;
st.x *= u_resolution.x/u_resolution.y;
st.y *= u_resolution.y/u_resolution.x;
float t = 1.0;
t *= abs(1.0 - sin(u_time * .35)) * 7.;
st += noise(st * 1.7) * t;
vec3 color = vec3(1.0) * shapeBorder(st, noise(st), 7.);
color += vec3(.7, .7, .7) * smoothstep(.7, .2, noise(st));
vec2 toCenter = vec2(0.5) - st;
float angle = atan(toCenter.y, toCenter.x);
float radius = length(toCenter) * 2.0;
color.r *= radius;
color.b *= angle;
color.g /= toCenter.x;
gl_FragColor = vec4(color, 1.0);
}