-
-
Notifications
You must be signed in to change notification settings - Fork 688
/
ikeda-04.frag
67 lines (51 loc) · 2.25 KB
/
ikeda-04.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
// Author @patriciogv - 2015
// Title: DeFrag
#ifdef GL_ES
precision mediump float;
#endif
// Copyright (c) Patricio Gonzalez Vivo, 2015 - http://patriciogonzalezvivo.com/
// I am the sole copyright owner of this Work.
//
// You cannot host, display, distribute or share this Work in any form,
// including physical and digital. You cannot use this Work in any
// commercial or non-commercial product, website or project. You cannot
// sell this Work and you cannot mint an NFTs of it.
// I share this Work for educational purposes, and you can link to it,
// through an URL, proper attribution and unmodified screenshot, as part
// of your educational material. If these conditions are too restrictive
// please contact me and we'll definitely work it out.
uniform vec2 u_resolution;
uniform vec2 u_mouse;
uniform float u_time;
float random (in float x) { return fract(sin(x)*1e4); }
float random (in vec2 _st) { return fract(sin(dot(_st.xy, vec2(12.9898,78.233)))* 43758.5453123);}
void main() {
vec2 st = gl_FragCoord.xy/u_resolution.xy;
st.x *= u_resolution.x/u_resolution.y;
// Grid
vec2 grid = vec2(100.0,50.);
st *= grid;
vec2 ipos = floor(st); // integer
vec2 vel = floor(vec2(u_time*10.)); // time
vel *= vec2(-1.,0.); // direction
vel *= (step(1., mod(ipos.y,2.0))-0.5)*2.; // Oposite directions
vel *= random(ipos.y); // random speed
// 100%
float totalCells = grid.x*grid.y;
float t = mod(u_time*max(grid.x,grid.y)+floor(1.0+u_time*u_mouse.y),totalCells);
vec2 head = vec2(mod(t,grid.x), floor(t/grid.x));
vec2 offset = vec2(0.1,0.);
vec3 color = vec3(1.0);
color *= step(grid.y-head.y,ipos.y); // Y
color += (1.0-step(head.x,ipos.x))*step(grid.y-head.y,ipos.y+1.); // X
color = clamp(color,vec3(0.),vec3(1.));
// Assign a random value base on the integer coord
color.r *= random(floor(st+vel+offset));
color.g *= random(floor(st+vel));
color.b *= random(floor(st+vel-offset));
color = smoothstep(0.,.5+u_mouse.x/u_resolution.x*.5,color*color); // smooth
color = step(0.5+u_mouse.x/u_resolution.x*0.5,color); // threshold
// Margin
color *= step(.1,fract(st.x+vel.x))*step(.1,fract(st.y+vel.y));
gl_FragColor = vec4(1.0-color,1.0);
}