Recently doing GPU-Driven Rendering Pipleline Related technologies , Throughout pipeline Middle tailoring is a very important part of it , be based on GPU Occlusion clipping is also one of many clipping algorithms , It takes full advantage of compute shader The power of parallel computing , While speeding up occlusion queries , Can reduce query latency . The implementation is based on GPU When clipping , We're going to use something called Hierarchical Z-buffer Technology , It's the key to the whole occlusion query . So what is Hierarchical Z-buffer Well ？ What are its advantages ？ Let's explain briefly today HiZ-buffer The basic principle of , In actual use , Although different games use different optimization methods , But the core principle is the same .
Let's assume the scenario shown below , This is a cross-sectional view , The camera is from Z0 Look at Z1. Let's take a look at this example , How to use Hierarchical Z-Buffer To judge a green object as blocked , And cut it off .
Above picture z = 0 It's near the cutting surface ,z = 1 It's the far cutting surface . First of all, we'll cover （ Red and blue ） To rasterize , Get one z-buffer, The gray line in the following figure represents the depth value after rasterization .
The next step is the most important step , Down sampling z-buffer, Get a bunch of mipmap Hierarchical mapping （ The mipmap A hierarchical chart is called Hierarchical Z-buffer, perhaps abbreviated HiZ-buffer）
In the process of subsampling , We use max operation , In other words, when two adjacent pixels are subsampled into one pixel , Use the value of the largest of the two as the value of the next level . As shown in the figure below ：
As can be seen from the figure above , Every next sampling , It's a conservative estimate of the upper level , In the first 4 There's only one depth left . Because we used max operation , So if an object is in level 2 The medium depth value is judged as occluded , So it must be level 1 It's also covered .
obtain HiZ-buffer after , So we can do occlusion Clipping Based on it ：
Calculate the green object AABB Bounding box , It's about the bounding box x-max/min and y-max/min Used to determine which level of sampling HiZ-buffer（ That is to see which level of size can cover all the pixels of the bounding box ）, In this case AABB The bounding box conforms to level 2, So we chose to sample level2, To get a z-buffer The conservative estimate of . Next we compare aabb.zmin With the depth we sampled , hear aabb.zmin < z-buffer.sample, So the green object is blocked , It should be cut out .
The above method is based on Hierarchical Z-buffer The occlusion clipping of . It can be seen that if there is no HiZ-buffer, We will have to take four samples to determine if an object is blocked ,HiZ-buffer Greatly reduces the number of texture sampling , It improves the efficiency of occlusion query .
We mentioned at the beginning of the article that based on GPU Rendering pipeline of , Now this technology is also a popular concept , I also use it in the actual work of terrain rendering , If there's time later , Will write a series of articles to talk about GPU-Driven Rendering Pipeline.