Shadow-soft Shadow mapping algorithm and its derivation process __ algorithm

Source: Internet
Author: User

Shadow mapping has become standard for the current 3D games. The traditional sm+pcf can realize the hard Shadow in the sunlight environment well, but if the soft Shadow produced by dim light is to be realized, either the effect is too blunt (sample number is less) or inefficient (sample number of times). As a result, more and more games are starting to use soft shadow algorithms that take full advantage of hardware features.
Here mainly summarizes various soft Shadow mapping algorithm thought and the derivation process, does not mention the realization detailed and the concrete code, and so on has the time to write the demo.
This article for original content, reprint please indicate the source.

Standard Shadow Maps
Shadow map of the basic idea: Light view painting once depth, and then camera view shading scene, the pixel coordinate transformation to Light space, compare depth (pixel more depth than Shadow The depth of the map is in the shaded area. You can also directly be screen spaces to depth map do post-processing.

The traditional method can be used percentage Closer filtering to solve the sawtooth problem, also very simple, pixel coordinates corresponding to the past, compare the surrounding multiple points, calculate the percentage of the shadow area. In addition, you can make the shadow smoother by bilinear filter, similar to PCF, compare adjacent 4 dots, and then interpolate according to Texel offset. It is noteworthy that today's GPU supports the hardware Shadow Map, which can be 2x2pcf+bf directly through the tex2dproj (U, V, Z, p) instructions.

Perspective Shadow Maps & trapezoidal Shadow Maps
These two methods follow the basic idea of Shadow map. In order to solve the problem of shadow map precision, the transformation matrix of depth pass is rigged.

Variance Shadow Maps
VSM's idea is great, it can be said that soft shadow from the VSM began to use the direction of hardware filter. First, it is also the depth pass of light view, but this time writes 2 values, one channel writes to depth, and the other channel writes to Depth2. And then to the out of this [Depth, Depth2] texture do blur. Intuitively speaking, the result of doing Blur is to take the average value of the points around a certain range (expected value), that is, blur after a [E (Depth), E (Depth2)] texture. With this texture, the variance can be computed from the variance formula V (Depth) =e (Depth2)-E (Depth) 2.

Finally, according to the Chebychev ' s inequality (Chebyshev-Chebyshev inequality)
P (x≥t) ≤σ2/(σ2+ (t-μ) 2) The σ2 is Variance V (Depth), μ is expected E (Depth)
The pixel coordinates are transformed to the depth after the light space, that is, the ratio of points greater than the depth t in a certain range around a point (note that Chebyshev inequality is only a range ≤, and here the result of the right side of the inequality is approximately pmax). is actually a differential-level PCF value, so you can get smooth shadows very efficiently.

Unfortunately, the VSM will be defective (Light bleeding) in areas where the depth change is larger (variance is greater). Because according to the Chebyshev inequality, in the case of large variance, (t-μ) must be large enough to make inequality to the right of 0. Then there is the LVSM to solve the problem.

Layered Variance Shadow Maps
In order to solve the light bleeding of VSM, the shadow map of VSM is layered, and the depth interval within each level is controlled to a certain extent, which is to reduce the possible variance value.

The

convolution Shadow Maps
CSM presents a very good idea for graphical algorithms. The derivation process is gorgeous and uses several mathematical concepts: convolution, Fourier series. (Note that there is another csm–cascaded Shadow Maps that works differently)

First, suppose that xR3 is a point of world coordinates, D (x) is the distance from that point to the light source (that is, the depth of light space). pR2 corresponds to the coordinates on the shadow map for that point, and Z (p) is the depth on the shadow map corresponding to that point. You can then define a shadow test function:
S (x) = f (d (x), Z (p)) when D>z, S is 0 and vice versa 1
In order to get a soft shadow, we want to be able to convolution the s, that is to expect:
SF (x) =∑w (Q) F (d (x), Z (p-q)) = [W*f (d (x), z)] (p ) (Highlight 1)
If we can apply the convolution theorem to the upper formula and get the result of the following formula, we can get the soft shadow by doing the convolution of Z (p). (That is, you can use blur, hardware bilinear filter and mipmap to achieve soft shadows)
[W*f (d (x), z)] (p) = f (d (x), [W*z] (p))
Unfortunately, F (d (x), Z (p)) is not a linear function (but a step function) and cannot be applied to convolution theorems. To this end, CSM instead uses the numerical analysis method to approximate the function f with Fourier series. (Highlights 2)

Although the process of CSM's derivation is quite gorgeous, its disadvantages are too much (for example: large memory cost, Shadow Map pass needs to output too much data, bandwidth memory is too tight), resulting in low practical value.

Exponential Shadow Maps
Having understood the principle of CSM, the ESM is quite simple.

(To be continued)

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.