Clean Wireframe Over Solid Mesh

What is the easiest way to get a clean wireframe over the same mesh that has its polys filled?

At the moment, (because of z-fighting i assume) a simple fill version draw then wire version draw has patchy wireframe lines. Apart from displacing the wireframe ever-so-slightly from the filled surface, is there a way of getting clean wires?

Instead of scaling the object, you can move each vertex along its normal when drawing the wired object. This way you are sure that whatever the object dimensions, all its vertices with displaced of the same distance. (This is not the case with a uniform scale).

One quick and dirty solution is to set the line thickness to 3 or more pixels.

Moving wireframe mesh a little towards the camera works really well.

The best and easiest that i have been able to come up with is to write a vertex-shader, that moves the vertices into the direction of the viewer. This is pretty simple to do, render you mesh as when you fill it only with fill-mode set to lines. Then use this vertex shader:

void main()
{
vec4 v = gl_ModelViewMatrix * gl_Vertex;
v.xyz = v.xyz * 0.99;

gl_Position = gl_ProjectionMatrix * v;

}

This first transforms the vertex into camera space, than scales it, such that it moves to the camera, and finally applies the projection. Results are perfect because since it is a scaling it moves the vertex more at the far-plane and less at the front-plane.

Hope that helps,
Jan.

Good Answers :slight_smile:

Thanks guys

glPolygonOffset?

Also, check out this one page paper: Single-pass Wireframe Rendering. A fragment shader is used to compute the shortest distance from a fragment the triangle’s edges. This distance is then mapped to an intensity. Sounds pretty straightforward to implement although I’ve never coded it.

Patrick

That looks like a clever, but simple solution … Thanks For That Link!