From: Vladimir D. <vo...@mi...> - 2004-12-31 17:32:39
|
Hi Felix - nice method :) It would be nice to have this configurable on a per-application basis. I imagine applications with a lot of detail in near scenes (autocad like perhaps ?) would work better with the old way of doing things. On the other hand, flight simulators are probably a prime candidates for=20 your way of doing things. best Vladimir Dergachev On Fri, 31 Dec 2004, Felix [ISO-8859-1] K=FChling wrote: > 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 16-bit float depth > values used by the Savage4: it uses a 12 bit mantissa and a 4 bit > unsigned exponent. A z-exponent 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^(e-15) > > 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. > > A happy new year to everybody! > > Bye, > Felix > > --=20 > | Felix K=FChling <fx...@gm...> http://fxk.de.vu | > | PGP Fingerprint: 6A3C 9566 5B30 DDED 73C3 B152 151C 5CC1 D888 E595 | > > > > ------------------------------------------------------- > The SF.Net email is sponsored by: Beat the post-holiday blues > Get a FREE limited edition SourceForge.net t-shirt from ThinkGeek. > It's fun and FREE -- well, almost....http://www.thinkgeek.com/sfshirt > -- > _______________________________________________ > Dri-devel mailing list > Dri...@li... > https://lists.sourceforge.net/lists/listinfo/dri-devel > |