W-buffering?

Started by
14 comments, last by GameDev.net 18 years, 2 months ago
I had heard somewhere that w-buffering was better than z-buffering. Is this true and if it is, what are the benefits?
Advertisement
W-buffering has a more linear distribution of depth values than z-buffering. It is supposed to produce less depth artifacts (z-fighting etc.) than the z-buffer and allow a larger range between the near and far planes. As I understand it hardware support for w-buffering is rare (it may be somewhat deprecaed). Note also that it may require a special projection matrix.

The math discussed briefly at the bottom of this page.
W-buffering was an acceptable alternative in the days of 16bit z-buffers, so to reduce medium distance z fighting artifacts. Today, with 24/32bit zbuffers, w-buffering will usually yield worse results than a plain old z-buffer. Especially near geometry will be badly affected.

A well defined near plane on a 24bit z-buffer will give you enough precision for even the most complex scenes. If you have extremely large distance viewing ranges, use a layered rendering approach.
How do you do layered rendering?
Quote:Original post by cppcdr
How do you do layered rendering?

Well, you first render your very far away geometry. Then you clear the depth buffer. Finally, you render your medium to near geometry. You can add additional layers as needed.

Note that this is only required, if you have huge viewing distances, as in eg. a space sim game. For indoor, or common planetary scale outdoor scenes (eg. large terrains), a single 24bit zbuffer is usually fine.
And how does repetively clearing your z-buffer help precision and z-fighting?
Quote:Original post by Anonymous Poster
And how does repetively clearing your z-buffer help precision and z-fighting?

By clearing the depth-buffer each "layer" can use the full depth buffer precision.
More specifically, if you render the SUPER-FAR range (say, 2000-200,000 world units) in the first pass, then 2000 becomes the Z-Buffer's 0.0, and 20,000 becomes the buffer's 1.0. Then you render the nearer stuff (1-2000), and now 1 is 0.0 in the zbuffer, and 2000 becomes 1.0.

Because it's the ratio between the two values (near and far plane distances) that determines the way the Z values are distributed, it is this ratio that contributes to z-fighting (though the scales of the objects plays a part as well). Rendering the 2000-200,000 range of Z-Values in one pass would give the same amount of z-fighting as rendering the 1-100 range (that is to say, not much at all - note that you can get very good results with even a 1-2000 range, so a 1:100 ratio is very good). rendering a full 1-200,000, however, would produce a ton of z-fighting, because of the large discrepancy between the near and far planes.

Obviously, if you have things that are very,very close together relative to the scales of the near/far plane, you're likely to see Z-Fighting regardless of the ratio, since that's basically what it is. But you should generally see fighting like that at any distance within the Z-buffer, not just farther away.

Sorry if this post is a bit rambling (and I'm only about 90% convinced of its factual accuracy), but I'm kinda tired. Hope it helps...apologies if it's just more confusing.
How do you resolve correct z values between the layers? It will almost never work out that an entire object will be on one side of the layer. For most cases objects and triangles will strattle that line.

It doesn't seem clear to me how this solution can be possible.
Perhaps you can do a sort for the object to see if it is considered as a far-layer object or near-layer object.

The Z-ranges for the layers don't need to be always the same for every frame.
So with the far-range objects you can do some bound box math to get approximate near plane distance to avoid object clipping. And the same calculation is needed for the farplane of the near-layer.

Yes, there is a problem if some objects are spatially related with the objects of the other layer. With terrain for example the problem is quite minimal since the terrain is usually made of chunks, which don't intersect any other chunks.

This topic is closed to new replies.

Advertisement