
struct VsOutput
{
  float4 pos: POSITION;
  float2 tc : TEXCOORD0;
};

float4 ofs   : register(c16);
float4 texsz : register(c17);

VsOutput vsh(float2 pos : POSITION)
{
  VsOutput O;
  float2 p=pos*ofs.xy+ofs.zw;
  O.pos=float4(p, 1, 1);
  O.tc=p*texsz.xy+texsz.zw;
  return O;
}


sampler aperTex : register(s0);


float4 psh(VsOutput I) : COLOR
{
  float4 aper=tex2D(aperTex, I.tc);
  aper.xzw=aper.xzw*2-1;
  aper.y=sqrt(1-dot(aper.xz, aper.xz));

  float3 light=0;
  light+=(1-aper.w)*float3(0.1, 0.4, 1)*0.5;

  float4 sun_dir=float4(-0.57735, 0.57735, 0.57735, 0.93969);

  float c=dot(aper.xyz, sun_dir.xyz);
  float ca=aper.w, cb=sun_dir.w;

  float cc=ca*cb, ss=sqrt((1-ca*ca)*(1-cb*cb));
  float maxc=cc+ss;
  float f=smoothstep(cc-ss, maxc, c)*(1-maxc);

  light+=float3(1, 0.6, 0.1)*f;

  return float4(light, 1);
}
