Treating the shadow map as defining a volume of space, separating light from dark,can also help in determining what parts of objects to shadow. Gollent [555] describes how CD Projekt’s terrain shadowing system computes for each area a maximum height that is still occluded, which can then be used to shadow not only terrain but also trees and other elements in the scene. To find each height, a shadow map of the visible area is rendered for the sun. Each terrain heightfield location is then checked for visibility from the sun. If in shadow, the height where the sun is first visible is estimated by increasing the world height by a fixed step size until the sun comes into view and then performing a binary search. In other words, we march along a vertical line and iterate to narrow down the location where it intersects the shadow map’s surface that separates light from dark. Neighboring heights are interpolated to find this occlusion height at any location. An example of this technique used for soft shadowing of a terrain heightfield can be seen in Figure 7.32. We will see more use of ray marching through areas of light and dark in Chapter 14.
将阴影贴图视为定义一个空间体积,将亮暗分开,也有助于确定对象的哪些部分需要阴影。Gollent [555]描述了CD Projekt的地形阴影系统如何为每个仍被遮挡的区域计算最大高度,该高度不仅可用于阴影地形,还可用于阴影场景中的树木和其他元素。为了找到每个高度,为太阳渲染可见区域的阴影图。然后检查每个地形高度场位置在太阳下的可见度。如果在阴影中,太阳第一次可见的高度是通过将世界高度增加一个固定的步长来估计的,直到太阳进入视野,然后执行二分搜索法。换句话说,我们沿着一条垂直线前进,并迭代缩小它与阴影贴图表面相交的位置,阴影贴图表面将光与暗分开。对相邻高度进行插值,以找到任何位置的遮挡高度。这种技术用于地形高度场的软阴影的例子可以在图7.32中看到。在第14章中,我们将会看到更多光线穿过明暗区域的应用。

