#version 400
layout(triangles) in;
layout(triangle_strip, max_vertices = 3) out;
in vec2 fUV[]; //uv coordinates
out vec2 gUV;
noperspective out vec3 GEdgeDistance;
void main()
{
float a = length(gl_in[1].gl_Position.xyz - gl_in[2].gl_Position.xyz);
float b = length(gl_in[2].gl_Position.xyz - gl_in[0].gl_Position.xyz);
float c = length(gl_in[1].gl_Position.xyz - gl_in[0].gl_Position.xyz);
float alpha = acos( (b*b + c*c - a*a) / (2.0*b*c) );
float beta = acos( (a*a + c*c - b*b) / (2.0*a*c) );
float ha = abs( c * sin( beta ) );
float hb = abs( c * sin( alpha ) );
float hc = abs( b * sin( alpha ) );
gUV=fUV[0];
GEdgeDistance = vec3( ha, 0, 0 );
gl_Position = gl_in[0].gl_Position;
EmitVertex();
gUV=fUV[1];
GEdgeDistance = vec3( 0, hb, 0 );
gl_Position = gl_in[1].gl_Position;
EmitVertex();
gUV=fUV[2];
GEdgeDistance = vec3( 0, 0, hc );
gl_Position = gl_in[2].gl_Position;
EmitVertex();
}
#version 400
in vec2 gUV;
uniform sampler2D png_tex;
uniform float wire_thickness;
noperspective in vec3 GEdgeDistance;
void main()
{
//base fragment color off of which edge is closest
float distance = min(GEdgeDistance[0],min(GEdgeDistance[1],GEdgeDistance[2]));
//draw the each side with different color, displaying the barymetric concept
//if (distance==GEdgeDistance[0])gl_FragColor=vec4(0.52,0,0,1);
//else if (distance==GEdgeDistance[1])gl_FragColor=vec4(0,0.52,0,1);
//else if (distance==GEdgeDistance[2])gl_FragColor=vec4(0,0,0.52,1);
if (distance<wire_thickness)gl_FragColor=vec4(1); //draw fragment if close to edge
else if (distance>=wire_thickness)discard; //discard if not
}