tags:

views:

195

answers:

2

I'm having a problem where drawing a grid using LineList and another (larger) grid overlapping it will make them flicker due to z-fighting. Using DepthBias will reduce that kind of problem when polygons and lines overlap but it apparently doesn't work when drawing lines in two separate DrawIndexedPrimitives calls.

Currently I "fixed" it by adding to the position of the second grid a small vector pointing towards the camera to simulate the DepthBias but the problem still happens when the camera is far from the grids.

Is there a better way to work around this problem?

A: 

From what I've heard you should take a look at your clip-planes. Example thread: xna.com

Edit: Dunno, about grids though, but you could always try! :)

Robelirobban
A: 

Unfortunately, this is the natural behavior due to the limited precision of 32bit floating point numbers (as used by the depth buffer). You can either translate one set of lines minimally (as You do now) and try to chose Your clipping planes as close to each other as possible (as Rob mentioned), or:

  1. Disable the depth buffer by setting device.RenderState.CompareFunction = CompareFunction.Allways, not by actually disabling the buffer!
  2. Draw all Your lines.
  3. Enable the depth buffer again by reversing the changes in step 1.
  4. Draw all Your other geometry.

Dave