#version 430 core
layout (points) in;
layout (triangle_strip, max_vertices = 4) out;
in vec2 vRad1[];
in vec2 vRad2[];
in vec2 vCen[];
in float vFactor[];
out vec2 vcpos;
out vec2 texPos;
out vec2 texDist;
out float gfactor;
vec2 g(float x,float y, vec2 v, vec2 r1, vec2 r2)
    { return vec2 
        (dot(normalize(r1-v),vec2(x,y)-v) / length(r1-v)
        ,dot(normalize(r2-v),vec2(x,y)-v) / length(r2-v)
        ); 
    }
void main() {
  vec2 cpos = vCen[0];
  vcpos = cpos;
  vec2 grad1 = vRad1[0];
  vec2 grad2 = vRad2[0];
  gfactor = vFactor[0];
  texPos = vec2(1,1);
  texDist = g(1,1,cpos,grad1,grad2);
  gl_Position = vec4 (1,1,0,1);
  EmitVertex();
  texPos = vec2(1,0);
  texPos = vec2(1,-1);
  texDist = g(1,-1,cpos,grad1,grad2);
  gl_Position = vec4 (1,-1,0,1);
  EmitVertex();
  texPos = vec2(0,1);
  texPos = vec2(-1,1);
  texDist = g(-1,1,cpos,grad1,grad2);
  gl_Position = vec4 (-1,1,0,1);
  EmitVertex();
  texPos = vec2(0,0);
  texPos = vec2(-1,-1);
  texDist = g(-1,-1,cpos,grad1,grad2);
  gl_Position = vec4 (-1,-1,0,1);
  EmitVertex();
  EndPrimitive();
}
