#version 120

varying vec2 uv0;

uniform float time;

vec3 palette(float d) {
  vec3 v = d + vec3(0.25, 0.40625, 0.5625); // 40 45 49
  v = v * 6.28318548202514648438;
  v = cos(v);
  return vec3(0.5, 0.5, 0.5) * v + vec3(0.5, 0.5, 0.5); // 48
}

float length2(vec2 v)
{
  float n = dot(v, v);
  n = 1.0 / sqrt(n);
  return 1.0 / n;
}

float pow_(float x, float n)
{
  x = log2(x);
  x = x * n;
  return exp2(x);
}

float sin_(float x)
{
  x = x * 0.159154936671257019043 + 0.5; // 48
  x = fract(x); // nop
  x = sin((x - 0.5) * 6.28318548202514648438); // presubtract (omod)
  return x;
}

void main()
{
  vec2 uv = uv0; // temp[1]

  vec4 final_color = vec4(0, 0, 0, 1);

  vec3 col2;

  for (float i = 0.0; i < 1.0; i++) {
    uv = uv * 1.5;            // 60
    uv = fract(uv);
    uv = uv - 0.5;            // 48

    float l = length2(uv0);

    float d = i * 0.4 + l;    // const[0].a
    d = time * 0.4 + d;       // const[0].a

    vec3 col = palette(d);
    col2 = col;
    break;

    d = exp(-l);

    l = length2(uv);
    d = l * d;
    d = d * 8.0 + time;       // 80
    d = 0.125 * sin_(d);      // omod
    d = 1.0 / abs(d);
    d = 0.01 * d;             // const[0].b
    d = pow_(d, 1.2);         // const[0].g

    final_color.xyz = col * d + final_color.xyz;
  }

  //gl_FragColor = final_color;
  gl_FragColor = vec4(col2, 1);
}
