-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMovingCells3.frag
47 lines (35 loc) · 1.16 KB
/
MovingCells3.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
#ifdef GL_ES
precision mediump float;
#endif
#define PI 3.14159265358979323846
uniform vec2 u_resolution;
uniform vec2 u_mouse;
uniform float u_time;
//---------------------------------------------------------------------
float random (in vec2 _st) {
return fract(sin(dot(_st.xy,vec2(12.9898,78.233)))*43758.5453123);
}
float box(vec2 _st, vec2 _size){
_size = vec2(0.5)-_size*0.5;
vec2 uv = smoothstep(_size,_size+vec2(1e-4),_st);
uv *= smoothstep(_size,_size+vec2(1e-4),vec2(1.0)-_st);
return uv.x*uv.y;
}
vec2 brickTile(vec2 _st, float _zoom){
_st *= _zoom;
// Here is where the offset is happening
_st.x += step(1., mod(_st.y,2.0)) * 0.5;
_st.x -= u_time;
return fract(_st);
}
//---------------------------------------------------------------------
void main() {
vec2 st = gl_FragCoord.xy/u_resolution.xy;
vec3 color = vec3(0.0);
// Divide the space in 4
st = brickTile(st, 10000.);
// Draw a square
float b = box(vec2(random(st), random(st)), vec2(.95));
color = vec3(fract(b * random(vec2(u_time))), fract(b * random(vec2(u_time))), fract(b * random(vec2(u_time))));
gl_FragColor = vec4(color,1.0);
}