shun_iwasawa 36e06f
#ifdef GL_ES
shun_iwasawa 36e06f
precision mediump float;
shun_iwasawa 36e06f
#endif
shun_iwasawa 36e06f
shun_iwasawa 36e06f
// Tweaked from  http://glsl.heroku.com/e#5893.0
shun_iwasawa 36e06f
shun_iwasawa 36e06f
shun_iwasawa 36e06f
uniform mat3 outputToWorld;
shun_iwasawa 36e06f
shun_iwasawa 36e06f
uniform vec4  color1;
shun_iwasawa 36e06f
uniform vec4  color2;
shun_iwasawa 36e06f
uniform float time;
shun_iwasawa 36e06f
shun_iwasawa 36e06f
vec2 Distort(vec2 p)
shun_iwasawa 36e06f
{
shun_iwasawa 36e06f
    float theta  = atan(p.y, p.x);
shun_iwasawa 36e06f
    float radius = length(p);
shun_iwasawa 36e06f
    radius = pow(radius, 1.3);
shun_iwasawa 36e06f
    p.x = radius * cos(theta);
shun_iwasawa 36e06f
    p.y = radius * sin(theta);
shun_iwasawa 36e06f
    return 0.5 * (p + 1.0);
shun_iwasawa 36e06f
}
shun_iwasawa 36e06f
vec4 pattern(vec2 p)
shun_iwasawa 36e06f
{
shun_iwasawa 36e06f
	vec2 m=mod(p.xy+p.x+p.y,2.)-1.;
shun_iwasawa 36e06f
	return vec4(length(m));
shun_iwasawa 36e06f
}
shun_iwasawa 36e06f
shun_iwasawa 36e06f
float hash(const float n)
shun_iwasawa 36e06f
{
shun_iwasawa 36e06f
	return fract(sin(n)*43758.5453);
shun_iwasawa 36e06f
}
shun_iwasawa 36e06f
shun_iwasawa 36e06f
float noise(const vec3 x)
shun_iwasawa 36e06f
{
shun_iwasawa 36e06f
	vec3 p=floor(x);
shun_iwasawa 36e06f
	vec3 f=fract(x);
shun_iwasawa 36e06f
shun_iwasawa 36e06f
    	f=f*f*(3.0-2.0*f);
shun_iwasawa 36e06f
shun_iwasawa 36e06f
    	float n=p.x+p.y*57.0+p.z*43.0;
shun_iwasawa 36e06f
shun_iwasawa 36e06f
    	float r1=mix(mix(hash(n+0.0),hash(n+1.0),f.x),mix(hash(n+57.0),hash(n+57.0+1.0),f.x),f.y);
shun_iwasawa 36e06f
    	float r2=mix(mix(hash(n+43.0),hash(n+43.0+1.0),f.x),mix(hash(n+43.0+57.0),hash(n+43.0+57.0+1.0),f.x),f.y);
shun_iwasawa 36e06f
shun_iwasawa 36e06f
	return mix(r1,r2,f.z);
shun_iwasawa 36e06f
}
shun_iwasawa 36e06f
shun_iwasawa 36e06f
void main( void )
shun_iwasawa 36e06f
{
shun_iwasawa 36e06f
	vec2 position = .01 * (outputToWorld * vec3(gl_FragCoord.xy, 1.0)).xy;
shun_iwasawa 36e06f
shun_iwasawa 36e06f
	float off = noise(position.xyx + time);
shun_iwasawa 36e06f
	vec4 c = pattern(Distort(position+off));
shun_iwasawa 36e06f
shun_iwasawa 36e06f
	c.xy = Distort(c.xy);
shun_iwasawa 36e06f
  
shun_iwasawa 36e06f
  
shun_iwasawa 36e06f
  // ORIGINAL:
shun_iwasawa 36e06f
  // vec4(c.x - off, sin(c.y) - off, cos(c.z), 1.0);
shun_iwasawa 36e06f
shun_iwasawa 36e06f
  // The original green component did not show much. So, the original formula can be written
shun_iwasawa 36e06f
  // as a linear combination of those R and B channels - we generalize that to 2 arbitrary
shun_iwasawa 36e06f
  // colors. Plus, the resulting color is required to be in a premultiplied form.
shun_iwasawa 36e06f
  
shun_iwasawa 36e06f
  vec4 col1 = vec4(color1.rgb * color1.a, color1.a);  // Premultiplication
shun_iwasawa 36e06f
  vec4 col2 = vec4(color2.rgb * color2.a, color2.a);  //
shun_iwasawa 36e06f
  
shun_iwasawa 36e06f
  float coeff1 = c.x - off, coeff2 = cos(c.z);
shun_iwasawa 36e06f
  gl_FragColor = (coeff1 * col1 + coeff2 * col2) / (coeff1 + coeff2);
shun_iwasawa 36e06f
}