
struct VsInput
{
  float4 pos       : POSITION;
  float4 color1    : COLOR0;
  float4 color2    : COLOR1;
  float4 color3    : COLOR2;
};

struct VsOutput
{
  float4 pos       : POSITION;
  float2 cp        : TEXCOORD0;
  float4 color1    : COLOR0;
  float4 color2    : COLOR1;
  float4 color3    : COLOR2;
};


float4 tm          : register(c16);


VsOutput vsh(VsInput I)
{
  VsOutput O;
  O.pos=float4(I.pos.xy*tm.xy+tm.zw, 1, 1);
  O.cp.xy=I.pos.zw;
  O.color1=I.color1;
  O.color2=I.color2;
  O.color3=I.color3;
  return O;
}


float4 psh(VsOutput I) : COLOR
{
  float d=dot(I.cp, I.cp);
  float3 n; n.xy=I.cp; n.z=sqrt(1-d);

  float4 res;
  res.a=I.color1.a;
  res.rgb=lerp(I.color2.rgb, I.color1.rgb,
    smoothstep(-1.0, 0.3, dot(n, normalize(float3(0, -1, -0.8)))));

  res.rgb=lerp(res.rgb,
    lerp(I.color1.rgb*0.5, 1, smoothstep(1, -0.5, n.y)),
    pow(d, 3));

  float a=smoothstep(0, I.color2.a, 1-d);

  res=lerp(I.color3*pow(saturate((2.25-d)/1.25), 2), res, a);

  return res;
}
