sampler SAMPLER : register (s0);
float4 params : register(c0);
float4 dims : register(c8);
float4 color_for_alpha : register(c3); // Passed through to the BatchRenderer::Draw call

// --------- SOME CONSTANTS ---------
static float PI = 3.14159265359;
// --------- END CONSTANTS ---------

void main(in float2 in_texcoord0 : TEXCOORD0,
         out float4 out_color0 : COLOR0)
{
  float4 color = tex2D(SAMPLER, in_texcoord0);

  float2 vec = float2(in_texcoord0.x - dims.x, in_texcoord0.y - dims.y);
  vec.xy /= dims.zw;
  vec = vec * 2 - 1; // vec now normalized to [-1, 1] range
  vec = vec * float2(1, -1); // vec now in the standard mathy orientation
  //   II  |   I
  //   ---------
  //   III |  IV

  // calculate the theta of this pixel to determine
  // whether it's in the wedge or not
  float arcStart  = params.x;
  float arcLength = params.y;
  float rotOffset = params.z;

  float theta = atan2(vec.y, vec.x) - rotOffset;
  theta += (2*PI) * step(theta, 0.);

  // test to see if the final pixel position is within the arc sweep
  out_color0 = color 
  * step(arcStart, theta)
  * step(theta, arcStart + arcLength);
}
