how to solve z-fighting

Started by
3 comments, last by 21st Century Moose 7 years, 10 months ago

two plane is same height, the below picture :

[attachment=32233:360??20160611170253851.jpg]

can you see the red part, there's a box under the plane, and the upper face of the box has the same height as the plane...

Is this call "flick" ?

how can I solve it ?

Advertisement

The best way to fix z-fighting is to move your geometry so that it doesn't z-fight.

Depending on which API you're using, there may be features available that can help to hide the effects of z-fighting. In OpenGL it would be polygon offset, in Direct3D it would be depth bias. But these are just a collection of hacks and tricks and may have unwanted side-effects. OpenGL's polygon offset is particularly bad because the specification allows it to be implementation-dependent. They also may not interact too well with a common non-linear depth buffer.

So the only real "fix" is to actually get it right to begin with.

Direct3D has need of instancing, but we do not. We have plenty of glVertexAttrib calls.

I always avoid depth bias style approaches because they're never very portable across different rendering APIs. I prefer to use a different projection matrix with an ever-so-slightly reduced field-of-view for decal rendering.

The best way to fix z-fighting is to move your geometry so that it doesn't z-fight.

Yeah, co-planar geometry will z-fight... unless they share exactly the same vertices data and run the same vertex shader.

So basically, co-planar faces is an art bug - you need to fix the art.

If you have z-fighting in other situations, the first thing to do is to increase your near-clip value. There's also different Z-buffer formats, different projection types, reversed projections, infinite far planes, etc...

Yeah, co-planar geometry will z-fight... unless they share exactly the same vertices data and run the same vertex shader.


My experience is that you also need the very same input assembler setup, as well as the same matrices. For example:

out.Position = mul (m1, mul (m2, in.Position));
out.Position = mul (m3, in.Position);


Assume that m3 = m1 * m2. This will probably z-fight.

device->DrawPrimitive (D3DPT_TRIANGLEFAN, ....);
device->DrawIndexedPrimitive (D3DPT_TRIANGLELIST, ....);


Assume that otherwise everything is identical and these are drawing the same geometry. This will also z-fight on certain hardware (*cough* Intel *cough*).

So to slightly contradict my initial statement; it's also important to ensure that one is not in a situation that actually causes z-fighting when otherwise there would be none.

Direct3D has need of instancing, but we do not. We have plenty of glVertexAttrib calls.

This topic is closed to new replies.

Advertisement