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