forked from patriciogonzalezvivo/thebookofshaders
-
Notifications
You must be signed in to change notification settings - Fork 0
/
marching_dots.frag
46 lines (37 loc) · 1.03 KB
/
marching_dots.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
// Author @patriciogv - 2015 - patricio.io
#ifdef GL_ES
precision mediump float;
#endif
const float PI = 3.1415926535897932384626433832795;
uniform vec2 u_resolution;
uniform vec2 u_mouse;
uniform float u_time;
vec2 movingTiles(vec2 _st, float _zoom, float _speed){
_st *= _zoom;
float time = u_time*_speed;
if( fract(time)>0.5 ){
if (fract( _st.y * 0.5) > 0.5){
_st.x += fract(time)*2.0;
} else {
_st.x -= fract(time)*2.0;
}
} else {
if (fract( _st.x * 0.5) > 0.5){
_st.y += fract(time)*2.0;
} else {
_st.y -= fract(time)*2.0;
}
}
return fract(_st);
}
float circle(vec2 _st, float _radius){
vec2 pos = vec2(0.5)-_st;
return smoothstep(1.0-_radius,1.0-_radius+_radius*0.2,1.-dot(pos,pos)*3.14);
}
void main() {
vec2 st = gl_FragCoord.xy/u_resolution.xy;
st.x *= u_resolution.x/u_resolution.y;
st = movingTiles(st,10.,0.5);
vec3 color = vec3( 1.0-circle(st, 0.3 ) );
gl_FragColor = vec4(color,1.0);
}