Rainbow Spiral

Rainbow Spiral

Shader loading...

View Source Code
#ifdef GL_ES
precision mediump float;
#endif

// A palette function that creates a colorful rainbow from a parameter t.
vec3 palette( float t, vec3 a, vec3 b, vec3 c, vec3 d ){
  return a + b * cos(6.28318 * (c * t + d));
}

void main(void) {
  vec2 uv = gl_FragCoord.xy / u_resolution.xy;
  vec2 p = (uv - 0.5) * vec2(u_resolution.x/u_resolution.y, 1.0);
  
  float r = length(p);
  float angle = atan(p.y, p.x);
  
  float t = u_time * 0.5 + r * 5.0 + sin(angle * 4.0);
  
  vec3 color = palette(
    t, 
    vec3(0.5),
    vec3(0.5),
    vec3(1.0,1.0,1.0),
    vec3(0.0, 0.33, 0.67)
  );
  gl_FragColor = vec4(color, 1.0);
}