Research on Deep cache and deep Cache

Source: Internet
Author: User

Research on Deep cache and deep Cache

Research on Deep cache (Z cache)

Recently stuck in the shadow map process. Because I want to run the shadow map on a platform compatible with OpenGL ES 2.0, and to run the shadow map smoothly, the general situation is that there is a GL_OES_depth_texture extension, and some compatible machines do not have this extension, this makes it difficult for our developers. However, there are still some solutions, provided that you have a deep understanding of the Z-Buffer in computer graphics.

Jiang caiyang's original article, first published at: http://blog.csdn.net/gamesdev/article/details/44939923. Welcome to the discussion.

Refer to the introduction to Z-Buffer on Wikipedia (here the first formula is likely to be incorrect, and it feels like 2far-near instead of-2far-near ), when the vertices in the scenario are transformed by MVP, their Z value will also be changed accordingly. Here we are particularly concerned with the changes in the vertex position (Xe, Ye, Ze) in the Perspective space after the transformation of the projection matrix.

First, perform projection transformation on the vertex based on the projection matrix:

Then, convert the homogeneous coordinate to the normal coordinate, that is, divide by-Ze for normalization, so that the fourth component is 1:

Zndc = now.

When the NDC (Normalized Device Coordinates) coordinate system is converted to the screen coordinate system, the Z value is also linearly interpolated. At this time, the Zndc in [-] must first be interpolated to [], and then based on the depth of the digits (usually 16, 24 and 32, there is almost no 8-bit depth.

 

Zw = S · [(Zndc/2) + 0.5]

Where S = 2n-1 and n are the depth digits set by the system.

That is

 

Take Ze as the Zw function, and simplify it, then:

 

We can roughly see that Ze is inversely proportional to Zw (proportional to 1/Zw ). To learn more about the situation, we obtain the derivative of it:

Ling

Then

 

 

After calculation

 

 

We can quickly see that when

 

Obtain the minimum value. This means that the infinite distance of the camera space only affects the Z cache of nearly 0. In other words, the change of the Z cache of a single position reflects the change of the infinite distance of the camera space.


Can this minimum value be obtained? Because the Depth Change of the Z cache on the computer is zwε [0, 2n-1], it must meet

 

Here, the sufficient and necessary conditions for the inequality on the left are near <far, which is positive. The sufficient and necessary conditions for the right inequality are:

 

 

This requires a different sign between near and far, but we usually do not set a different sign between near and far. Therefore, the inequality on the right is not satisfied. Therefore

 

 

Zws in [0, 2n-1] are monotonically increasing, while zws in [0, 2n-1] are monotonically decreasing. Therefore, this shows that the Z cache gives more precision (binary digits) to objects that are closer to the camera (or zNear) and objects in the distance (or zFar closer, the reserved Z cache has little precision. Therefore, the distance and precision between the Z cache and zNear and zFar are not linear. This requires us to place more objects in the near plane. For objects in the distance, we can ignore them by using the level of detail (dump) to avoid the occurrence of z-fighting. At the same time, due to this feature, shadow map may also display different resolutions in different distances. This requires us to use technologies like Cascade Shadow Map (CSM) to solve the problem.

 

References:

OpenGL FAQ: https://www.opengl.org/archives/resources/faq/technical/depthbuffer.htm

Exploring perspective matrix: http://blog.csdn.net/popy007/article/details/1797121

Z-Buffering on Wikipedia: http://en.wikipedia.org/wiki/Z-buffering#Mathematics

 

Question:

In the OpenGL FAQ

D (ze/we)/d zw =-f * (f-n) * (1/s)/n

=-F * (f/N-1)/s

It may be wrong. We should add a pair of parentheses. Become

=-F * (f/(n-1)/s

Related Article

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.