#include "common.sh"


struct VsInput
{
  float2 xz        : POSITION0;
  float2 wf        : TEXCOORD0;
};

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


VsOutput vsh(VsInput I)
{
  VsOutput O;
  float2 p=I.xz*(2.0/HMAP_SIZE)-1;
  O.pos=float4(p.x, -p.y, 1, 1);
  O.wf=I.wf;
  return O;
}


float4 psh(VsOutput I) : COLOR
{
  float w=I.wf.x, fk=I.wf.y;

  if (w>=0)
  {
    // water
    float foam=lerp(fk, 1, fk*fk*0.7);

    float a=1-fastexp(w*1);

    return float4(lerp(
      float3(0, 0.4*fastexp(w*0.2), 0.8*fastexp(w*0.05)),
      1, foam), a);
  }
  else
  {
    // lava
    //==
    float t=1-fastexp(-w*0.9);
    // t=smoothstep(0.00, 0.95, t);
    return float4(
      lerp(0.04, float3(t+0.5, t*t*0.5, 0), smoothstep(0.05, 0.50, t)),
      1-fastexp(-w*10));
  }
}
