ISF - Distortion - Triple Rotate


/*{
	"CATEGORIES": [
		"Geometry Adjustment"
	],
	"DESCRIPTION": "Performs three different rotations",
	"ISFVSN": "2",
	"INPUTS": [
		{
			"NAME": "inputImage",
			"TYPE": "image"
		},
		{
			"NAME": "angle1",
			"TYPE": "float",
			"MAX": 1,
			"DEFAULT": 0,
			"MIN": 0
		},
		{
			"NAME": "angle2",
			"TYPE": "float",
			"MAX": 1,
			"DEFAULT": 0,
			"MIN": 0
		},
		{
			"NAME": "angle3",
			"TYPE": "float",
			"MAX": 1,
			"DEFAULT": 0,
			"MIN": 0
		},
		{
			"NAME": "angle4",
			"TYPE": "float",
			"MAX": 1,
			"DEFAULT": 0,
			"MIN": 0
		},
		{
			"NAME": "radius1",
			"TYPE": "float",
			"MAX": 1,
			"DEFAULT": 0.15,
			"MIN": 0
		},
		{
			"NAME": "radius2",
			"TYPE": "float",
			"MAX": 1,
			"DEFAULT": 0.15,
			"MIN": 0
		},
		{
			"NAME": "radius3",
			"TYPE": "float",
			"MAX": 1,
			"DEFAULT": 0.15,
			"MIN": 0
		}
	],
	"CREDIT": "VIDVOX"
}
*/

const float pi = 3.14159265359;

void main(){
	//	'loc' is the location in pixels of this vertex.  we're going to convert this to polar coordinates (radius/angle)
	vec2		loc = RENDERSIZE * vec2((isf_FragNormCoord.xy)[0],(isf_FragNormCoord.xy)[1]);
	//	'r' is the radius- the distance in pixels from 'loc' to the center of the rendering space
	float		r = distance(RENDERSIZE/2.0, loc);
	//	'a' is the angle of the line segment from the center to loc is rotated
	float		a = atan ((loc.y-RENDERSIZE.y/2.0),(loc.x-RENDERSIZE.x/2.0));

	//	now modify 'a', and convert the modified polar coords (radius/angle) back to cartesian coords (x/y pixels)
	float	angle = angle1;
	float	minSide = min(RENDERSIZE.x,RENDERSIZE.y);
	if (r > (radius1 + radius2 + radius3)*minSide)
		angle = angle4;
	else if (r > (radius1 + radius2)*minSide)
		angle = angle3;
	else if (r > radius1 * minSide)
		angle = angle2;
	loc.x = r * cos(a + 2.0 * pi * angle);
	loc.y = r * sin(a + 2.0 * pi * angle);

	loc = loc / RENDERSIZE + vec2(0.5);

	if ((loc.x < 0.0)||(loc.y < 0.0)||(loc.x > 1.0)||(loc.y > 1.0))	{
		gl_FragColor = vec4(0.0);
	}
	else	{
		gl_FragColor = IMG_NORM_PIXEL(inputImage,loc);
	}
}