#version 150

#define RED vec3(0.6,0,0.3)
#define BLUE vec3(0,0,0.6)
#define WHITE vec3(1,1,1)

float random(vec2 sv) {
    return fract(sin(dot(sv.xy, vec2(12.9898, 78.233))) * 43758.5453);
}

// 2D Value Noise
float noise(vec2 st) {
    vec2 i = floor(st);
    vec2 f = fract(st);

    // Four corners in 2D of a tile
    float a = random(i);
    float b = random(i + vec2(1.0, 0.0));
    float c = random(i + vec2(0.0, 1.0));
    float d = random(i + vec2(1.0, 1.0));

    // Smooth interpolation
    vec2 u = f * f * (3.0 - 2.0 * f);

    // Mix 4 corners
    return mix(a, b, u.x) +
           (c - a) * u.y * (1.0 - u.x) +
           (d - b) * u.x * u.y;
}

float noise_layers(vec2 pos, float speed) {
    float value = 0;
    int dir = 0;
    for (int i = 0; i < 6; i++) {
        vec2 movingUV = pos + vec2(GameTime * sin(dir)*speed, GameTime * cos(dir)*speed);
        float noiseValue = noise(movingUV);

        value += noise(movingUV)/6;
        dir += 60;
    }
    return value;
}