2015-07-22 20:57:47 +00:00
|
|
|
// Author @patriciogv - 2015
|
2016-04-24 15:26:26 +00:00
|
|
|
// Title: DeFrag
|
2015-07-22 20:57:47 +00:00
|
|
|
|
|
|
|
#ifdef GL_ES
|
|
|
|
precision mediump float;
|
|
|
|
#endif
|
|
|
|
|
2021-10-22 12:30:14 +00:00
|
|
|
// 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.
|
|
|
|
|
2015-07-22 20:57:47 +00:00
|
|
|
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
|
2017-08-19 10:11:58 +00:00
|
|
|
|
2015-07-22 20:57:47 +00:00
|
|
|
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
|
2017-08-19 10:11:58 +00:00
|
|
|
|
2015-07-22 20:57:47 +00:00
|
|
|
// 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
|
2015-07-23 14:02:53 +00:00
|
|
|
color = step(0.5+u_mouse.x/u_resolution.x*0.5,color); // threshold
|
2015-07-22 20:57:47 +00:00
|
|
|
|
|
|
|
// Margin
|
|
|
|
color *= step(.1,fract(st.x+vel.x))*step(.1,fract(st.y+vel.y));
|
|
|
|
|
2015-07-23 14:02:53 +00:00
|
|
|
gl_FragColor = vec4(1.0-color,1.0);
|
2017-08-19 10:11:58 +00:00
|
|
|
}
|