uniform sampler2D tex;
uniform float twirl;
void main(void)
{
	
	vec2 newTCoord=vec2(0,0);
	float radius=sqrt( (gl_TexCoord[0].x-0.5)*(gl_TexCoord[0].x-0.5) +(gl_TexCoord[0].y-0.5)*(gl_TexCoord[0].y-0.5));
	
	
	float degTwirl=2.0*twirl*3.1415926535897932384626433832795/180.0;

        float radiHack= 1.0/( (radius+ 0.18)*12.0);
	float angle=3.1415926535897932384626433832795*(radiHack*(degTwirl*radiHack));//+sign(twirl)*270.0;
	
	newTCoord.x=(gl_TexCoord[0].x-0.5)*cos(angle) + (gl_TexCoord[0].y-0.5)*sin(angle);
	
	newTCoord.y=(gl_TexCoord[0].y-0.5)*cos(angle) - (gl_TexCoord[0].x-0.5)*sin(angle);
	
	newTCoord.x+=0.5;
	newTCoord.y+=0.5;
        newTCoord = clamp(newTCoord,0.01,0.99);
	vec4 value = texture2D(tex,newTCoord);
	gl_FragColor = value;
}

