Real-Time Rendering——7.5 Percentage-Closer Filtering百分比接近过滤(PCF)

A simple extension of the shadow-map technique can provide pseudo-soft shadows. This method can also help ameliorate resolution problems that cause shadows to look blocky when a single light-sample cell covers many screen pixels. The solution is similar to texture magnification (Section 6.2.1). Instead of a single sample being taken off the shadow map, the four nearest samples are retrieved. The technique does not interpolate between the depths themselves, but rather the results of their comparisons with the surface’s depth. That is, the surface’s depth is compared separately to the four texel depths, and the point is then determined to be in light or shadow for each shadow-map sample. These results, i.e., 0 for shadow and 1 for light, are then bilinearly interpolated to calculate how much the light actually contributes to the surface location. This filtering results in an artificially soft shadow. These penumbrae change, depending on the shadow map’s resolution, camera location, and other factors. For example, a higher resolution makes for a narrower softening of the edges. Still, a little penumbra and smoothing is better than none at all.

阴影贴图技术的简单扩展可以提供伪软阴影。这种方法还有助于改善分辨率问题,当单个光照样本单元覆盖许多屏幕像素时,这些问题会导致阴影看起来呈块状。解决方案类似于纹理放大(第6.2.1节)。不是从阴影贴图中取出单个样本,而是检索四个最近的样本。该技术不是在深度本身之间进行插值,而是将深度与表面深度进行比较的结果。也就是说,将表面的深度分别与四个纹理元素深度进行比较,然后为每个阴影贴图样本确定该点是在亮处还是在阴影处。这些结果,即阴影为0,光为1,然后进行双线性插值,以计算光对表面位置的实际贡献。这种过滤会产生一种人工的柔和阴影。这些半影会根据阴影贴图的分辨率、摄影机位置和其他因素而变化。例如,分辨率越高,边缘的柔化越窄。尽管如此,一点半影和平滑总比没有好。

This idea of retrieving multiple samples from a shadow map and blending the results is called percentage-closer filtering (PCF) [1475]. Area lights produce soft shadows. The amount of light reaching a location on a surface is a function of what proportion of the light’s area is visible from the location. PCF attempts to approx- imate a soft shadow for a punctual (or directional) light by reversing the process.Instead of finding the light’s visible area from a surface location, it finds the visibility of the punctual light from a set of surface locations near the original location. See Figure 7.22. The name “percentage-closer filtering” refers to the ultimate goal, to find the percentage of the samples taken that are visible to the light. This percentage is how much light then is used to shade the surface.

这种从阴影贴图中检索多个样本并混合结果的想法被称为百分比接近过滤(PCF) [1475]。区域光产生柔和的阴影。到达表面上某个位置的光量是从该位置可见的光面积比例的函数。PCF试图通过反转该过程来近似估算点状(或定向)灯光的柔和阴影。它不是从曲面位置查找灯光的可见区域,而是从原始位置附近的一组曲面位置查找点光源的可见性。参见图7.22。“百分比接近过滤”这个名称指的是最终目标,即找到对光可见的样本的百分比。这个百分比就是有多少光线被用来遮挡表面。

Figure 7.22. On the left, the brown lines from the area light source show where penumbrae are formed. For a single point p on the receiver, the amount of illumination received could be computed by testing a set of points on the area light’s surface and finding which are not blocked by any occluders. On the right, a point light does not cast a penumbra. PCF approximates the effect of an area light by reversing the process: At a given location, it samples over a comparable area on the shadow map to derive a percentage of how many samples are illuminated. The red ellipse shows the area sampled on the shadow map. Ideally, the width of this disk is proportional to the distance between the receiver and occluder.

在左边,来自面光源的棕色线条显示了半影形成的地方。对于接收器上的单个点p,可以通过测试区域光表面上的一组点并找到没有被任何遮光器遮挡的点来计算接收的照明量。在右侧,点光源不投射半影。PCF通过反转该过程来近似区域光的效果:在给定位置,它在阴影贴图上的可比区域上采样,以得出有多少样本被照亮的百分比。红色椭圆显示阴影贴图上采样的区域。理想情况下,这个圆盘的宽度与接收器和封堵器之间的距离成正比。

In PCF, locations are generated nearby to a surface location, at about the same depth, but at different texel locations on the shadow map. Each location’s visibility is checked, and these resulting boolean values, lit or unlit, are then blended to get a soft shadow. Note that this process is non-physical: Instead of sampling the light source directly, this process relies on the idea of sampling over the surface itself. The distance to the occluder does not affect the result, so shadows have similar-sized penumbrae. Nonetheless this method provides a reasonable approximation in many situations.

在PCF中,位置生成在表面位置附近,在大约相同的深度,但是在阴影图上的不同纹理元素位置。检查每个位置的可见性,然后将这些结果布尔值(亮的或不亮的)混合在一起,得到一个柔和的阴影。请注意,这个过程是非物理的:这个过程不是直接对光源进行采样,而是依赖于对表面本身进行采样的想法。到遮光器的距离不会影响结果,因此阴影具有相似大小的半影。尽管如此,这种方法在许多情况下提供了一个合理的近似值。

