thebookofshaders/10/ikeda-03.frag

50 lines
1.2 KiB
GLSL
Raw Normal View History

2015-07-21 20:25:41 +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;
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 21:16:00 +00:00
float pattern(vec2 st, vec2 v, float t) {
vec2 p = floor(st+v);
return step(t, random(100.+p*.000001)+random(p.x)*0.5 );
2015-07-21 20:25:41 +00:00
}
void main() {
vec2 st = gl_FragCoord.xy/u_resolution.xy;
st.x *= u_resolution.x/u_resolution.y;
2015-07-21 21:16:00 +00:00
2015-07-21 21:37:00 +00:00
vec2 grid = vec2(100.0,50.);
st *= grid;
2015-07-21 21:16:00 +00:00
2015-07-22 20:57:47 +00:00
vec2 ipos = floor(st); // integer
vec2 fpos = fract(st); // fraction
2015-07-21 20:25:41 +00:00
2015-07-21 21:37:00 +00:00
vec2 vel = vec2(u_time*2.*max(grid.x,grid.y)); // time
2015-07-22 20:57:47 +00:00
vel *= vec2(-1.,0.0) * random(1.0+ipos.y); // direction
2015-07-21 20:25:41 +00:00
2015-07-21 21:16:00 +00:00
// Assign a random value base on the integer coord
2015-07-21 21:37:00 +00:00
vec2 offset = vec2(0.1,0.);
2015-07-21 20:25:41 +00:00
2015-07-21 21:16:00 +00:00
vec3 color = vec3(0.);
color.r = pattern(st+offset,vel,0.5+u_mouse.x/u_resolution.x);
color.g = pattern(st,vel,0.5+u_mouse.x/u_resolution.x);
color.b = pattern(st-offset,vel,0.5+u_mouse.x/u_resolution.x);
2015-07-21 20:25:41 +00:00
2015-07-21 21:16:00 +00:00
// Margins
2015-07-22 20:57:47 +00:00
color *= step(0.2,fpos.y);
2015-07-21 20:25:41 +00:00
2015-07-21 21:16:00 +00:00
gl_FragColor = vec4(1.0-color,1.0);
2015-07-21 20:25:41 +00:00
}