#version 330
 
uniform sampler2D t;
uniform vec2 size;
uniform float zo;
uniform float mult; 

in vec4 color;
in float vertexFade;

smooth in vec4 vPosition;
smooth in vec4 vPrevPosition;
smooth in vec4 maskPosition;

layout(location = 0) out vec4 output;

void main()
{
  vec2 uv = gl_FragCoord.xy / size;

  float amp = 0.1;
  float freq = 1.0 - zo * mult * 1.0;
  float phase = -pow(zo * mult, 0.5) * 2.5;

  float dif = (uv.y + amp * cos(phase + uv.x * 2.0 * 3.141592654 * freq)) - (-amp + ((1.0 + 2.0 * amp) * clamp(zo * mult, 0.0, 1.0)));
  
  dif = (dif);
  
    float feather = 0.001;
    if (dif > -feather && dif < feather)
    {
      dif += feather;
      dif /= (2.0 * feather);
    }
    else if (dif <= -feather)
    {
      dif = 0.0;
    }
    else if (dif >= feather)
    {
      dif = 1.0;
    } 
    
    /*float dif;
    if ((uv.y + amp * cos(phase + uv.x * 2.0 * 3.141592654 * freq)) < (-amp + ((1.0 + 2.0 * amp) * clamp(zo * mult, 0.0, 1.0))))
    { 
      dif = 0.0;
    }
    else
    {
      dif = 1.0;
    }  */

    
  output = vec4(color.rgb, mix(color.a, 0.0, dif));
  
  
  /*if (dif < 0.0)
    output = color;
  else
    output = vec4(color.rgb, 0.0);*/  
}