Week 3

I call this one spaghetti.

download-8 download-10


// 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;
#define PI 3.14159265358979323846
float random (in vec2 st) {
return fract(sin(dot(st.xy,
vec2(0.360,0.320)))
* 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)+sin(u_time*0.1);
vec2 u = f*f*(3.0-2.0*f);
return mix( mix( random( i + vec2(0.0,0.0) ),
random( i + vec2(1.0,0.0) ), u.x),
mix( random( i + vec2(0.0,1.0) ),
random( i + vec2(1.0,1.0) ), u.x), u.y);
}

mat2 rotate2d(float angle){
return mat2(cos(angle),-sin(angle),
sin(angle),cos(angle));
}
vec2 rotatePattern(vec2 _st, float _angle){
_st -= 0.5;
_st = mat2(cos(_angle),-sin(_angle),
sin(_angle),cos(_angle)) * _st;
_st += -0.596;
return _st;
}

vec2 tile(vec2 _st, float _zoom){
_st *= _zoom;
return fract(_st);
}
float lines(in vec2 pos, float b){
float scale = 1.600;
pos *= scale;
return smoothstep(0.0,
.5+b*.5,
abs((sin(pos.x*u_time/25.0)+b*abs(sin((u_time)))))*.5);
}
vec2 rotateTilePattern(vec2 _st){

// Scale the coordinate system by 2x2
_st *= 2.0;

// Give each cell an index number
// according to its position
float index = 0.0;
index += step(1., mod(_st.x,2.0));
index += step(1., mod(_st.y,2.0))*2.0;

// |
// 2 | 3
// |
//--------------
// |
// 0 | 1
// |

// Make each cell between 0.0 - 1.0
_st = fract(_st);

// Rotate each cell according to the index
if(index == 1.0){
// Rotate cell 1 by 90 degrees
_st = rotatePattern(_st,PI*0.25);
} else if(index == 2.0){
// Rotate cell 2 by -90 degrees
_st = rotatePattern(_st,PI*-.75);
} else if(index == 3.0){
// Rotate cell 3 by 180 degrees
_st = rotatePattern(_st,PI*.75);
}
else{
_st = rotatePattern(_st,PI*-.25);
}

return _st;
}

void main() {
vec2 st = gl_FragCoord.xy/u_resolution.xy;
st = tile(st,1.);
st = rotateTilePattern(st);
st.y *= u_resolution.y/u_resolution.x;

vec2 pos = st.yx*vec2(0.990,0.960);
vec3 color = vec3(0.0);
float pattern = pos.x;
// Add noise
pos = rotate2d( noise(pos) ) * pos;

// Draw lines
pattern = lines(pos,.5);

gl_FragColor = vec4(vec3(1.0,pattern*.9,0.25),1.0);
}

It’s getting hard for me to add on to my old code because the functions tend to feel overwhelming so I decided to start fresh using the wood example created by¬†@patriciogv. I love the endless possibilities of using noise and I’m interested in learning more about Perlin noise.

Leave a Reply