Shadow Map series (PCF, CSM, VSM, lvsm)

Source: Internet
Author: User

I have recently read a thesis on shadow map and summarized it as follows:

 

Shadow Map: used to generate shadows.

If you want to know about shadow map, the best way is to look at the DX demo. The algorithm is as follows:

Use the render to target method to render the texture, and use the light source in the scenario as the coordinate origin to establish the light source coordinate system, so as to obtain the scene depth information relative to the light source, save it on the render target (generally r32f's surface). The reason why r32f is selected is to consider the accuracy of the scenario. Here r32f is what we call shadow map, which stores the scene depth information relative to the light source.

Next, use the default render target of the system to enable the depth buffer and convert the objects in the scenario (represented by world coordinates) to the projection coordinates based on the light source. This change is as follows: world coordinates> Object coordinates> light source visual coordinates> light source projection coordinates. Then compare the depth. In the pixel shader, the depth is smaller than the relative point depth in the shadow map, that is, the place where the light source shines (the value is 1 ), otherwise, it is in the shadow area (the value is 0 ). Note that when we compare the depth value here, we need to convert the coordinates to the window coordinates. After all, the shadow map is generated as the render target. In this way, the color is output at the place where the value is 1, and the color is black at the place where the value is 0, which is the shadow.

Advantages and disadvantages:

Advantage: you do not need to calculate the shape of geometric objects in the scenario like Volume Shadow. For complex scenarios, you only need to generate a map.

Disadvantage: the shadow has a sawtooth value. The reason is that when the shadow depth is greater, only the outputs of 0 and 1 are displayed. In this way, the values of 1 and 0 alternate at the shadow edge to generate a sawtooth value. This has also become a hot topic in the graphic field.

 

PCF (percentage closer filter): Process shadow serfations generated by shadow map.

It means to put the values 0 and 1 produced by the depth comparison in a render target, and then filter them, so that 0.2, 0 will appear in the shadow edge area. 5 .... and then generate soft shadow. However, this filtering method consumes time, especially when the number of samples is large. It is simplified to Horizontal Filtering and vertical filtering to reduce the number of samples.

 

CSM (Convolution shadow map): convolution shadow map. This method uses shadow-based reconstruction. Because the depth test is either 0 or 1, an X coordinate [-] can be constructed. the Y coordinate is a function of [0, 1]. This function performs FFT transformation and uses the reference function (SIN and COS) to re-construct the shadow map. This method occupies a large amount of memory and requires multiple render targets.

 

VSM (variance shadow map): variance shadow map. This method uses the chersprue inequality to calculate the gray scale value through the expectation and variance of the depth values of each pixel in the shadow map. This is an estimation method. Note that the depth value here is expected to be the depth value obtained after filtering the shadow map (horizontal and vertical. Here, the shadow map contains two channels, one storing the depth value and the other storing the square of the Depth value. After filtering, both the expectation of the Depth value and the expectation of the square of the Depth value can be obtained. In this way, the variance is easy to be obtained, and then the value of each pixel is obtained using the chercher's inequality. The depth value is smaller than expected, that is, the place where the light source shines. The depth value is greater than expected, that is, the shadow area.

Advantage: you do not need to have multiple render targets. At the same time, the effect is good.

Disadvantage: "Light bleeding" appears when multiple shadows are duplicated ". This artifact is also caused by the cherhov inequality. So we will have layers variance shadow map to solve "Light bleeding" in the future"

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.