Real-Time Rendering——5.2.2 Punctual Lights精准光

A punctual light is not one that is on time for its appointments, but rather a light that has a location, unlike directional lights.Such lights also have no dimensions to them,no shape or size, unlike real-world light sources.

精准光不是准时赴约的灯,而是有位置的灯,不像定向灯。这种灯也没有尺寸,没有形状或大小,不像现实世界的光源。

We use the term “punctual,” from the Latin punctus meaning “point,” for the class consisting of all sources of illumination that originate from a single, local position. We use the term “point light” to mean a specific kind of emitter, one that shines light equally in all directions. So, point and spotlight are two different forms of punctual lights.

我们用“精准”这个词来表示所有的照明来源都来自于一个单一的、局部的位置,这个词来自拉丁语puntus,意思是“点”。我们用“点光”这个词来表示一种特定的发射器,一种可以向所有方向均匀发光的发射器。所以,点和聚光灯是准时灯的两种不同形式。

The light direction vector l varies depending on the location of the currently shaded surface point p0 relative to the punctual light’s position plight:

灯光方向向量l根据当前着色表面点p0相对于点光源位置的位置而变化:

This equation is an example of vector normalization: dividing a vector by its length to produce a unit-length vector pointing in the same direction. 

这个等式是向量归一化的一个例子:用向量除以它的长度,得到一个指向同一方向的单位长度向量。

This is another common shading operation, and, like the shading operations we have seen in the previous section, it is a built-in function in most shading languages.

这是另一种常见的着色操作,就像我们在上一节中看到的着色操作一样,它是大多数着色语言中的内置函数。

Applying this to the punctual light direction computation gives us the following:

将此应用于点光源方向计算,我们得到以下结果:

Since the dot product of two vectors is equal to the product of the two vector’s lengths with the cosine of the angle between them, and the cosine of 0° is 1.0,the dot product of a vector with itself is the square of its length. So, to find the length of any vector,we just dot it with itself and take the square root of the result. 

因为两个向量的点积等于两个向量的长度与它们之间角度的余弦的乘积,并且0°的余弦是1.0,所以向量与其自身的点积是其长度的平方。因此,要找到任何向量的长度,我们只需用它本身点积下,然后取结果的平方根。

The intermediate value that we need is r, the distance between the punctual light source and the currently shaded point. Besides its use in normalizing the light vector,the value of r is also needed to compute the attenuation (darkening) of the light color clight as a function of distance. This will be discussed further in the following section.

我们需要的中间值是r,点光源和当前阴影点之间的距离。除了用于归一化光矢量,r的值也需要计算光色光的衰减(变暗),作为距离的函数。这将在下一节中进一步讨论。

Point/Omni Lights 点/泛光灯

Punctual lights that emit light uniformly in all directions are known as point lights or omni lights. For point lights, clight varies as a function of the distance r, with the only source of variation being the distance attenuation mentioned above.

向各个方向均匀发光的点光源称为点光源或泛光灯。对于点光源,clight作为距离r的函数而变化,变化的唯一来源是上面提到的距离衰减。

Figure 5.5 shows why this darkening occurs, using similar geometric reasoning as the demonstration of the cosine factor in Figure 5.4.

图5.5显示了为什么会出现这种变暗现象,使用了与图5.4中余弦系数的论证相似的几何推理。

Figure 5.5. The spacing between light rays from a point light increases proportionally to the distance r. Since the spacing increase occurs in two dimensions, the density of rays (and thus the light intensity) decreases proportionally to

图5.5。来自点光源的光线之间的间距与距离r成比例增加。由于间距的增加发生在二维空间中,因此光线密度(以及光强度)与成比例减少。

 This enables us to specify the spatial variation in clight with a single light property, clight0 , which is defined as the value of clight at a fixed reference distance r0:

这使我们能够用单一光属性clight0指定clight的空间变化,clight 0定义为固定参考距离r0处的clight值:

Equation 5.11 is often referred to as inverse-square light attenuation. Although technically the correct distance attenuation for a point light, there are some issues that make this equation less than ideal for practical shading use. 

等式5.11通常被称为平方反比光衰减。虽然从技术上来说,点光源的距离衰减是正确的,但是对于实际的着色使用来说,还有一些问题使得这个公式不太理想。

The first issue occurs at relatively small distances. As the value of r tends to 0,the value of clight will increase in an unbounded manner. When r reaches 0, we will have a divide-by-zero singularity. To address this, one common modification is to add a small value to the denominator 

第一个问题发生在相对较小的距离。当r的值趋于0时,clight的值将以无界的方式增加。当r达到0时,我们将有一个被零除的奇点。为了解决这个问题,一个常见的修改是在分母上增加一个小的值 

 

