adding ikeda and other random patterns

This commit is contained in:
Patricio Gonzalez Vivo 2015-07-22 16:57:47 -04:00
parent 1d6dc9b345
commit 2f3ce79233
6 changed files with 195 additions and 35 deletions

41
10/2d-random-dots.frag Normal file
View File

@ -0,0 +1,41 @@
// Author @patriciogv ( patriciogonzalezvivo.com ) - 2015
#ifdef GL_ES
precision mediump float;
#endif
uniform vec2 u_resolution;
uniform vec2 u_mouse;
uniform float u_time;
float rows = 10.0;
float circle(vec2 st, float radius){
vec2 pos = vec2(0.5)-st;
radius *= 0.75;
return 1.-smoothstep(radius-(radius*0.01),radius+(radius*0.01),dot(pos,pos)*3.14);
}
float random(in vec2 st){ return fract(sin(dot(st.xy ,vec2(12.9898,78.233))) * 43758.5453); }
void main(){
vec2 st = gl_FragCoord.xy/u_resolution.xy;
st.x *= u_resolution.x/u_resolution.y;
st *= 10.0;
// Offset every other row
st.x -= step(1., mod(st.y,2.0)) * 0.5;
vec2 ipos = floor(st); // integer position
vec2 fpos = fract(st); // float position
// Move Right
ipos += vec2(floor(u_time*-8.),0.);
float pct = random(ipos);
pct *= circle(fpos, 0.5);
// pct = step(0.1+u_mouse.x/u_resolution.x,pct);
// pct = 1.-pct;
gl_FragColor = vec4(vec3(pct),1.0);
}

68
10/digits.frag Normal file
View File

@ -0,0 +1,68 @@
// Author @patriciogv - 2015
// http://patriciogonzalezvivo.com
#ifdef GL_ES
precision mediump float;
#endif
uniform vec2 u_resolution;
uniform float u_time;
float random(in float x){ return fract(sin(x)*43758.5453); }
float random(in vec2 st){ return fract(sin(dot(st.xy ,vec2(12.9898,78.233))) * 43758.5453); }
float bin(vec2 ipos, float n){
float remain = mod(n,33554432.);
for(float i = 0.0; i < 25.0; i++){
if ( floor(i/3.) == ipos.y && mod(i,3.) == ipos.x ) {
return step(1.0,mod(remain,2.));
}
remain = ceil(remain/2.);
}
return 0.0;
}
float char(vec2 st, float n){
st.x = st.x*2.-0.5;
st.y = st.y*1.2-0.1;
vec2 grid = vec2(3.,5.);
vec2 ipos = floor(st*grid);
vec2 fpos = fract(st*grid);
float digit[10];
digit[0] = 31600.;
digit[1] = 9363.0;
digit[2] = 31184.0;
digit[3] = 31208.0;
digit[4] = 23525.0;
digit[5] = 29672.0;
digit[6] = 29680.0;
digit[7] = 31013.0;
digit[8] = 31728.0;
digit[9] = 31717.0;
float pct = bin(ipos, digit[int(floor(mod(n,10.)))]);
vec2 borders = vec2(1.);
// borders *= step(0.01,fpos.x) * step(0.01,fpos.y); // inner
borders *= step(0.0,st)*step(0.0,1.-st); // outer
return step(.5,1.0-pct) * borders.x * borders.y;
}
void main(){
vec2 st = gl_FragCoord.st/u_resolution.xy;
st.x *= u_resolution.x/u_resolution.y;
float rows = 34.0;
vec2 ipos = floor(st*rows);
vec2 fpos = fract(st*rows);
ipos += vec2(0.,floor(u_time*20.*random(ipos.x+1.)));
float pct = random(ipos);
vec3 color = vec3(char(fpos,100.*pct));
color = mix(color,vec3(color.r,0.,0.),step(.99,pct));
gl_FragColor = vec4( color , 1.0);
}

View File