Figure 7.32. Terrain lit with the height where the sun is first seen computed for each heightfield location. Note how trees along the shadow’s edge are properly shadowed [555]. (CD PROJEKT R ,The Witcher R are registered trademarks of CD PROJEKT Capital Group. The Witcher game c CD PROJEKT S.A. Developed by CD PROJEKT S.A. All rights reserved. The Witcher game is based on the prose of Andrzej Sapkowski. All other copyrights and trademarks are the property of their respective owners.)
图7.32。为每个高度场位置计算出的第一次看到太阳的高度照亮的地形。注意沿着阴影边缘的树是如何被正确地阴影化的。(CD PROJEKT R、The Witcher R是CD PROJEKT Capital Group的注册商标。由CD PROJEKT S.A .开发的巫师游戏c CD PROJEKT S.A .版权所有。巫师游戏是基于安德烈·萨普克维斯基的散文。所有其他版权和商标是其各自所有者的财产。)
One last method worth a mention is rendering screen-space shadows. Shadow maps often fail to produce accurate occlusions on small features, because of their limited resolution. This is especially problematic when rendering human faces, because we are particularly prone to noticing any visual artifacts on them. For example, rendering glowing nostrils (when not intended) looks jarring. While using higher-resolution shadow maps or a separate shadow map targeting only the area of interest can help,another possibility is to leverage the already-existing data. In most modern rendering engines the depth buffer from the camera perspective, coming from an earlier prepass,is available during rendering. The data stored in it can be treated as a heightfield.By iteratively sampling this depth buffer, we can perform a ray-marching process(Section 6.8.1) and check if the direction toward the light is unoccluded. While costly,as it involves repeatedly sampling the depth buffer, doing so can provide high-quality results for closeups in cut scenes, where spending extra milliseconds is often justified.The method was proposed by Sousa at al. [1678] and is commonly used in many game engines today [384, 1802].
最后一个值得一提的方法是渲染屏幕空间阴影。由于分辨率有限,阴影贴图通常无法对小特征产生准确的遮挡。这在渲染人脸时尤其成问题,因为我们特别容易注意到人脸上的任何视觉伪像。例如,渲染发光的鼻孔(如果不是故意的)看起来很不协调。虽然使用更高分辨率的阴影贴图或仅针对感兴趣区域的单独阴影贴图会有所帮助,但另一种可能性是利用已经存在的数据。在大多数现代渲染引擎中,来自早期prepass的相机视角的深度缓冲区在渲染期间是可用的。存储在其中的数据可以被视为一个高度场。通过反复采样这个深度缓冲区,我们可以执行光线行进过程(6.8.1节),并检查朝向光的方向是否未被遮挡。虽然成本很高,因为它涉及重复采样深度缓冲区,但这样做可以为过场动画的特写提供高质量的结果,在这种情况下,花费额外的毫秒数通常是合理的。这种方法是索萨等人提出的。[1678]并且在今天的许多游戏引擎中普遍使用[384,1802]。
To summarize this whole chapter, shadow mapping in some form is by far the most common algorithm used for shadows cast onto arbitrary surface shapes. Cascaded shadow maps improve sampling quality when shadows are cast in a large area,such as an outdoor scene. Finding a good maximum distance for the near plane via SDSM can further improve precision. Percentage-closer filtering (PCF) gives some softness to the shadows, percentage-closer soft shadows (PCSS) and its variants give contact hardening, and the irregular z-buffer can provide precise hard shadows. Filtered shadow maps provide rapid soft-shadow computation and work particularly well when the occluder is far from the receiver, as with terrain. Finally, screen-space techniques can be used for additional precision, though at a noticeable cost.
总结这一章,某种形式的阴影贴图是目前最常用的算法,用于投射到任意表面形状的阴影。当阴影投射在较大区域(如室外场景)时,级联阴影贴图可以提高采样质量。通过SDSM找到近平面的最佳最大距离可以进一步提高精度。百分比接近过滤(PCF)为阴影提供一些柔和度,百分比接近软阴影(PCSS)及其变体提供接触硬化,不规则z缓冲区可以提供精确的硬阴影。过滤阴影贴图提供了快速的软阴影计算,并且在遮挡器远离接收器(如地形)时特别有效。最后,屏幕空间技术可以用来提高精度,尽管代价很大。
In this chapter, we have focused on key concepts and techniques currently used in applications. Each has its own strengths, and choices depend on world size, composition(static content versus animated), material types (opaque, transparent, hair,or smoke), and number and type of lights (static or dynamic; local or distant; point,spot, or area), as well as factors such as how well the underlying textures can hide any artifacts. GPU capabilities evolve and improve, so we expect to continue seeing new algorithms that map well to the hardware appear in the years ahead. For example,the sparse-texture technique described in Section 19.10.1 has been applied to shadowmap storage to improve resolution [241, 625, 1253]. In an inventive approach, Sintorn,K¨ampe, and others [850, 1647] explore the idea of converting a two-dimensional shadow map for a light into a three-dimensional set of voxels (small boxes; see Section 13.10).An advantage of using a voxel is that it can be categorized as lit or in shadow, thus needing minimal storage. A highly compressed sparse voxel octree representation stores shadows for a huge number of lights and static occluders. Scandolo et al. [1546] combine their compression technique with an interval-based scheme using dual shadow maps, giving still higher compression rates. Kasyan [865] uses voxel cone tracing (Section 13.10) to generate soft shadows from area lights. See Figure 7.33 for an example.More cone-traced shadows are shown in Figure 13.33 on page 585.
在这一章中,我们将重点放在应用程序中目前使用的关键概念和技术上。每种都有自己的优势,选择取决于世界的大小、组成(静态内容与动画)、材质类型(不透明、透明、头发或烟雾)以及灯光的数量和类型(静态或动态;本地或远方;点、点或区域),以及诸如底层纹理能够多好地隐藏任何伪像之类的因素。GPU功能不断发展和改进,因此我们预计未来几年将继续看到与硬件完美匹配的新算法出现。例如,第19.10.1节中描述的稀疏纹理技术已经应用于阴影贴图存储以提高分辨率[241,625,1253]。在一种创造性的方法中,Sintorn、K ampe和其他人[850,1647]探索了将光的二维阴影图转换成三维体素集(小方框;参见第13.10节)。使用体素的一个优点是它可以被分类为亮的或暗的,因此需要最小的存储。高度压缩的稀疏体素八叉树表示存储了大量灯光和静态遮光器的阴影。Scandolo等人[1546]将他们的压缩技术与使用双重阴影图的基于间隔的方案相结合,给出了更高的压缩率。卡西扬[865]使用体素锥跟踪(第13.10节)从区域光生成软阴影。例子见图7.33。更多的锥形阴影如图13.33所示。

