From: Felix <fxkuehl@gm...>  20041231 14:40:46

Hi, I want to share an idea that I had, which drastically improves the depth buffer quality on Savage4 hardware. Maybe the same can be applied to different hardware too. Short version: reverse the depth range (z' =3D 1  z) such that far coordinates map to z'=3D0 and near coordinates to z'=3D1. Then use a floating point format to store depth values in the depth buffer. Of course the hardware needs to support a floating point depth buffer. By reversing the depth range a floating point format compensates for the usual loss of accuracy of depth values of far objects due to the perspective transformation. Reversing the depth range is done in the Driver.Viewport callback that computes the viewport transformation matrix. The depth compare functions have to be swapped (Less <> Greater, LessEqual <> GreaterEqual) and the computation of the clear depth must be adjusted. See [0] for other adjustments that I havn't implemented yet. I have implemented this in the Savage driver and the result is really impressive. I had to reverse engineer the format of 16bit float depth values used by the Savage4: it uses a 12 bit mantissa and a 4 bit unsigned exponent. A zexponent offset can be programmed in order adjust it to the depth range of vertices (16 seems to be the right value for depth values in range [0,1]). Format: eeee[0.]mmmmmmmmmmmm , Value: x =3D m * 2^(e15) As a result, near objects are represented with only 12 bits (mantissa) instead of 16 bits, but this seems to be no problem. However, far objects are now represented 2^15 times more accurately than near objects and still 2^11 times more accurately than with a 16 bit fixed point format. (even up to 2^3 times more accurately that with a 24 bit fixed point depth buffer!) An interesting observation: reversing the depth range without using a floating point depth buffer already lead to a slight improvement of depth buffer quality. I guess this is due to how depth interpolation works internally on the Savage4. [0] There are still three problems I need to sort out: the float format used with a 24 bit depth buffer, polygon offsets (have to depend on the depth value) and correct handling of float depth values in software fallbacks.=20 A happy new year to everybody! Bye, Felix =20  Felix K=FChling <fxkuehl@...> http://fxk.de.vu   PGP Fingerprint: 6A3C 9566 5B30 DDED 73C3 B152 151C 5CC1 D888 E595  