Shadow Cone (Shadow Volume)

Source: Internet
Author: User

Transferred from: http://blog.csdn.net/zjull/article/details/11819923

Shadow map and Shadow volume are the most popular real-time shadow rendering methods, compared with Shadow map, the biggest advantage of Shadow volume is that there is no shadow aliasing problem, but because it is a geometry-based approach, each frame is likely to construct and render a shadow cone, And some work must be done by the CPU, making it inefficient Shadow map high, because its calculations are done on the GPU side, but for indoor scenes or objects not much outdoor scene, Shadow volume still have a useful, shadow cone implementation of a variety of algorithms, And can do more than a variety of optimizations, here to learn about Z-pass and Z-fail algorithms, they are multipass, and temporarily did not consider optimization problems.

Z-pass algorithm

PASS1: Open depth test, render the entire scene as normal, and get depth map.

PASS2: Open stencil test, turn off Z writing and color buffer writing, render shadow volumes, set stencil test always pass, for front faces, if z test p In the case of stencil value +1, if z test fail, stencil value is not updated; For back faces, if z test pass, then stencil value-1.

When the Pass3:pass2 is complete, the pixel in stencil buffer with value not 0 is in the shaded area, and the shadow effect is drawn accordingly.

Figure 1:z-pass Algorithm

The z-pass algorithm gets the wrong stencil values when the viewpoint is in the shadow cone or intersects the near clipping face, as shown in:

Figure 2:z-pass The failure condition of the algorithm

Z-fail algorithm

The Z-fail algorithm is the independent invention of John Carmack,bill Bilodeau and Mike Songy, whose aim is to solve the problem of shadow algorithm failure after the viewpoint enters volume z-pass;

Pass1: As with the z-pass algorithm

PASS2: Open stencil test, turn off Z writing and color buffer writing, render shadow volumes, set stencil test always pass, for front faces, if z test F AIL, stencil value-1, if z test pass, does not update stencil value; For back faces, if z test fail, stencil value +1.

PASS3: Just like Z-pass.

As shown in 3, the Z-fail algorithm can correctly get stencil values regardless of whether the point of view is outside the shadow cone, or the near clipping surface intersects with the shadow cone.

Figure 3:z-fail Algorithm

Z-fail requires shadow volume must be closed, Figure 4 left will get the wrong stencil values, plus shadow cone caps (Figure 4 right) can be corrected.

Figure 4:z-fail The failure scenarios of the algorithm and remedial measures

Shadow cone Implementation (Z-pass)

Comparison of Shadow map and Shadow volume

Advantages of Shadow Map:

Simple to implement, no geometry calculations are required, and shadow map can be generated entirely by the GPU.

No template caching is required, only one shadow map is saved for each light source, and there is no cache high fill rate issue.

Disadvantages of Shadow Map:

Jagged edges are easily formed at the edge of the shadow, reducing the quality of the shadows, especially when the light source is far from the shadow projection body.

For each light source, the scene needs to be rendered once to get the shadow map, and more work is needed for the point light.

Advantages of Shadow Volume:

High-quality shadow effect, no shadow edge aliasing problem;

It can easily deal with various light sources such as poly illumination, directional light, etc.

Disadvantages of Shadow Volume:

When the geometrical information of the light source or projection object changes, the shadow cone needs to be recalculated, occupying more CPU time;

There is a requirement for the geometry's topology, i.e. the geometry must be closed;

Template caching is required, there is a high fill rate problem in the case of non-optimization, and the common optimization methods are: Finite shadow cone (finite Volumes), xy clipping (xy Clipping), Z-Limit (z-bounds);

Cannot handle shadow casts with transparent material objects, such as bulletin boards, particle systems, leaves, grass, etc.;

All objects in the scene are required to receive projected shadows, even if they are not received.

Reference links

Http://http.developer.nvidia.com/GPUGems/gpugems_ch09.html

Http://blog.donews.com/yyh/archive/2005/05/19/387143.aspx

    • Previous article "Leetcode" Same tree
    • Next OpenGL rendering pipeline
Top
2
Step

(Turn) Shadow Cone (Shadow Volume)

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.