Figure 7.33. At the top is an image generated with a basic soft-shadows approximation. At the bottom is voxel-based area light shadowing using cone tracing, on a voxelization of the scene.Note the considerably more diffuse shadows for the cars. Lighting also differs due to a change in the time of day. (Images courtesy of Crytek [865].)
图7.33。在顶部是一个基本的软阴影近似生成的图像。底部是基于体素的区域光阴影,在场景的体素化上使用圆锥体追踪。注意汽车的漫射阴影要多得多。照明也因一天中时间的变化而不同。(图片由Crytek [865]提供。)
Further Reading and Resources
进一步阅读和资源
Our focus in this chapter is on basic principles and what qualities a shadow algorithm needs—predictable quality and performance—to be useful for interactive rendering.We have avoiding an exhaustive categorization of the research done in this area of rendering, as two texts tackle the subject. The book Real-Time Shadows by Eisemann et al. [412] focuses directly on interactive rendering techniques, discussing a wide range of algorithms along with their strengths and costs. A SIGGRAPH 2012 course provides an excerpt of this book, while also adding references to newer work [413].Presentations from their SIGGRAPH 2013 course are available at their website, www.realtimeshadows.com. Woo and Poulin’s book Shadow Algorithms Data Miner [1902] provides an overview of a wide range of shadow algorithms for interactive and batch rendering. Both books supply references to hundreds of research articles in the field.Tuft’s pair of articles [1791, 1792] are an excellent overview of commonly used shadow-mapping techniques and the issues involved. Bjørge [154] presents a range of popular shadow algorithms suitable for mobile devices, along with images comparing various algorithms. Lilley’s presentation [1046] gives a solid and extensive overview of practical shadow algorithms, with a focus on terrain rendering for GIS systems. Blog articles by Pettineo [1403, 1404] and Casta˜no [235] are particularly valuable for their practical tips and solutions, as well as a demo code base. See Scherzer et al. [1558]for a shorter summary of work specifically focused on hard shadows. The survey of algorithms for soft shadows by Hasenfratz et al. [675] is dated, but covers a wide range of early work in some depth.
我们在这一章的重点是基本原则和阴影算法需要什么样的品质——可预测的品质和性能——对交互式渲染有用。我们避免了对渲染领域的研究进行详尽的分类,因为有两篇文章讨论了这个主题。Eisemann等人的《实时阴影》一书[412]直接关注交互式渲染技术,讨论了各种算法及其优势和成本。SIGGRAPH 2012课程提供了这本书的摘录,同时也增加了对更新作品的参考[413]。他们的SIGGRAPH 2013课程的演示文稿可在他们的网站www.realtimeshadows.com获得。Woo和Poulin的书Shadow Algorithms Data Miner[1902]概述了用于交互式和批量渲染的各种阴影算法。两本书都提供了该领域数百篇研究文章的参考。Tuft的两篇文章[1791,1792]很好地概述了常用的阴影贴图技术和涉及的问题。bjrge[154]介绍了一系列适用于移动设备的流行阴影算法,以及比较各种算法的图像。Lilley的报告[1046]给出了实用阴影算法的可靠和广泛的概述,重点是GIS系统的地形渲染。pettino[1403,1404]和casta no[235]的博客文章特别有价值,因为它们提供了实用的技巧和解决方案,以及演示代码库。参见Scherzer等人[1558]对专门关注硬阴影的工作的简短总结。Hasenfratz等人[675]对软阴影算法的调查是过时的,但在一定程度上涵盖了广泛的早期工作。