View Full Version : Wireframe (line draw) and Z-Fighting

01-14-2010, 12:51 PM
I work on a piece of modeling software that draws a wireframe display into a viewport and I have been tasked with the job of improving the quality of the line draw. One of my biggest problems is the Z-fighting that occurs between multiple lines drawn in the same spot.

Imagine two planes side by side (models are far more complex but lets keep this simple) that have 2 nearly shared (yet not identical) vertices. If we draw the planes a different color (there are a variety of reasons why we draw things in different colors, that has to work and I cannot change it) then when you draw the shared edge both lines get drawn using nearly the same vertices and Z-fighting occurs.

I have tried Polygon offset, it does not work very well. It can make the problem somewhat less severe but overall the problem is still very evident.

I have tried transparency and blending but it brings the application to a crawl when large models are loaded.

I am unable to disable writes to the depth buffer when drawing the wireframe because we need the depth information later in the draw to perform blending with various transparent objects.

I am unable to disable the depth test as the wireframe draw must fit correctly into the scene with any other objects that are present.

I cannot merge the vertices (thus creating only a single edge) as I don't have control over the data creation, just the draw.

I have tried using GL_LINE_SMOOTH and GL_MULTISAMPLE to reduce the fighting and (much like polygon offset) it helps a little but the problem is still very evident.

I have tried drawing the wireframe twice, once with depth writes off (to prevent the z-fighting with other lines that have been drawn.. this gets the proper information into the framebuffer) and then again with depth writes on but with the framebuffer masked (to disable writes to the framebuffer). This technique works.. but is WAY too slow.

Anyone have some other suggestions I could try? I know.. I am painted in a corner but no harm in asking right?

Mikkel Gjoel
01-15-2010, 05:59 AM
I will just very quickly refer you to this page


- and add a couple of additional links to more info on the subject





01-15-2010, 03:43 PM
Does anyone know the specifics of how Maya or Max implemented wireframe overlays in the fixed function-only days?

01-17-2010, 12:58 AM
cheers for the links Mikkel, pretty straight forward when u think about it

U might wanna recheck how max does its lines, heres my version (old I think max4)
this is with software rendering