Z-buffer and W-Buffer

Source: Internet
Author: User

There are two types of depth-buffer (deep cache): Z-buffer and W-buffer. Here we discuss the differences between these two types of deep cache and how to convert them.

Meaning of W

The coordinates of 3D spatial points are (x, y, z). In order to make the matrix multiplication function of translation transformation, we use the points (X, Y, Z, W) in 4D space) to represent vertices (x', y', Z') in a 3D space. The relationship between these two points is:

 
X' = x/W y' = y/W Z' = z/W

In this way, a four-dimensional spatial point is used to represent a three-dimensional spatial point, or a n + 1 dimensional spatial point is called a homogeneous coordinate representation ".

In actual use, in the process of model-> world conversion, world-> View conversion, W is always the same, always equal to one, the first three components of homogeneous coordinates correspond to the three coordinate components of 3D spatial points. However, after the projection transformation, W will get a proportional value. For example, the general perspective projection transformation matrix is:

 
| W 0 0 0 | 0 h 0 0 | 0 0 q 1 | 0 0 0-qzn 0 | where ZN = near crop surface Z coordinate ZF = far crop surface Z coordinate W = 2 * Zn/WXH = 2 * Zn/WXH = ZF/(ZF-Zn)

Multiply the point (X, Y, Z, 1) by this matrix, W is no longer one, and the corresponding 3D space coordinate (x/W, Y/W, z/W. At the same time, because the value of W is usually proportional to the Z coordinate (for example, after the transformation of the matrix above, the value of W is actually the value of Z coordinate), after the projection transformation, objects will produce near-large and small effects.

Difference between Z-buffer and W-Buffer

In short, the difference between Z-buffer and W-buffer is that the former stores the Z coordinate of the vertex, while the latter stores the W coordinate of the vertex.

Specifically, because the stored values have different meanings, the actual results may be different.

The Z-buffer stores the Z coordinate after the projection transformation. As mentioned above, after the projection, the object will produce a result of being close to big and small, so it is closer to the eye, the resolution of the Z coordinate is relatively large, while the resolution of the distant coordinate is relatively small. In other words, the projection Z coordinate is in its value range. For physical distance changes away from the eyes, this is not a linear change (I .e. non-even distribution). One advantage of this is that close objects get a high depth resolution, but the depth judgment of distant objects may fail.

The W-buffer stores the W coordinate after the projection transformation, while the W coordinate is usually proportional to the Z coordinate in the world coordinate system, so after the transformation to the projection space, the value is still linear, so that no matter the distance or near the object, there is the same depth resolution, which is its advantage, of course, the disadvantage is that it is not possible to use a high depth resolution to represent near objects.

From the perspective of hardware implementation, almost all hardware 3D acceleration CARDS support Z-buffer, while W-buffer does not support Z-buffer as widely. In addition, early direct3d versions do not seem to support w-buffer.

Z-buffer and W-buffer Conversion

According to the matrix transformation above, you can easily export the formula for converting w-buffer into Z-buffer:

 
Zdepth = Q * (wdepth-Zn)/wdepth = ZF/(ZF-Zn) * (wdepth-Zn)/wdepth

what is the use of this conversion formula? For example, 3DS MAX uses w-buffer. If depth information is exported from 3DS MAX to direct3d and used as the pre-rendering background, the above conversion may be used. Of course, if w-buffer is used in d3d, the problem will not be solved. However, if z-buffer is used without such conversion, the rendering result will fail.

Related Article

E-Commerce Solutions

Leverage the same tools powering the Alibaba Ecosystem

Learn more >

Apsara Conference 2019

The Rise of Data Intelligence, September 25th - 27th, Hangzhou, China

Learn more >

Alibaba Cloud Free Trial

Learn and experience the power of Alibaba Cloud with a free trial worth $300-1200 USD

Learn more >

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.