thebookofshaders/10/ikeda-02.frag

40 lines
1.0 KiB
GLSL
Raw Normal View History

2015-07-21 12:48:27 +00:00
// Author @patriciogv - 2015
// http://patriciogonzalezvivo.com
#ifdef GL_ES
precision mediump float;
#endif
uniform vec2 u_resolution;
uniform vec2 u_mouse;
uniform float u_time;
2015-07-21 21:16:00 +00:00
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);}
2015-07-21 12:48:27 +00:00
void main() {
vec2 st = gl_FragCoord.xy/u_resolution.xy;
2015-07-21 20:25:41 +00:00
st.x *= u_resolution.x/u_resolution.y;
2015-07-21 12:48:27 +00:00
2015-07-21 21:16:00 +00:00
st *= vec2(100.0,50.);
2015-07-22 20:57:47 +00:00
vec2 ipos = floor(st); // integer
vec2 fpos = fract(st); // fraction
2015-07-21 12:48:27 +00:00
vec2 vel = floor(vec2(u_time*10.)); // time
vel *= vec2(-1.,0.); // direction
2015-07-22 20:57:47 +00:00
vel *= (step(1., mod(ipos.y,2.0))-0.5)*2.; // Oposite directions
vel *= random(ipos.y); // random speed
2015-07-21 20:25:41 +00:00
// Move
2015-07-22 20:57:47 +00:00
ipos += floor(vel);
2015-07-21 12:48:27 +00:00
// Assign a random value base on the integer coord
2015-07-22 20:57:47 +00:00
float pct = 1.0;
pct *= random(ipos);
pct *= step(.1,fpos.x)*step(.1,fpos.y); // margin
pct = step(0.001+u_mouse.x/u_resolution.x,pct); // threshold
gl_FragColor = vec4(vec3(pct),1.0);
2015-07-21 12:48:27 +00:00
}