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#6051.0
shun_iwasawa 36e06f
shun_iwasawa 36e06f
shun_iwasawa 36e06f
// Posted by Trisomie21 : 2D noise experiment (pan/zoom)
shun_iwasawa 36e06f
//
shun_iwasawa 36e06f
// failed attempt at faking caustics
shun_iwasawa 36e06f
//
shun_iwasawa 36e06f
shun_iwasawa 36e06f
shun_iwasawa 36e06f
uniform mat3 outputToWorld;
shun_iwasawa 36e06f
shun_iwasawa 36e06f
uniform vec4  color;
shun_iwasawa 36e06f
uniform float time;
shun_iwasawa 36e06f
shun_iwasawa 36e06f
shun_iwasawa 36e06f
vec4 textureRND2D(vec2 uv){
shun_iwasawa 36e06f
	uv = floor(uv);
shun_iwasawa 36e06f
	float v = uv.x+uv.y*1e3;
shun_iwasawa 36e06f
shun_iwasawa 36e06f
  // Build space-specific corner values
shun_iwasawa 36e06f
  vec4 res = fract(1e5*sin(vec4(v*1e-2, (v+1.)*1e-2, (v+1e3)*1e-2, (v+1e3+1.)*1e-2)));
shun_iwasawa 36e06f
shun_iwasawa 36e06f
  // Add 'sawtooth-like'  wavefronts evolution
shun_iwasawa 36e06f
  return 2.0 * abs(fract(res + vec4(time * .03)) - 0.5);
shun_iwasawa 36e06f
}
shun_iwasawa 36e06f
shun_iwasawa 36e06f
float noise(vec2 p) {
shun_iwasawa 36e06f
  vec4 r = textureRND2D(p);                           // Noise values at cell corners
shun_iwasawa 36e06f
  
shun_iwasawa 36e06f
  vec2 f = fract(p);
shun_iwasawa 36e06f
	f = f*f*(3.0-2.0*f);                                // aka the smoothstep() builtin function
shun_iwasawa 36e06f
  
shun_iwasawa 36e06f
	return (mix(mix(r.x, r.y, f.x), mix(r.z, r.w, f.x), f.y));
shun_iwasawa 36e06f
}
shun_iwasawa 36e06f
shun_iwasawa 36e06f
float buildColor(vec2 p) {
shun_iwasawa 36e06f
  p += noise(p);                                      // Noising p itself first. This helps
shun_iwasawa 36e06f
                                                      // preventing grid-like patterns.
shun_iwasawa 36e06f
  
shun_iwasawa 36e06f
	float v = 1.0 - abs(pow(abs(noise(p) - 0.5), 0.75)) * 1.7;  // Lots of magical constants  o_o?
shun_iwasawa 36e06f
	return v;
shun_iwasawa 36e06f
}
shun_iwasawa 36e06f
shun_iwasawa 36e06f
shun_iwasawa 36e06f
const float SPEED   = .15;
shun_iwasawa 36e06f
shun_iwasawa 36e06f
void main( void ) {
shun_iwasawa 36e06f
	vec2 p = (outputToWorld * vec3(gl_FragCoord.xy, 1.0)).xy;
shun_iwasawa 36e06f
  
shun_iwasawa 36e06f
	float c1 = buildColor(p*.03 + time * SPEED);
shun_iwasawa 36e06f
	float c2 = buildColor(p*.03 - time * SPEED);
shun_iwasawa 36e06f
	
shun_iwasawa 36e06f
	float c3 = buildColor(p*.02 - time * SPEED);
shun_iwasawa 36e06f
	float c4 = buildColor(p*.02 + time * SPEED);
shun_iwasawa 36e06f
	
shun_iwasawa 36e06f
	float cf = pow(c1*c2*c3*c4+0.5,6.);                 // Yep this is bad. Explicitly
shun_iwasawa 36e06f
                                                      // dependent on the 4 above. Better?
shun_iwasawa 36e06f
	vec3 c = vec3(cf);
shun_iwasawa 36e06f
	gl_FragColor = vec4(c, 0.0) + color;
shun_iwasawa 36e06f
  
shun_iwasawa 36e06f
  gl_FragColor.rgb *= gl_FragColor.a;                 // Premultiplication
shun_iwasawa 36e06f
}