The exact value used for depends on the application; for example, the Unreal game engine uses 

用于的确切值取决于应用;例如,虚幻游戏引擎使用 .

An alternative modification, used in the CryEngine and Frostbite game engines, is to clamp r to a minimum value rmin:

在CryEngine和Frostbite游戏引擎中使用的另一种修改将clamp r到最小值rmin:

Unlike the somewhat arbitrary value used in the previous method, the value of rmin has a physical interpretation: the radius of the physical object emitting the light.Values of r smaller than rmin correspond to the shaded surface penetrating inside the physical light source, which is impossible. 

与前面方法中使用的有些随意的值不同,rmin的值有一个物理解释:发出光的物理对象的半径。小于rmin的r值对应于穿透物理光源内部的阴影表面,这是不可能的。

 In contrast, the second issue with inverse-square attenuation occurs at relatively large distances. The problem is not with visuals but with performance. Although light intensity keeps decreasing with distance it never goes to 0.

相比之下,平方反比衰减的第二个问题发生在相对较大的距离。问题不在于视觉效果,而在于性能。尽管光强度随着距离的增加而不断降低,但它永远不会达到0。

For efficient rendering, it is desirable for lights to reach 0 intensity at some finite distance (Chapter 20). There are many different ways in which the inverse-square equation could be modified to achieve this. Ideally the modification should introduce as little change as possible. To avoid a sharp cutoff at the boundary of the light’s influence, it is also preferable for the derivative and value of the modified function to reach 0 at the same distance.

为了有效的渲染,希望灯光在有限的距离达到0强度(第20章)。有许多不同的方法可以修改平方反比方程来实现这一点。理想情况下,修改应该引入尽可能少的变化。为了避免在光影响的边界处突然截止,修改函数的导数和值在相同距离处达到0也是优选的。

One solution is to multiply the inverse-square equation by a windowing function with the desired properties. One such function is used by both the Unreal Engine and Frostbite game engines:

 一种解决方案是将平方反比方程乘以具有所需属性的窗口函数。一个这样的函数被虚幻引擎和Frostbite游戏引擎使用:

The +2 means to clamp the value, if negative, to 0 before squaring it. Figure 5.6 shows an example inverse-square curve, the windowing function from Equation 5.14,and the result of multiplying the two. 

+2表示在平方该值之前,如果该值为负值,则将其固定为0。图5.6显示了一个平方反比曲线的例子,方程5.14的窗口函数,以及两者相乘的结果。

Figure 5.6. This graph shows an inverse-square curve (using the method to avoid singularities, with an value of 1), the windowing function described in Equation 5.14 (with rmax set to 3), and the windowed curve. 

图5.6。该图显示了一条平方反比曲线(使用方法避免奇点,值为1)、等式5.14中描述的窗口函数(rmax设置为3)和窗口曲线。

Application requirements will affect the choice of method used. For example,having the derivative equal to 0 at rmax is particularly important when the distance attenuation function is sampled at a relatively low spatial frequency (e.g., in light maps or per-vertex). CryEngine does not use light maps or vertex lighting, so it employs a simpler adjustment, switching to linear falloff in the range between 0.8rmax and rmax

应用要求将影响所用方法的选择。例如,当以相对低的空间频率(例如,在光照贴图或逐顶点中)对距离衰减函数进行采样时,在rmax处导数等于0是特别重要的。CryEngine不使用光照贴图或顶点照明,因此它采用了更简单的调整,切换到0.8rmax和rmax之间的线性衰减

For some applications, matching the inverse-square curve is not a priority, so some other function entirely is used. This effectively generalizes Equations 5.11–5.14 to the following:

对于某些应用来说,匹配平方反比曲线并不是优先考虑的事情,所以完全使用其他函数。这有效地将方程5.11-5.14推广到如下:

where fdist(r) is some function of distance. Such functions are called distance falloff functions. In some cases, the use of non-inverse-square falloff functions is driven by performance constraints. 

其中fdist(r)是距离的函数。这种函数称为距离衰减函数。在某些情况下,非平方反比衰减函数的使用是由性能约束决定的。

For example, the game Just Cause 2 needed lights that were extremely inexpensive to compute. This dictated a falloff function that was simple to compute, while also being smooth enough to avoid per-vertex lighting artifacts

例如,游戏Just Cause 2只需要计算起来非常便宜的灯。这规定了一个衰减函数,它计算起来很简单,同时也足够平滑以避免每顶点的灯光伪像

In other cases, the choice of falloff function may be driven by creative considerations.For example, the Unreal Engine, used for both realistic and stylized games,has two modes for light falloff: an inverse-square mode, as described in Equation 5.12,and an exponential falloff mode that can be tweaked to create a variety of attenuation curves. 