@ -15,23 +15,26 @@ float random (in vec2 _st) { return fract(sin(dot(_st.xy, vec2(12.9898,78.233)))
void main() {
vec2 st = gl_FragCoord.xy/u_resolution.xy;
st.x *= u_resolution.x/u_resolution.y;
vec3 color = vec3(0.0);
st *= vec2(100.0,50.);
vec2 ivec = floor(st); // integer
vec2 fvec = fract(st); // fraction
vec2 ipos = floor(st); // integer
vec2 fpos = fract(st); // fraction
vec2 vel = floor(vec2(u_time*10.)); // time
vel *= vec2(-1.,0.); // direction
// vel *= (step(1., mod(ivec.y,2.0))-0.5)*2.; // Oposite directions
vel *= random(ivec.y); // random speed
vel *= (step(1., mod(ipos.y,2.0))-0.5)*2.; // Oposite directions
vel *= random(ipos.y); // random speed
// Move
ivec += floor(vel);
ipos += floor(vel);
// Assign a random value base on the integer coord
color = vec3(step(.8,random(ivec)));
gl_FragColor = vec4(color,1.0);
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);
}

View File

@ -29,12 +29,11 @@ void main() {
vec2 grid = vec2(100.0,50.);
st *= grid;
vec2 ivec = floor(st); // integer
vec2 fvec = fract(st); // fraction
vec2 ipos = floor(st); // integer
vec2 fpos = fract(st); // fraction
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
vel *= vec2(-1.,0.0) * random(1.0+ipos.y); // direction
// Assign a random value base on the integer coord
vec2 offset = vec2(0.1,0.);
@ -45,7 +44,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,fpos.y);
gl_FragColor = vec4(1.0-color,1.0);
}

55
10/ikeda-04.frag Normal file
View File

@ -0,0 +1,55 @@
// 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);}
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(color,1.0);
}

View File

@ -4,28 +4,20 @@
#ifdef GL_ES
precision mediump float;
#endif
uniform sampler2D u_tex0;
uniform vec2 u_tex0Resolution;
uniform vec2 u_resolution;
uniform vec2 u_mouse;
uniform float u_time;
float random(in float x){
return fract(sin(x)*43758.5453);
}
float random(in float x){ return fract(sin(x)*43758.5453); }
float random(in vec2 st){ return fract(sin(dot(st.xy ,vec2(12.9898,78.233))) * 43758.5453); }
float random(in vec2 st){
return fract(sin(dot(st.xy ,vec2(12.9898,78.233))) * 43758.5453);
}
float randomChar(in vec2 outer,in vec2 inner){
float randomChar(vec2 outer,vec2 inner){
float grid = 5.;
vec2 margin = vec2(.2,.05);
float seed = 23.;
vec2 borders = step(margin,inner)*step(margin,1.-inner);
return step(.5,random(outer*seed+floor(inner*grid))) * borders.x * borders.y;
vec2 ipos = floor(inner*grid);
vec2 fpos = fract(inner*grid);
return step(.5,random(outer*64.+ipos)) * borders.x * borders.y * step(0.01,fpos.x) * step(0.01,fpos.y);
}
void main(){
@ -33,18 +25,20 @@ void main(){
st.y *= u_resolution.y/u_resolution.x;
vec3 color = vec3(0.0);
float rows = 24.0;
float rows = 1.0;
// rows = 3.0;
// rows = 12.0;
// rows = 24.0;
vec2 ipos = floor(st*rows);
ipos += vec2(.0,floor(u_time*20.*random(ipos.x+1.)));
vec2 fpos = fract(st*rows);
vec2 center = (.5-fpos);
float pct = random(ipos);
float glow = (1.-dot(center,center)*3.)*2.0;
ipos += vec2(0.,floor(u_time*20.*random(ipos.x+1.)));
color = vec3(0.643,0.851,0.690) * ( randomChar(ipos,fpos) * pct );
color += vec3(0.027,0.180,0.063) * pct * glow;
float pct = 1.0;
pct *= randomChar(ipos,fpos);
// pct *= random(ipos);
color = vec3(pct);
gl_FragColor = vec4( color , 1.0);
}