Im trying to make a tool for skinning 3D models, and as part of that, I need to show faces wireframed, making use of the geometry shader stage.
Im following the approach suggested here and here. My problem however, is that it ends up looking like this:
Where some of the lines get thicker when the faces are oriented in a specific way. This is my geometry shader: (The vertex shader just passes vertices, so theres no need to show it)
#version 400
layout(triangles) in;
layout(triangle_strip, max_vertices = 3) out;
noperspective out vec3 gDist;
void main()
{
//800,600=window size(make uniform later)
vec2 p0 = vec2(800,600) * gl_in[0].gl_Position.xy/gl_in[0].gl_Position.w;
vec2 p1 = vec2(800,600) * gl_in[1].gl_Position.xy/gl_in[0].gl_Position.w;
vec2 p2 = vec2(800,600) * gl_in[2].gl_Position.xy/gl_in[0].gl_Position.w;
vec2 v0=p2-p1;
vec2 v1=p2-p0;
vec2 v2=p1-p2;
float area = abs(v1.x*v2.y - v1.y * v2.x);
gDist = vec3(area/length(v0),0,0);
gl_Position = gl_in[0].gl_Position;
EmitVertex();
gDist = vec3(0,area/length(v1),0);
gl_Position = gl_in[1].gl_Position;
EmitVertex();
gDist = vec3(0,0,area/length(v2));
gl_Position = gl_in[2].gl_Position;
EmitVertex();
EndPrimitive();
}
and frag shader:
#version 400
noperspective in vec3 gDist;
const vec4 wire_color = vec4(0.0,0.5,0.0,1);
const vec4 fill_color = vec4(1,1,1,0);
void main()
{
float d = min(gDist[0],min(gDist[1],gDist[2]));
float i = exp2(-2*d*d);
gl_FragColor = i * wire_color + (1.0 - i) * fill_color;
}
So what am I doing wrong here? I feel like im missing something. Is anyone familiar with this?