From: | Hans-Joerg Frieden |
Date: | 15 Aug 2001 at 00:29:34 |
Subject: | Re: [3DWorld] Z buffer inaccuracies. |
On Tuesday 14 August 2001 20:14, Michal Wozniak wrote:
> I have some problems with Z buffer. If I draw
> 2 parallel objects (lets say cylinder in cylinder)
> that are nearly perpedicular (is it spelled right?)
> to the screen plane, I get the inner cylinder
> "move out" from the outer one. Is it supposed
> to happen?
I suspect that the surfaces in question are very close together. The problem
then is that the ZBuffer is not a floating point buffer but an integer
buffer. Although the Z range of [0..1] is scaled to the interval [0...327676]
or [0..65535] there is still a quantization effect, more so since most of the
time Z coordinates tend to "cluster", that is, they tend to only use a
fraction of the actual zbuffer range... The reason for this is that most of
the time you will be using the untransformed Z from camera space to save
yourself the hassle of transforming Z beyond clip space.
The result of this is that you get jagged "saw-tooth" edges where surfaces
penetrate each other.
There are two possible solutions for this problem, depending on the
environment you're using.
Under MiniGL, use a smaller depth range. When you specify the front and back
clip plane, use values that are closer together. This spreads the surfaces in
Z space.
Under Warp3D directly (i.e. if you have direct access to the W3D_Vertex
structure) you can use a different Z value. One possible course of action is
to directly use the w value for the z value and reverse the ZCompare
function, i.e. instead of e.g. Z_LESS use Z_GEQUAL.
Alternatively you can use different Z calculation. The difference between W
and Z is that usually W is linear while Z is not, so what you could do is do
your perspective divide for Z too, thus making it linear. This counters the
above mentioned clustering of Z values, making it less prone to the
inaccuracies...
I hope this helps.
Regards,