#version 430 core
layout (points) in;
layout (triangle_strip, max_vertices = 4) out;
in vec4 vColor [];
in vec4 vparams [];
out vec4 gColor;
out float gRadIn;
out vec2 angles;
out vec2 dist;

uniform mat4 worldMat;

void main()
{
  angles = vparams[0].xy;
  vec4 cenPos = gl_in[0].gl_Position;
  gColor = vColor[0];
  float width = vparams[0].w ;
  float rad = vparams[0].z + width;
  gRadIn  = 1 - width * 2 / rad;
  // I am not currently sure why the multiplicand is 4 and not 2

  gl_Position = worldMat * vec4 (cenPos.x + rad, cenPos.y + rad, cenPos.z , 1);
  dist = vec2 (1,1);
  EmitVertex();
  gl_Position = worldMat * vec4 (cenPos.x - rad, cenPos.y + rad, cenPos.z , 1);
  dist = vec2 (-1,1);
  EmitVertex();
  gl_Position = worldMat * vec4 (cenPos.x + rad, cenPos.y - rad, cenPos.z , 1);
  dist = vec2 (1,-1);
  EmitVertex();
  gl_Position = worldMat * vec4 (cenPos.x - rad, cenPos.y - rad, cenPos.z , 1);
  dist = vec2 (-1,-1);
  EmitVertex();

  EndPrimitive();
}
