From 1614d59b9ae0e0dc72a4ade57ae6fc9de98e2105 Mon Sep 17 00:00:00 2001 From: Patricio Gonzalez Vivo Date: Thu, 10 Sep 2015 12:49:53 -0400 Subject: [PATCH] adding fractals --- 08/matrices.frag | 83 ++++++++++++++++++++++++++++++++++++++++++++ 11/2d-voronoi.frag | 5 ++- 11/warp-grid.frag | 47 +++++++++++++++++++++++++ 13/fractal-tile.frag | 45 ++++++++++++++++++++++++ 4 files changed, 177 insertions(+), 3 deletions(-) create mode 100644 08/matrices.frag create mode 100644 11/warp-grid.frag create mode 100644 13/fractal-tile.frag diff --git a/08/matrices.frag b/08/matrices.frag new file mode 100644 index 0000000..89a8ab3 --- /dev/null +++ b/08/matrices.frag @@ -0,0 +1,83 @@ +#ifdef GL_ES +precision mediump float; +#endif + +#define PI 3.1415926535897932384626433832795 +#define PI_2 1.57079632679489661923 +#define PI_4 0.785398163397448309616 +#define PI180 .017453293 + +float PHI = (1.0+sqrtf(5.0))/2.0; +float sind(float a){return sin(a * PI180);} +float cosd(float a){return cos(a * PI180);} + +uniform vec2 u_resolution; +uniform float u_time; + +mat2 rotate2D(float angle){ + return mat2(cos(angle),-sin(angle), + sin(angle),cos(angle)); +} + +mat3 rotateX3D(float phi){ + return mat3( + vec3(1.,0.,0.), + vec3(0.,cos(phi),-sin(phi)), + vec3(0.,sin(phi),cos(phi))); +} + +mat4 rotateX4D(float phi){ + return mat4( + vec4(1.,0.,0.,0), + vec4(0.,cos(phi),-sin(phi),0.), + vec4(0.,sin(phi),cos(phi),0.), + vec4(0.,0.,0.,1.)); +} + +mat3 rotateY3D(float theta){ + return mat3( + vec3(cos(theta),0.,-sin(theta)), + vec3(0.,1.,0.), + vec3(sin(theta),0.,cos(theta))); +} + +mat4 rotateY4D(float theta){ + return mat4( + vec4(cos(theta),0.,-sin(theta),0), + vec4(0.,1.,0.,0.), + vec4(sin(theta),0.,cos(theta),0.), + vec4(0.,0.,0.,1.)); +} + +mat3 rotateZ3D(float psi){ + return mat3( + vec3(cos(psi),-sin(psi),0.), + vec3(sin(psi),cos(psi),0.), + vec3(0.,0.,1.)); +} + +mat4 rotateZ4D(float psi){ + return mat4( + vec4(cos(psi),-sin(psi),0.,0), + vec4(sin(psi),cos(psi),0.,0.), + vec4(0.,0.,1.,0.), + vec4(0.,0.,0.,1.)); +} + +mat4 scale4D(float x, float y, float z){ + return mat4( + vec4(x, 0.0, 0.0, 0.0), + vec4(0.0, y, 0.0, 0.0), + vec4(0.0, 0.0, z, 0.0), + vec4(0.0, 0.0, 0.0, 1.0) + ); +} + +mat4 translate4D(float x, float y, float z){ + return mat4( + vec4(1.0, 0.0, 0.0, 0.0), + vec4(0.0, 1.0, 0.0, 0.0), + vec4(0.0, 0.0, 1.0, 0.0), + vec4(x, y, z, 1.0) + ); +} \ No newline at end of file diff --git a/11/2d-voronoi.frag b/11/2d-voronoi.frag index 910c429..952ed47 100644 --- a/11/2d-voronoi.frag +++ b/11/2d-voronoi.frag @@ -67,11 +67,10 @@ void main() { // isolines color = c.x*(0.5 + 0.5*sin(64.0*c.x))*vec3(1.0); // borders - color = mix( vec3(1.0,0.6,0.0), color, smoothstep( 0.01, 0.02, c.x ) ); + color = mix( vec3(1.0,.0,.0), color, smoothstep( 0.01, 0.02, c.x ) ); // feature points float dd = length( c.yz ); - color = mix( vec3(1.0,0.6,0.1), color, smoothstep( 0.0, 0.12, dd) ); - color += vec3(1.0,0.6,0.1)*(1.0-smoothstep( 0.0, 0.04, dd)); + color += vec3(.0,1.,1.)*(1.0-smoothstep( 0.0, 0.04, dd)); gl_FragColor = vec4(color,1.0); } \ No newline at end of file diff --git a/11/warp-grid.frag b/11/warp-grid.frag new file mode 100644 index 0000000..119de02 --- /dev/null +++ b/11/warp-grid.frag @@ -0,0 +1,47 @@ +#ifdef GL_ES +precision mediump float; +#endif + +uniform vec2 u_resolution; +uniform vec2 u_mouse; +uniform float u_time; + +vec2 random2(vec2 st){ + st = vec2( dot(st,vec2(127.1,311.7)), + dot(st,vec2(269.5,183.3)) ); + return -1.0 + 2.0*fract(sin(st)*43758.5453123); +} + +// Value Noise by Inigo Quilez - iq/2013 +// https://www.shadertoy.com/view/lsf3WH +float noise(vec2 st) { + vec2 i = floor(st); + vec2 f = fract(st); + + vec2 u = f*f*(3.0-2.0*f); + + return mix( mix( dot( random2(i + vec2(0.0,0.0) ), f - vec2(0.0,0.0) ), + dot( random2(i + vec2(1.0,0.0) ), f - vec2(1.0,0.0) ), u.x), + mix( dot( random2(i + vec2(0.0,1.0) ), f - vec2(0.0,1.0) ), + dot( random2(i + vec2(1.0,1.0) ), f - vec2(1.0,1.0) ), u.x), u.y); +} + +float grid(vec2 st, float res){ + vec2 grid = fract(st*res); + return 1.-(step(res,grid.x) * step(res,grid.y)); +} + +void main() { + vec2 st = gl_FragCoord.xy/u_resolution.xy; + st.x *= u_resolution.x/u_resolution.y; + vec3 color = vec3(0.0); + + // Grid + vec2 grid_st = (st+1.)*(290.+noise(st*5.+u_time)*10.); + + color += vec3(0.2,0.,0.)*grid(grid_st,0.01); + color += vec3(0.1,0.,0.)*grid(grid_st,0.02); + color += vec3(0.1)*grid(grid_st,0.1); + + gl_FragColor = vec4(1.0-color,1.0); +} \ No newline at end of file diff --git a/13/fractal-tile.frag b/13/fractal-tile.frag new file mode 100644 index 0000000..8b61b89 --- /dev/null +++ b/13/fractal-tile.frag @@ -0,0 +1,45 @@ +#ifdef GL_ES +precision mediump float; +#endif + +uniform vec2 u_resolution; +uniform float u_time; + +float random(in vec2 st){ return fract(sin(dot(st.xy ,vec2(12.9898,78.233))) * 43758.5453); } + +vec2 tileFractal(vec2 st) { + vec2 f = fract(st); + vec2 i = floor(st); + + return fract(st*pow(2.,floor(random(i)*5.))); +} + +float circle(vec2 st, float radius){ + vec2 pos = vec2(0.5)-st; + radius *= 0.75; + return 1.-smoothstep(radius-(radius*0.05),radius+(radius*0.05),dot(pos,pos)*3.14); +} + +float box(vec2 st, vec2 size){ + size = vec2(0.5)-size*0.5; + vec2 uv = smoothstep(size,size+vec2(1e-4),st); + uv *= smoothstep(size,size+vec2(1e-4),vec2(1.0)-st); + return uv.x*uv.y; +} + +void main() { + vec2 st = gl_FragCoord.xy/u_resolution; + vec3 color = vec3(0.0); + + st *= 3.; + st = tileFractal(st); + + float pct = 0.; + pct = circle(st,.999); + // pct = box(st,vec2(.95)); + + color.rg = st; + color.rgb = vec3(1.)*pct; + + gl_FragColor = vec4(color,1.); +} \ No newline at end of file