random wave

pull/14/head
Patricio Gonzalez Vivo 9 years ago
parent 4056f84d81
commit 1d6dc9b345

@ -9,12 +9,13 @@ 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 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); }
float random (in vec2 st) {
return fract(sin(dot(st.xy, vec2(12.9898,78.233)))* 43758.5453123);
float grid(vec2 st, float res){
vec2 grid = fract(st*res);
return 1.0-(step(0.005*res,grid.x) * step(0.005*res,grid.y));
}
void main() {
@ -23,18 +24,21 @@ void main() {
vec3 color = vec3(0.0);
float t = u_time*24.*2.;
vec2 grid = vec2(100.0,2.0);
float t = u_time*max(grid.x,grid.y);
vec2 grid = vec2(2.0,50.0);
vec2 ipos = floor(st*grid);
vec2 fpos = fract(st*grid);
float value = random(floor(ipos.y+t));// * pow(smoothstep(0.,.2,(1.0-ipos.y/grid.y)),.9)*mix((0.5+ipos.y/grid.y),1.0,1.0-ipos.y/grid.y) ;
float value = random(floor(ipos.x+t));
if (ipos.x == 0.) {
if (mod(ipos.y,2.) == 0.) {
fpos = 1.0-fpos;
}
color += step(fpos.x*1.5,value);
color += step(fpos.y*1.5,value);
color += vec3(0.5,0.,0.)*grid(st,2.)+vec3(0.2)*grid(st,10.0);
gl_FragColor = vec4(color,1.0);
}

@ -26,21 +26,18 @@ void main() {
vec2 st = gl_FragCoord.xy/u_resolution.xy;
st.x *= u_resolution.x/u_resolution.y;
st *= vec2(100.0,50.);
vec2 grid = vec2(100.0,50.);
st *= grid;
vec2 ivec = floor(st); // integer
vec2 fvec = fract(st); // fraction
vec2 vel = vec2(u_time*100.); // time
vel *= vec2(-1.,0.0) * random(ivec.y); // direction
vec2 vel = vec2(u_time*2.*max(grid.x,grid.y)); // time
vel *= vec2(-1.,0.0) * random(1.0+ivec.y); // direction
// vel *= (step(1., mod(ivec.y,2.0))-0.5)*2.; // Oposite directions
// Move
ivec += floor(vel);
// Assign a random value base on the integer coord
vec2 offset = vec2(0.25,0.);
vec2 offset = vec2(0.1,0.);
vec3 color = vec3(0.);
color.r = pattern(st+offset,vel,0.5+u_mouse.x/u_resolution.x);
@ -48,7 +45,7 @@ void main() {
color.b = pattern(st-offset,vel,0.5+u_mouse.x/u_resolution.x);
// Margins
color *= step(0.2,fvec.y);
// color *= step(0.2,fvec.y);
gl_FragColor = vec4(1.0-color,1.0);
}
Loading…
Cancel
Save