Hello everybody,
I would like to render thick lines strarting from a list of points.
This is the geometry shader that takes in input point and creates the thick lines:
////////////////////////////////////////////////////////////////////////////////////////////
#version 330 compatibility
#extension GL_EXT_geometry_shader4 : enable
#define MAX_VERTICES 6
layout(lines_adjacency) in;
layout(triangle_strip, max_vertices = MAX_VERTICES) out;
in vec4 v_position[4]; // Position
void emitTheVertex(vec3 p){
gl_Position = vec4(p, 1.0);
gl_FrontColor = v_color[0];
EmitVertex();
}
void main(void)
{
// Get the 4 vertices and convert them into screen space
vec4 pos0 = gl_ModelViewProjectionMatrix * vec4(v_position[0].xyz, 1.0);
vec4 pos1 = gl_ModelViewProjectionMatrix * vec4(v_position[1].xyz, 1.0);
vec4 pos2 = gl_ModelViewProjectionMatrix * vec4(v_position[2].xyz, 1.0);
vec4 pos3 = gl_ModelViewProjectionMatrix * vec4(v_position[3].xyz, 1.0);
vec3 v0 = pos0.xyz / (pos0.w);
vec3 v1 = pos1.xyz / (pos1.w);
vec3 v2 = pos2.xyz / (pos2.w);
vec3 v3 = pos3.xyz / (pos3.w);
float width = 0.005;
p0 = v1 - n12*width;
p1 = v1 + n12*width;
p2 = v2 - n12*width;
p3 = v2 + n12*width;
emitTheVertex(p0);
emitTheVertex(p1);
emitTheVertex(p2);
emitTheVertex(p3);
EndPrimitive();
}
//////////////////////////////////////////////////////////////////
Sometimes I have a problem when one point is visible and the next is outside the screen. The coordinates of the point outside are different if I move the camera view.
Here there are some images…
[ATTACH=CONFIG]838[/ATTACH]
[ATTACH=CONFIG]839[/ATTACH]
[ATTACH=CONFIG]840[/ATTACH]
… if I get closer…
[ATTACH=CONFIG]841[/ATTACH]
the point outside the screen is placed in the wrong place.
I think this problem is related to the following operation: …pos1.xyz / (pos1.w)…
I divide each point by “w” in order to not keep the perspective (near lines are equal to far lines).
Can anyone help me?
Thanks!