Once the width of the area to be sampled is determined, it is important to sample in a way that avoids aliasing artifacts. There are numerous variations of how to sample and filter nearby shadow-map locations. Variables include how wide of an area to sample, how many samples to use, the sampling pattern, and how to weight the results. With less-capable APIs, the sampling process could be accelerated by a special texture sampling mode similar to bilinear interpolation, which accesses the four neighboring locations. Instead of blending the results, each of the four samples is compared to a given value, and the ratio that passes the test is returned [175]. However, performing nearest neighbor sampling in a regular grid pattern can create noticeable artifacts. Using a joint bilateral filter that blurs the result but respects object edges can improve quality while avoiding shadows leaking onto other surfaces [1343]. See Section 12.1.1 for more on this filtering technique.

一旦确定了采样区域的宽度,就必须避免混叠伪影。对于如何采样和过滤附近的阴影贴图位置,有许多不同的方法。变量包括采样区域的宽度、使用的样本数量、采样模式以及如何对结果进行加权。对于能力较弱的API,可以通过类似于双线性插值的特殊纹理采样模式来加速采样过程,该模式访问四个相邻位置。不是混合结果,而是将四个样本中的每一个与给定值进行比较,并返回通过测试的比率[175]。然而,在规则网格模式中执行最近邻采样会产生明显的伪像。使用模糊结果但尊重对象边缘的联合双边过滤器可以提高质量,同时避免阴影泄漏到其他表面上[1343]。有关该过滤技术的更多信息,请参见第12.1.1节。

DirectX 10 introduced single-instruction bilinear filtering support for PCF, giving a smoother result [53, 412, 1709, 1790]. This offers considerable visual improvement over nearest neighbor sampling, but artifacts from regular sampling remain a problem. One solution to minimize grid patterns is to sample an area using a precomputed Poisson distribution pattern, as illustrated in Figure 7.23. This distribution spreads samples out so that they are neither near each other nor in a regular pattern. It is well known that using the same sampling locations for each pixel, regardless of the distribution, can result in patterns [288]. Such artifacts can be avoided by randomly rotating the sample distribution around its center, which turns aliasing into noise. Castan ̃o [235] found that the noise produced by Poisson sampling was particularly noticeable for their smooth, stylized content. He presents an efficient Gaussian-weighted sampling scheme based on bilinear sampling.

DirectX 10引入了对PCF的单指令双线性过滤支持,给出了更平滑的结果[53,412,1709,1790]。与最近邻采样相比,这提供了相当大的视觉改进,但是来自常规采样的伪像仍然是一个问题。最小化格网模式的一个解决方案是使用预计算的泊松分布模式对一个区域进行采样,如图7.23所示。这种分布将样本分散开来,使它们既不相互靠近,也不呈规则模式。众所周知,无论分布如何,对每个像素使用相同的采样位置都会产生图案[288]。这种伪影可以通过围绕其中心随机旋转样本分布来避免,这将混叠转变为噪声。卡斯塔恩·̃o[235]发现泊松采样产生的噪声因其平滑、风格化的内容而特别引人注目。他提出了一种基于双线性采样的高效高斯加权采样方案。

Figure 7.23. The far left shows PCF sampling in a 4×4 grid pattern, using nearest neighbor sampling. The far right shows a 12-tap Poisson sampling pattern on a disk. Using this pattern to sample the shadow map gives the improved result in the middle left, though artifacts are still visible. In the middle right, the sampling pattern is rotated randomly around its center from pixel to pixel. The structured shadow artifacts turn into (much less objectionable) noise. (Images courtesy of John Isidoro, ATI Research, Inc.)

最左边显示了使用最近邻采样的4×4网格模式的PCF采样。最右边显示了磁盘上的12抽头泊松采样模式。使用这种模式对阴影贴图进行采样,可以在中间的左侧得到改善的结果,尽管伪像仍然可见。在中间右侧,采样模式围绕其中心从一个像素到另一个像素随机旋转。结构化阴影伪像变成了(更少令人讨厌的)噪声。(图片由ATI研究公司的约翰·伊西多罗提供)

Self-shadowing problems and light leaks, i.e., acne and Peter Panning, can become worse with PCF. Slope scale bias pushes the surface away from the light based purely on its angle to the light, with the assumption that a sample is no more than a texel away on the shadow map. By sampling in a wider area from a single location on a surface, some of the test samples may get blocked by the true surface.

自阴影问题和漏光,即痤疮和彼得潘,可以变得更糟的PCF。“坡度比例偏移”完全基于曲面与灯光的角度将曲面推离灯光,并假设采样在阴影贴图上的距离不超过一个纹理像素。通过从表面上的单个位置在更宽的区域取样,一些测试样品可能会被真实表面阻挡。

