Research of deep cache (Z-cache)

Source: Internet
Author: User

Research of deep cache (Z-cache)

Recently stuck in the shadow map process. Because I want to run the shadow map on the OpenGL ES 2.0 compatible platform, and to run shadow map smoothly, the usual situation is to have gl_oes_depth_texture extension, and some compatible machines are not this extension, This has brought some difficulty to our developers. However, there is still some way, the premise is to the computer graphics Z-buffer to have a deep understanding of the line.

Saiyang original article, starting address: http://blog.csdn.net/gamesdev/article/details/44939923. Welcome to come to discuss the peer.

Refer to Wikipedia's introduction to Z-buffer (the first formula is probably wrong, the feeling is 2far near instead of -2far near), and when the vertex in the scene does the MVP transformation, its Z-value will be changed accordingly. What we are particularly concerned about here is the vertex position (Xe, Ye, Ze) in the perspective space, and what happens when the projection matrix is transformed.

The first is the projection transformation of the vertex according to the projection matrix:

The homogeneous coordinates are then converted to normal coordinates, that is, divided by Ze, with the fourth component being 1:

It's zndc= at this time.

The z-values are also linearly interpolated during the normalized Device coordinates coordinate system to the screen coordinate system. At this point the zndc∈[-1,1], the first need to interpolate to [0,1], and then according to the depth of the number of bits (generally 16, 24 and 32 bits, almost no 8-bit depth), to average mapping past.

Then there are: Zw=s [(ZNDC/2) +0.5]

Where S=2n-1,n is the number of depth bits set by the system.

That

The function of ze as ZW, and simplification, is:

We can generally see that ze and ZW are inversely proportional (and 1/ZW). To learn more about the situation, we have a derivative of it:

Make

The

After calculation, we get

We can quickly see that when

When

Gets the maximum value. This means that the distance from the infinite camera space affects only the z-cache, which is nearly 0, in other words, a bit's Z-cache change will reflect an infinitely long camera space distance change.

So can this maximum point be taken? Because the depth of the computer's Z-cache is zw∈[0,2n-1], it must be satisfied

The sufficient and necessary condition for the left inequality to satisfy is near<far, which is certain. The sufficient and necessary condition for the right inequality to be satisfied is

This requires near and far, but we usually do not set the near and far XOR numbers. So the inequality on the right is not satisfied. So

On zw∈[0,2n-1] is monotonically increasing, while ze is monotonically decreasing on zw∈[0,2n-1]. So this reflects that the Z-cache will give more precision (binary digits) to objects closer to the camera (or znear), while distant (or near-Zfar) objects are left with little Z-cache accuracy. So the relationship between Z-cache and znear to Zfar is not linear. This requires us to put more objects near the plane, distant objects, can use LOD techniques to ignore the display, to avoid the occurrence of z-fighting. At the same time, due to such characteristics, the shadow map will also show inconsistent resolution at different distances. This requires that we use technology such as Cascade Shadow Map (CSM) to solve the problem.

Reference documents:

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

Explore the perspective matrix in depth: http://blog.csdn.net/popy007/article/details/1797121

Z-buffering on Wikipedia:http://en.wikipedia.org/wiki/z-buffering#mathematics

Questions:

OpenGL FAQ Inside the

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

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

May be wrong, you should add a pair of parentheses. Become

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

Research of deep cache (Z-cache)

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.