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

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.x /= dims.z;
    vec.y /= dims.w;
    vec = vec*2-1;

    // calculate the angle of this pixel to determine
    // whether it's part of the remainder or elapsed pie
    float PI = 3.141592653;
    float angle = PI + atan2(vec.x, vec.y);
    // cheat forward a bit to make the fade look a little better
    angle += 0.05;
    
    // angle over which to fade out
    float fadeOutAngle = params.y;

    // default to the passed in color
    out_color0 = color;
    
    // if we've passed the target angle
    if (angle > params.x)
    {
        // then do a non-hue-preserving fade out (because it looks kind of cool to have the color get more extreme as it fades)
        out_color0 -= (angle - params.x) / fadeOutAngle;
    }
    
    // apply HUD alpha
    out_color0.a *= color_for_alpha.a;
}
