What is deep, deep cache, and deep testing in OpenGL?

Source: Internet
Author: User
What is deep, deep cache, and deep testing in OpenGL?

10:50:32| Category:Default category| Tag:OpenGL |Font SizeLargeMediumSmall  Subscription

1) intuitive understanding

The depth is the distance between the pixel point and the camera in the 3D world. The depth cache stores the depth values of each pixel point (drawn on the screen! The depth test determines whether to draw a distant pixel point (or a closer pixel point). Usually, the closer one is selected, and the farther one gives priority to the effect of pivoting !!!

2) z value (depth value) and Z buffer (depth cache)

The following describes the zcoordinate. The zcoordinate is the same as the X and Y coordinates. After transformation, reduction, and perspective division, the Z range is-1.0 ~ 1.0. The depthrange range ing specifies the transformation of the zcoordinate, which is similar to the transformation of the view that maps X and Y to the window coordinate. However, the depthrange range ing is different from the window coordinate ing, because the hardware solution of deep cache applies to applications Program It is hidden. The parameter that calls depthrange is [0.0, 1.0]. The Z value (depth value) associated with a piece indicates the distance to the eye. By default, parts closest to the eye (on the near cross section) are mapped to 0.0, and the parts farthest from the eye (on the far cross section) are mapped to 1.0. Fragments can be mapped to a subset of the deep cache range (by specifying a smaller value in the depthrange ). The ing can also be the opposite. In this case, the farthest part from the eyes is 0.0, and the closest part is 1.0 (call depthrange (1.0, 0.0). Although this is the case, reverse ing is acceptable, but it does not play a major role in practical applications.
To understand why rendering quality is inconsistent, the most important thing is to understand the zcoordinate feature of the screen. The Z value specifies the distance from the clip to the eye. In orthogonal projection, the relationship between distance and Z value is linear, but not in Perspective Projection. In Perspective Projection, this relationship is non-linear and the degree of non-linearity is proportional to the far/near (or zfar/znear in the gluperspective function) in the frustum function. This kind of non-linearity increases the accuracy of the Z value when approaching the near-cross section, and increases the efficiency of the Depth cache. However, the accuracy is reduced in other parts of the visible body, this reduces the precision of the deep cache. Based on experience, the ratio of far to near is greater than 1000. Therefore, the ratio of far to near should be less than 1000. To solve this problem, the simplest way is to reduce the FAR/near ratio by moving the cross section away from the eyes. The only side effect is that objects close to the eyes may be dropped, however, this is rarely a problem in specific applications. The position of the near-Cross Section has no effect on the projection of X and Y coordinates, so this has little impact on the image.
Some other aspects of OpenGL raster and deep cache are worth mentioning. One major problem is that the grating process is inaccurate. Algorithm Therefore, it is difficult to process the common elements unless they share the same plane equation. This problem is more serious in the implementation of limited precision deep cache. These problems include decaling, line hiding, contour polygon, and shadow. However, many methods have been proposed to solve these problems, such as polygonoffset technology.
The number of bits in depth cache is a parameter used to measure the depth cache accuracy. The higher the number of digits in the deep cache, the higher the accuracy. Currently, the video card generally supports 16-bit Z buffer. Some advanced video cards can support 32-bit Z buffer, however, it is enough to use a 24-bit Z buffer.

3) Deep Test

In OpenGL, deep testing uses the deep cache algorithm to eliminate the possibility of non-conformity in scenarios. By default, the depth value range in the deep cache is between 0.0 and 1.0. The range value can be calculated using the function:
Gldepthrange (nearnormdepth, farnormaldepth );
Change the range of the Depth value to nearnormdepth to farnormaldepth. Here, nearnormdepth and farnormaldepth can take any value from the range of 0.0 to 1.0, or even allow nearnormdepth> farnormaldepth. In this way, the gldepthrange function can be used to perform a deep test in any area of the Perspective Projection finite observation space.
Another very useful function is:
Glcleardepth (maxdepth );
The maxdepth parameter can be any value in the range of 0.0 to 1.0. Glcleardepth uses maxdepth to initialize the deep cache. By default, the deep cache uses 1.0 for initialization. The glcleardepth function can be used to accelerate the deep test process because no polygon larger than the initial value of the Depth cache will be drawn during the deep test. Note that after the initialization value of the deep cache is specified, you should call:
Glclear (gl_depth_buffer_bit );
Complete the initialization of the deep cache.
In the depth test, by default, the Z value of the new pixel to be drawn is compared with the Z value at the corresponding position in the depth buffer. If the value is smaller than the value in the depth cache, then, use the color value of the new pixel to update the color value of the corresponding pixel in the frame cache. This comparative test method can be implemented through functions:
Gldepthfunc (func );
. The func values can be gl_never (not processed), gl_always (processing all), gl_less (less than), gl_lequal (less than or equal to), gl_equal (equal to), and gl_gequal (greater than or equal), gl_greater (greater than) or gl_notequal (not equal to). The default value is gl_less. These tests can reduce the computing of deep cache processing in various applications.

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.