在其他情况下,衰减函数的选择可能是出于创造性的考虑。例如,用于真实和风格化游戏的虚幻引擎有两种灯光衰减模式:平方反比模式,如等式5.12中所述,以及指数衰减模式,可以调整该模式以创建各种衰减曲线。

The developers of the game Tomb Raider (2013) used spline-editing tools to author falloff curves, allowing for even greater control over the curve shape.

游戏《古墓丽影》(2013)的开发者使用样条编辑工具来创作衰减曲线,允许对曲线形状进行更大的控制。

Spotlights聚光灯

Unlike point lights, illumination from nearly all real-world light sources varies by direction as well as distance. This variation can be expressed as a directional falloff function fdir(l), which combines with the distance falloff function to define the overall spatial variation in light intensity:

与点光源不同,几乎所有真实光源的照明都随方向和距离而变化。这种变化可以表示为方向衰减函数fdir(l ),它与距离衰减函数结合来定义光强度的整体空间变化:

Different choices of fdir(l) can produce various lighting effects. One important type of effect is the spotlight, which projects light in a circular cone. 

选择不同的fdir(l)可以产生不同的照明效果。一种重要的效果是聚光灯,它将光线投射成圆锥形。

A spotlight’s directional falloff function has rotational symmetry around a spotlight direction vector s, and thus can be expressed as a function of the angle θs between s and the reversed light vector −l to the surface. The light vector needs to be reversed because we define l at the surface as pointing toward the light, and here we need the vector pointing away from the light.

聚光灯的方向衰减函数具有围绕聚光灯方向向量s的旋转对称性,因此可以表示为s与表面反向光向量l之间的角度θs的函数。灯光向量需要反转,因为我们将曲面上的l定义为指向灯光,这里我们需要指向远离灯光的向量。

Most spotlight functions use expressions composed of the cosine of θs, which (as we have seen earlier) is the most common form for angles in shading. Spotlights typically have an umbra angle θu, which bounds the light such that fdir(l) = 0 for all θs ≥ θu.This angle can be used for culling in a similar manner to the maximum falloff distance rmax seen earlier. It is also common for spotlights to have a penumbra angle θp, which defines an inner cone where the light is at its full intensity. See Figure 5.7.

大多数聚光灯函数使用由θs的余弦组成的表达式,这是阴影中角度最常见的形式(正如我们前面看到的)。聚光灯通常有一个本影角度θu,它限制了光线,使得对于所有θs ≥ θu,fdir(l) = 0。该角度可用于剔除,其方式与前面看到的最大衰减距离rmax类似。聚光灯的半影角θp也很常见,半影角θp定义了光线处于最大强度的内锥。参见图5.7。

Figure 5.7. A spotlight: θs is the angle from the light’s defined direction s to the vector −l, the direction to the surface; θp shows the penumbra; and θu shows the umbra angles defined for the light. 

图5.7。聚光灯:θs是从光的定义方向s到向量l的角度,向量l是表面的方向;θp表示半影;θu表示为光线定义的本影角度。

Various directional falloff functions are used for spotlights, but they tend to be roughly similar. For example, the function fdirF(l) is used in the Frostbite game engine, and the function fdirT(l) is used in the three.js browser graphics library:

各种方向衰减函数用于聚光灯,但它们大致相似。比如函数fdirF(l)用在Frostbite游戏引擎中,函数fdirT(l)用在three.js浏览器图形库中:

Recall that x+ is our notation for clamping x between 0 and 1, as introduced in Section 1.2. The smoothstep function is a cubic polynomial that is often used for smooth interpolation in shading. It is a built-in function in most shading languages. 

回想一下,x+是我们将x clamping在0和1之间的符号,如1.2节所介绍的。smoothstep函数是一个三次多项式,通常用于着色中的平滑插值。它是大多数着色语言中的内置函数。

Figure 5.8 shows some of the light types we have discussed so far.

图5.8显示了我们到目前为止讨论过的一些光源类型。

Figure 5.8. Some types of lights. From left to right: directional, point light with no falloff, and spotlight with a smooth transition. Note that the point light dims toward the edges due to the changing angle between the light and the surface. 

图5.8。一些类型的灯。从左到右:无衰减的平行光、点光源和平滑过渡的聚光灯。请注意,由于灯光和曲面之间的角度不断变化,点光源会向边缘变暗。

In Section 6.9 we will discuss how light intensity and color can be varied via the use of textures.

在6.9节中,我们将讨论如何通过使用纹理来改变光的强度和颜色。

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

椰子糖莫莫

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

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

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

打赏作者

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

抵扣说明:

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

余额充值