A few different additional bias factors have been invented and used with some success to reduce the risk of self-shadowing. Burley [212] describes the bias cone, where each sample is moved toward the light proportional to its distance from the original sample. Burley recommends a slope of 2.0, along with a small constant bias. See Figure 7.24.

已经发明了一些不同的附加偏置因子,并成功地用于降低自阴影的风险。Burley [212]描述了偏置锥体,其中每个样本都朝着与原始样本的距离成比例的光移动。Burley建议斜率为2.0,并带有一个小的恒定偏差。参见图7.24。

Figure 7.24. Additional shadow bias methods. For PCF, several samples are taken surrounding the original sample location, the center of the five dots. All these samples should be lit. In the left figure, a bias cone is formed and the samples are moved up to it. The cone’s steepness could be increased to pull the samples on the right close enough to be lit, at the risk of increasing light leaks from other samples elsewhere (not shown) that truly are shadowed. In the middle figure, all samples are adjusted to lie on the receiver’s plane. This works well for convex surfaces but can be counterproductive at concavities, as seen on the left side. In the right figure, normal offset bias moves the samples along the surface’s normal direction, proportional to the sine of the angle between the normal and the light. For the center sample, this can be thought of as moving to an imaginary surface above the original surface. This bias not only affects the depth but also changes the texture coordinates used to test the shadow map.

其他阴影偏差方法。对于PCF,在原始样本位置(五个点的中心)周围取几个样本。所有这些样品都应该被点燃。在左图中,形成了一个偏置锥体,样品向上移动到它上面。可以增加锥体的陡度,以将右边的样本拉得足够近而被照亮,冒着增加从其他地方(未示出)真正被遮蔽的其他样本的光泄漏的风险。在中间的图中,所有样本被调整为位于接收器的平面上。这对于凸面非常有效,但是对于凹面可能会适得其反,如左侧所示。在右图中,法线偏移偏移沿着曲面的法线方向移动样本,与法线和灯光之间的角度的正弦值成比例。对于中心样本,这可以被认为是移动到原始曲面上方的虚拟曲面。这种偏差不仅会影响深度,还会改变用于测试阴影贴图的纹理坐标。

Schu ̈ler [1585], Isidoro [804], and Tuft [1790] present techniques based on the ob- servation that the slope of the receiver itself should be used to adjust the depths of the rest of the samples. Of the three, Tuft’s formulation [1790] is most easily applied to cascaded shadow maps. Dou et al. [373] further refine and extend this concept, ac- counting for how the z-depth varies in a nonlinear fashion. These approaches assume that nearby sample locations are on the same plane formed by the triangle. Referred to as receiver plane depth bias or other similar terms, this technique can be quite pre- cise in many cases, as locations on this imaginary plane are indeed on the surface, or in front of it if the model is convex. As shown in Figure 7.24, samples near concavities can become hidden. Combinations of constant, slope scale, receiver plane, view bias, and normal offset biasing have been used to combat the problem of self-shadowing, though hand-tweaking for each environment can still be necessary [235, 1391, 1403].

舒·̈ler[1585]、伊西多罗[804]和塔福特[1790]提出了基于观测的技术,即接收器本身的斜率应用于调整其余样本的深度。在这三者中,Tuft的公式[1790]最容易应用于级联阴影贴图。Dou等人【373】进一步完善和扩展了这一概念,解释了z深度如何以非线性方式变化。这些方法假设附近的样本位置在由三角形形成的同一平面上。称为接收器平面深度偏差或其他类似术语,这种技术在许多情况下可以相当精确,因为这个假想平面上的位置实际上在表面上,或者如果模型是凸的,则在它的前面。如图7.24所示,凹面附近的样本可能会被隐藏。常数、斜率、接收器平面、视角偏差和法向偏移偏差的组合已被用于解决自阴影问题,尽管仍有必要针对每个环境进行手动调整[235,1391,1403]。

One problem with PCF is that because the sampling area’s width remains constant, shadows will appear uniformly soft, all with the same penumbra width. This may be acceptable under some circumstances, but appears incorrect where there is ground contact between the occluder and receiver. See Figure 7.25.

PCF的一个问题是,因为采样区域的宽度保持不变,所以阴影看起来均匀柔和,所有阴影都具有相同的半影宽度。在某些情况下,这可能是可以接受的,但在封堵器和接收器之间有地面接触的情况下,这似乎是不正确的。参见图7.25。

Figure 7.25. Percentage-closer filtering and percentage-closer soft shadows. On the left, hard shadows with a little PCF filtering. In the middle, constant width soft shadows. On the right, variable-width soft shadows with proper hardness where objects are in contact with the ground. (Images courtesy of NVIDIA Corporation.) 

百分比接近过滤和百分比接近软阴影。在左边,硬阴影带有一点PCF过滤。在中间,恒定宽度的软阴影。在右边,物体与地面接触的地方有适当硬度的可变宽度的软阴影。(图片由英伟达公司提供。)

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

椰子糖莫莫

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值