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