-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfragmentShader.glsl
60 lines (42 loc) · 1.28 KB
/
fragmentShader.glsl
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
#version 330 core
#define fragCoord gl_FragCoord.xy
#ifdef GL_ES
precision mediump float;
#endif
const float PI = 3.14159265359;
const float PI2 = 6.283185;
uniform vec2 iMouse;
uniform float iTime;
uniform vec2 iResolution;
out vec4 fragColor;
vec2 random2( vec2 p ) {
return fract(sin(vec2(dot(p,vec2(127.1,311.7)),dot(p,vec2(269.5,183.3))))*43758.5453);
}
void main() {
vec2 st = fragCoord/iResolution.xy;
st.x *= iResolution.x/iResolution.y;
vec3 color = vec3(.0);
// Scale
st *= 6.;
vec2 i_st = floor(st);
vec2 f_st = fract(st);
float m_dist = 1;
for (int y= -1; y <= 1; y++) {
for (int x= -1; x <= 1; x++) {
vec2 neighbor = vec2(float(x),float(y));
vec2 point = random2(i_st + neighbor);
point = 0.5 + 0.5*sin(iTime + PI2*point)/2.0 ;
vec2 diff = neighbor + point - f_st;
// Distance to the point
float dist = length(diff);
m_dist = min(m_dist, dist);
}
}
//colored version
//color += vec3(m_dist,sin(iTime / PI)+1.0/2 , sin(iTime / PI)+1.0/2 );
//black and white version
color += vec3(m_dist -0.4, m_dist-0.1, m_dist-0.1);
// Draw the point center
color += 1.-step(.02, m_dist);
fragColor = vec4(color,1.0);
}