#ifdef GL_ES
//precision mediump float;
#else
#define highp
#define lowp
#define mediump
#endif
uniform vec2 renderTargetSize;
uniform vec4 solidColor;
uniform mat4 modelViewProjectionMatrix;
uniform float lineThickness;
in vec4 vtxColor[2];
flat out vec4 varColor;
layout (lines) in;
layout (triangle_strip, max_vertices = 4) out;
vec3 fixVertex(vec3 vert)
{
//seems like I need to manually clip the lines, otherwise I end up with incorrect lines running across the entire screen
vert.z = clamp(vert.z, 0.0, 1.0);
return vert;
}
void main()
{
vec3 ndc0 = gl_in[0].gl_Position.xyz / gl_in[0].gl_Position.w;
vec3 ndc1 = gl_in[1].gl_Position.xyz / gl_in[1].gl_Position.w;
bool bad = (ndc0.z > 1.0 || ndc1.z > 1.0);
//ndc0 = fixVertex(ndc0);
//ndc1 = fixVertex(ndc1);
vec2 lineScreenForward = normalize(ndc1.xy - ndc0.xy);
vec2 lineScreenRight = vec2(-lineScreenForward.y, lineScreenForward.x);
vec2 lineScreenOffset = (vec2(lineThickness) / renderTargetSize) * lineScreenRight;
gl_Position = vec4(ndc0.xy + lineScreenOffset, ndc0.z, 1.0);
varColor = vtxColor[0];
if(bad)
varColor = vec4(1.0, 0.0, 0.0, 1.0);
EmitVertex();
gl_Position = vec4(ndc0.xy - lineScreenOffset, ndc0.z, 1.0);
varColor = vtxColor[0];
if(bad)
varColor = vec4(1.0, 0.0, 0.0, 1.0);
EmitVertex();
gl_Position = vec4(ndc1.xy + lineScreenOffset, ndc1.z, 1.0);
varColor = vtxColor[1];
if(bad)
varColor = vec4(1.0, 0.0, 0.0, 1.0);
EmitVertex();
gl_Position = vec4(ndc1.xy - lineScreenOffset, ndc1.z, 1.0);
varColor = vtxColor[1];
if(bad)
varColor = vec4(1.0, 0.0, 0.0, 1.0);
EmitVertex();
EndPrimitive();
}