#include <system.vsh>

//shader constants which is populated from game code
float2 TwistOriginPoint;
float TwistGradient;
float TwistStrength;

VS_OUT vs_main(VS_IN In) {	
	VS_OUT Out;
	
	//calculate point relative to origin point
	float2 posVector = In.Pos.xy - TwistOriginPoint;
	//find angle and length in radians of point relative to origin point
	float angle = atan2(posVector.y, posVector.x);
	float length = sqrt(posVector.x * posVector.x + posVector.y * posVector.y);
	//modify angle depending on distance to origin point
	angle += TwistStrength * (length / TwistGradient) * (length / TwistGradient);
	//calculate modified point coordinates
	float2 newPoint = TwistOriginPoint + float2 (cos(angle) * length, sin(angle) * length);
	
	//calculate position of point in device scale
	Out.Pos.xy = __TransformXY(newPoint);
	//copy rest of values
	Out.Pos.z = In.Pos.z;
	Out.Pos.w = 1.0;
	Out.Color = In.Diffuse;
	Out.Tex0 =  In.Tex0;
	Out.Tex1 =  In.Tex1;
	
	return Out;	
}