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#5941.2
shun_iwasawa 36e06f
shun_iwasawa 36e06f
//
shun_iwasawa 36e06f
// Description : Array and textureless GLSL 2D/3D/4D 
shun_iwasawa 36e06f
//               noise functions with wrapping
shun_iwasawa 36e06f
//      Author : People
shun_iwasawa 36e06f
//  Maintainer : Anyone
shun_iwasawa 36e06f
//     Lastmod : 20130111 (davidwparker)
shun_iwasawa 36e06f
//     License : No Copyright No rights reserved.
shun_iwasawa 36e06f
//               Freely distributed
shun_iwasawa 36e06f
//
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 detail;
shun_iwasawa 36e06f
uniform float time;
shun_iwasawa 36e06f
shun_iwasawa 36e06f
const float pi_twice = 6.283185307;
shun_iwasawa 36e06f
shun_iwasawa 36e06f
shun_iwasawa 36e06f
float snoise(vec3 uv, float res)
shun_iwasawa 36e06f
{
shun_iwasawa 36e06f
	const vec3 s = vec3(1e0, 1e2, 1e4);
shun_iwasawa 36e06f
	
shun_iwasawa 36e06f
	uv *= res;
shun_iwasawa 36e06f
	
shun_iwasawa 36e06f
	vec3 uv0 = floor(mod(uv, res))*s;
shun_iwasawa 36e06f
	vec3 uv1 = floor(mod(uv+vec3(1.), res))*s;
shun_iwasawa 36e06f
	
shun_iwasawa 36e06f
	vec3 f = fract(uv);
shun_iwasawa 36e06f
	f = f*f*(3.0-2.0*f);
shun_iwasawa 36e06f
shun_iwasawa 36e06f
	vec4 v = vec4(uv0.x+uv0.y+uv0.z, uv1.x+uv0.y+uv0.z,
shun_iwasawa 36e06f
		      uv0.x+uv1.y+uv0.z, uv1.x+uv1.y+uv0.z);
shun_iwasawa 36e06f
shun_iwasawa 36e06f
	vec4 r = fract(sin(v*1e-3)*1e5);
shun_iwasawa 36e06f
	float r0 = mix(mix(r.x, r.y, f.x), mix(r.z, r.w, f.x), f.y);
shun_iwasawa 36e06f
	
shun_iwasawa 36e06f
	r = fract(sin((v + uv1.z - uv0.z)*1e-3)*1e5);
shun_iwasawa 36e06f
	float r1 = mix(mix(r.x, r.y, f.x), mix(r.z, r.w, f.x), f.y);
shun_iwasawa 36e06f
	
shun_iwasawa 36e06f
	return  2.0 * mix(r0, r1, f.z) - 1.0;               // Range in [-1, 1]
shun_iwasawa 36e06f
}
shun_iwasawa 36e06f
shun_iwasawa 36e06f
void main(void) 
shun_iwasawa 36e06f
{
shun_iwasawa 36e06f
  vec2 p = .002 * (outputToWorld * vec3(gl_FragCoord.xy, 1.0)).xy;
shun_iwasawa 36e06f
  
shun_iwasawa 36e06f
  float color   = 3.0 * (1.0 - 2.0 * length(p));
shun_iwasawa 36e06f
	vec3  coord   = vec3(atan(p.y, p.x) / pi_twice, length(p) * 0.4, 0.0);
shun_iwasawa 36e06f
	
shun_iwasawa 36e06f
	for(int i = 1; i <= 7; i++)
shun_iwasawa 36e06f
	{
shun_iwasawa 36e06f
		float power   = pow(2.0, float(i));
shun_iwasawa 36e06f
		vec3  timed   = vec3(0.0, - time*.02, time*.01);
shun_iwasawa 36e06f
    
shun_iwasawa 36e06f
		color        += 1.5 * snoise(coord + timed, power * detail) / power;
shun_iwasawa 36e06f
	}
shun_iwasawa 36e06f
  
shun_iwasawa 36e06f
  color = max(color, 0.);
shun_iwasawa 36e06f
shun_iwasawa 36e06f
shun_iwasawa 36e06f
  // ORIGINAL:
shun_iwasawa 36e06f
	//gl_FragColor = vec4( color, pow(max(color,0.),2.)*0.4, pow(max(color,0.),3.)*0.15 , 1.0);
shun_iwasawa 36e06f
  
shun_iwasawa 36e06f
  vec4 col1 = color1 * color1.a, col2 = color2 * color2.a;
shun_iwasawa 36e06f
  
shun_iwasawa 36e06f
  gl_FragColor    = mix(col1, col2, color / 3.0);
shun_iwasawa 36e06f
  gl_FragColor.a *= smoothstep(0.0, 1.0, color);
shun_iwasawa 36e06f
shun_iwasawa 36e06f
  gl_FragColor.rgb *= gl_FragColor.a;                 // Premultiplication
shun_iwasawa 36e06f
}
shun_iwasawa 36e06f