xxxxxxxxxx
96
precision mediump float;
in vec2 pos;
out vec4 colour;
uniform float millis;
const float TIME_SCALE = 0.0001;
const vec4 low = vec4(0.165,0.345,0.31, 1.);
const vec4 high = vec4(0.988,1.,0.753, 1.);
float rand(vec2 p) {
return fract(sin(dot(p, vec2(12.9898,78.233)))*43758.5453123);
return fract(sin(dot(p, vec2(14.234523, 120.9812879)))*23.234234);
}
float noise(vec2 p) {
vec2 i = floor(p); // integer part
vec2 f = fract(p); // fractional part
// get noise values for the four corners of a square
float a = rand(i);
float b = rand(i + vec2(1.0, 0.0));
float c = rand(i + vec2(0.0, 1.0));
float d = rand(i + vec2(1.0, 1.0));
// add smoothing to the position
f = smoothstep(0., 1., f);
// interpolate between the corner values
return mix(mix(a, b, f.x), mix(c, d, f.x), f.y);
}
// Simple rotation matrix
const mat2 rot = mat2(1.);//mat2(0.8, 0.6, -0.6, 0.8);
const int numOctaves = 6;
float fbm(vec2 p) {
float f = 0.;
vec2 shift = vec2(100.);
float amp = 1.;
float totalAmp = 0.;
for(int i = 0; i < numOctaves; i ++) {
float spice = 0.;
if(i == numOctaves/2 || i == numOctaves - 1) {
spice = millis/1000.;
}
f += amp * noise(p + spice);
totalAmp += amp;
float scale = 2. + rand(vec2(float(i)))/5.;
amp /= scale;
p = p * rot * scale + shift;
}
f /= totalAmp;
return f;
}
float pattern(vec2 p) {
return fbm(p + fbm(p + fbm(p)));
}
void main() {
float v = 1.;
// 1. Random numbers
v = rand(floor((pos) * 10. + 0.5));// * millis/100.);
// 2. Smooth noise
v = noise(pos * 10.);
//3. Fractal brownian motion
v = fbm(pos * 10.);
//4. Domain warping
// v = pattern(pos * 10.);
float n = 4.;
// v = round(pattern(pos * 10.) * n)/n;
colour = mix(low, high, v);
}