/*
 * Shockwave Shader
 * From: 		http://www.geeks3d.com/20091116/shader-library-2d-shockwave-post-processing-filter-glsl/
 * Original: 	http://empire-defense.crystalin.fr/blog/2d_shock_wave_texture_with_shader
 *
 * Inputs:
 * 	center (vec2): 			mouse position (in texture coord space: [0 ; 1]).
 * 	time (float): 			shockwave elapsed time in second.
 * 	shockParams (vec3): 	shockwave parameters
 *
 *  shockParams[0]: "depth distance" modifier. larger is flatter, ish. / outer edge of thing
 *  shockParams[1]: "zoom" depth
 *  shockParams[2]: "size" / timer to check against.
 *
 */

#version 130 
precision highp float;

// input
uniform sampler2D ark_TextureId;

uniform vec2 center; 			// Mouse position
uniform float time; 			// effect elapsed time 
uniform vec3 shockParams; 		// 10.0, 1.0, 0.1

// in vec4 ark_VertexColorOut;
in vec2 ark_VertexTexCoordOut;

// output
out vec4 ark_FragColor;

void main(void) 
{  
	vec2 uv = ark_VertexTexCoordOut;
	vec2 texCoord = uv;
	float distance = distance(uv, center);
	if ( (distance <= (time + shockParams.z)) && 
       (distance >= (time - shockParams.z)) ) 
	{
		float diff = (distance - time); 
		float powDiff = 1.0 - pow( abs(diff*shockParams.x), shockParams.y ); 
		float diffTime = diff  * powDiff; 
		vec2 diffUV = normalize(uv - center); 
		texCoord = uv + (diffUV * diffTime);
	} 
	ark_FragColor = texture(ark_TextureId, texCoord); // * ark_VertexColorOut;
}