1.2 照片级真实感渲染和光线追踪算法

来源:互联网 发布:js点击按钮弹出输入框 编辑:程序博客网 时间:2024/06/05 00:39

开启了一段新旅程,希望能坚持翻译完,并掌握pbr技术。
pbrt的中文翻译应该不止一家,我希望借由这次翻译,让自己习惯看英文文档,也顺便给自己的碎片时间找点事情做。
这第一篇零零散散用了三周,以后的章节可能时间会更久。
翻译中若有不正确的地方,欢迎留言指正。


1.2 PHOTOREALISTIC RENDERING AND
THE RAY-TRACING ALGORITHM

1.2 照片级真实感渲染和光线追踪算法



The goal of photorealistic rendering is to create an image of a 3D scene that is indistinguishable from a photograph of the same scene. 


照片级真实感渲染的目标是使一张通过3D场景渲染出来的图片看起来和真实世界的同样场景中照出来的照片没有差别(indistinguishable)。


Before we describe the rendering process,it is important to understand that in this context the word “indistinguishable” is imprecise because it involves a human observer, and different observers may perceive the same image differently.


在我们开始描述渲染流程前,需要先理解“没有差别”是因人而异的,所以不可能完全一致。


Although we will cover a few perceptual issues in this book, accounting for the precise characteristics of a given observer is a very difficult and largely unsolved problem. 


虽然我们会讨论一些涉及主观上的问题,但是我们不解决这类问题。


For the most part, we will be satisfied with an accurate simulation of the physics of light and its interaction with matter, relying on our understanding of display technology to present a good image to the viewer.


大多数情况下,我们通过对光的物理特性和与其他物体的交互的精确模拟,以及利用我们的渲染技巧来为观众呈现一个非常好的图像质量。


Most photorealistic rendering systems are based on the ray-tracing algorithm. Ray tracing is actually a very simple algorithm; it is based on following the path of a ray of light through a scene as it interacts with and bounces off objects in an environment. 


大多数照片级实感渲染系统都是基于光线追踪算法。光线追踪实际上是一个非常简单的算法,它的原理建立在对光在场景中传递时,处理它和环境中物体的相互作用和反射。


Although there are many ways to write a ray tracer, all such systems simulate at least the following
objects and phenomena:


虽然有很多种思路去实现一个光线追踪器(ray tracer),这些系统都模拟了下列一些对象和现象(phenomena [fɪˈnɑmənə]):


. Cameras: How and from where is the scene being viewed? Cameras generate raysfrom the viewing point into the scene.


摄像机:如何观察场景的哪一个部分?摄像机负责从视点(viewing point)生成场景中的光线。


. Ray-object intersections: We must be able to tell precisely where a given ray pierces a geometric object. In addition, we need to determine certain geometric properties of the object at the intersection point, such as a surface normal or its material. Most ray tracers also have some facility for finding the intersection of a ray with multiple objects, typically returning the closest intersection along the ray.


光线-物体的相互作用:我们要能精确的知道一个光线照射到了一个指定的几何体上。而且我们需要知道射入点的一些几何属性,比如面法线(surface normal)或者它的材质(material)。大部分光线追踪器都包含测量一个光线和多个物体的相交、返回距离最近的对象之类的功能。


. Light distribution: Without lighting, there would be little point in rendering a scene. A ray tracer must model the distribution of light throughout the scene, including not only the locations of the lights themselves, but also the way in which they distribute their energy throughout space.


光¬照分布:如果没有光照,那渲染出来的场景也没啥意义。一个光线追踪器应该对场景中的光照进行建模,除了描述光线(todo:光源)的位置,也包括描述这些光的能量是如何分布在场景中。


. Visibility: In order to know whether a given light deposits energy at a point on a surface, we must know whether there is an uninterrupted path from the point to the light source. Fortunately, this question is easy to answer in a ray tracer, since we can just construct the ray from the surface to the light, find the closest ray-object intersection, and compare the intersection distance to the light distance.


可见性:为了确定光是否照亮了某个物体(残留了能量),我们需要确定在光源和目标表面照射点之间是否有一条不被阻碍的连线路径。幸运的是,这个问题对光线追踪器来说很简单,我们只需要构造一条从物体表面到光源的射线,找到最近的相交物体,比较一下被检测物体表面到相交点的距离和被检测物体表面到光源的距离。


. Surface scattering: Each object must provide a description of its appearance, including information about how light interacts with the object’s surface, as well as the nature of the reradiated (or scattered) light. We are usually interested in the properties of the light that is scattered directly toward the camera. Models for surface scattering are typically parameterized so that they can simulate a variety of appearances.


表面散射:每个对象都应该提供它的外观的描述,其中需要包括光和自己表面的相互作用信息,以及对光的辐射性质(或散射)。我们一般只对散射向摄像机方向的光线感兴趣。对物体表面的光线散射建模时,一般都是参数化的,这样我们可以通过调节参数来模拟多种外观表现。


. Recursive ray tracing: Because light can arrive at a surface after bouncing off or passing through several other surfaces, it is usually necessary to trace additional rays originating at the surface to fully capture this effect. This is particularly important for shiny surfaces like metal or glass.


光线的递归追踪:由于光在到达某个表面后可以通过散射来到达更多的表面,所以一般我们需要跟踪更多的光线来充分捕捉这种物理现象的效果。这对光泽表面的物体表达尤为重要,比如金属或玻璃。


. Ray propagation: We need to know what happens to the light traveling along a ray as it passes through space. If we are rendering a scene in a vacuum, light energy remains constant along a ray. Although most human observers have never been in a vacuum, this is the typical assumption made by most ray tracers. More sophisticated models are available for tracing rays through fog, smoke, the Earth’s atmosphere, and so on.


光线传播:我们需要知道光线穿过空间时的情况。如果我们渲染在真空中的场景,光线的能量会在路径上保持一个常量。绝大多数人类都没去过真空环境。这是绝大多数光线追踪器的假设情况(assumption [əˈsʌmpʃən])。一些十分精细的光照模型可以模拟光线穿过雾、烟、地球的大气层之类的情况。


We will briefly discuss each of these simulation tasks in this section. In the next section, we will show pbrt’s high-level interface to the underlying simulation components and follow the progress of a single ray through the main rendering loop. We will also show one specific surface scattering model based on Turner Whitted’s original ray-tracing algorithm.


我们会在本章简略的讨论一下这些模拟目标。在下个章节,我们会展示pbrt的高级接口,以便方便理解这些组件以及通过单一光线的传递过程来了解主要的渲染流程。同时也会展示一个基于Turner Whitted的原始光线追踪算法建立的表面散射模型。




1.2.1 CAMERAS

1.2.1摄像机



Nearly everyone has used a camera and is familiar with its basic functionality: you indicate your desire to record an image of the world (usually by pressing a button), and the image is recorded onto a piece of film or an electronic sensor. 


大家基本上都用过照相机,它们的功能基本相同:你希望拍个照,于是按个按钮,然后图像就记录在一个胶片或电子传感器上了。


One of the simplest devices for taking photographs in the real world is called the pinhole camera. Pinhole cameras consist of a light-tight box with a tiny hole at one end (Figure 1.1). When the hole is uncovered, light enters this hole and falls on a piece of photographic paper that is affixed to the other end of the box. Despite its simplicity, this kind of camera is still used today, frequently for artistic purposes. Very long exposure times are necessary to get enough light on the film to form an image.


在现实中最简单的摄像机就是针孔成像摄像机(pinhole camera)。针孔成像包含一个不透光的盒子,其中一端上有一个小孔。当这个孔没被遮住时,光线通过这个孔落到盒子的另外一个面或者胶片上。鉴于这套原理的简易性,直到现在还有一部分照相机使用这样的技术来达到一些特定的艺术效果。需要曝光足够长的时间,才能获得足够的光线来进行成像。


Although most cameras are substantially more complex than the pinhole camera, it is a convenient starting point for simulation. The most important function of the camera is to define the portion of the scene that will be recorded onto the film. In Figure 1.1, it is easy to see that connecting the pinhole to the edges of the film creates a double pyramid that extends into the scene. Objects that are not inside this pyramid cannot be imaged onto the film. Because modern cameras image a more complex shape than a pyramid, we will refer to the region of space that can potentially be imaged onto the film as the viewing volume.


虽然几乎所有相机都比针孔相机的原理要复杂,但它作为我们的一个开端来说倒是挺方便的。对相机来说最重要的功能是定义场景中会被记录到胶卷上的可视部分。在图1.1里,你可以看到穿过盒子的两个椎体。如果场景中的物体不在盒子外面那个椎体内,就不会被拍进去。现代的相机的可视部分比椎体要复杂多了,我们将可视部分的空间统称为视见体(viewing volume)。


 


Figure 1.1: A Pinhole Camera.


Another way to think about the pinhole camera is to place the film plane in front of the pinhole, but at the same distance (Figure 1.2). Note that connecting the hole to the film defines exactly the same viewing volume as before. Of course, this is not a practical way to build a real camera, but for simulation purposes it is a convenient abstraction. When the film (or image) plane is in front of the pinhole, the pinhole is frequently referred to as the eye.


换一种思路,将成像平面移动到小孔的前方,距离保持不变。可以发现移动后对成像体系而而言视见体形状依然是一致的。当然我们无法实际造出来这么一个相机,但是对于模拟而言这是一个极好的抽象。当成像平面在孔的前方时,我们一般将孔称为“眼睛”(eye)。



 
Figure 1.2: When we simulate a pinhole camera, we place the film in front of the hole at the near plane, and the hole is renamed the eye.
图1.2: 当我们模拟一个针孔成像时,我们将成像平面设置在孔的前面,作为近平面(near plane),孔(hole)就改名叫做眼睛(eye)。


Now we come to the crucial issue in rendering: at each point in the image, what color value do we display? If we recall the original pinhole camera, it is clear that only light rays that travel along the vector between the pinhole and a point on the film can contribute to that film location. In our simulated camera with the film plane in front of the eye, we are interested in the amount of light traveling from the image point to the eye.


现在我们进入渲染的核心问题之一:图像上的每一个点,应该呈现出何种颜色?重新看一下针孔成像,只有沿着成像区中某点到小孔的直线的光线会到达成像区。在我们的前置成像区模型中,我们关心所有能到达眼睛的光线和其光照能量值。


Therefore, the task of the camera simulator is to take a point on the image and generate rays along which light is known to contribute to that image location. Because a ray consists of an origin point and a direction vector, this is particularly simple for the pinhole camera model of Figure 1.2: it uses the pinhole for the origin, and the vector from the pinhole to the near plane as the ray’s direction. For more complex camera models involving multiple lenses, the calculation of the ray that corresponds to a given point on the image may be more involved. However, if the process of converting image locations to rays is completely encapsulated in the camera module, the rest of the rendering system can focus on evaluating the lighting along those rays, and a variety of camera models can be supported. pbrt’s camera abstraction is described in detail in Chapter 6.


因此,模拟摄像机的任务就是选取图像上的一个点,生成一条光线作为这个点的颜色来源。一条射线包含一个原点和一个方向向量,这个性质和图1.2所描述的成像模型一致:用眼睛当原点,眼睛到近平面上的点作为射线的方向。更加复杂的摄像机模型涉及多个镜头,这样关于成像点的计算会涉及到对多条射线进行跟踪。简而言之,如果我们将成像点和射线的关系封装到摄像机(Camera)对象里,那么渲染系统的其他部分就可以只关心计算光线沿着这些射线的传播情况,同时这些系统也可以支持各种不同模型的摄像机。pbrt的摄像机概念将在第六章详细讨论。


1.2.2 RAY-OBJECT INTERSECTIONS
1.2.2计算光线和物体的相交



Each time the camera generates a ray, the first task of the renderer is to determine which object, if any, that ray intersects first and where the intersection occurs. This intersection point is the visible point along the ray, and we will want to simulate the interaction of light with the object at this point. To find the intersection, we must test the ray for intersection against all objects in the scene and select the one that the ray intersects first. 


每次摄像机生成一个射线,首要任务就是检测首先和哪个物体相交以及相交于何处(如果有的话)。这个相交点就是沿着这条射线的可视点,然后我们希望在这个点上模拟光线和物体的(基于物理的)相互作用。为了找出相交,我们需要测试射线和所有物体的是否相交,并选用第一个交点。


Given a ray r, we first start by writing it in parametric form:
r(t) = o + td,
where o is the ray’s origin, d is its direction vector, and t is a parameter whose legal range is [0, ∞). We can obtain a point along the ray by specifying its parametric t value and evaluating the above equation.


对于一条给定的射线r,我们首先将其表述为向量式:
r(t) = o + td
r = 射线
o = 原点
d = 方向
t = 指定点和原点的距离的值[0, ∞)
我们可以通过输入不同的t值来计算射线上任意一点的位置。


It is often easy to find the intersection between the ray r and a surface defined by an implicit function F(x, y, z) = 0. We first substitute the ray equation into the implicit equation, producing a new function whose only parameter is t. We then solve this function fort and substitute the smallest positive root into the ray equation to find the desired point. For example, the implicit equation of a sphere centered at the origin with radius r is
x2 + y2 + z2 − r2 = 0,
so substituting the ray equation, we have
o + td2 x + o + td2 y + o + td2 z − r2 = 0.
This is just a quadratic equation in t, so we can easily solve it. If there are no real roots, the ray must miss the sphere. If there are roots, we select the smaller positive one to find the intersection point. 


如果有一个表面能被描述为F(x, y, z) = 0,那么我们很容易得到射线r和它的交点。我们只需要联立方程组求解。比如一个球形表面的方程为:
x2 + y2 + z2 − r2 = 0,
联立方程之后是:
o + td2 x + o + td2 y + o + td2 z − r2 = 0.
这样就只是跟t有关的一个方程了,我们很容易就可以对它求解。如果t没有实根,表示射线没有和球相交。如果有根,我们选择比较小的那个正数根作为相交点的t值,从而确定交点位置。


The intersection point is not enough information for the rest of the ray tracer; it needs to know certain properties of the surface at the point. First, the appearance model needs to be extracted and passed along to later stages of the ray-tracing algorithm, and additional geometric information about the intersection point will also be required in order to shade the point. For example, the surface normal n is always required. Although many ray tracers operate with only n, more sophisticated rendering systems like pbrt require even more information, such as various partial derivatives of position and surface normal with respect to the local parameterization of the surface.


对于余下的光线追踪流程,光知道交点的位置还不行,还需要知道交点的表面属性。首先模型的外观信息(diffuse纹理之类的)需要被提炼出来,供光线追踪算法的后续的处理阶段使用,然后一些额外的几何体信息也需要,用来指导对成像点的着色。比如面法线n (surface normal n)总是需要的。一部分光线追踪器只需要n,而像pbrt之类更精细的渲染系统需求更多的信息,比如局部参数化的位置和表面法线的各种偏导数(用来计算光的辐射能量)。


Of course, most scenes are made up of multiple objects. The brute-force intersection approach would be to test the ray against each object in turn, choosing the minimum t value of the intersections found. This approach, while correct, is very slow, even for scenes of modest complexity. A solution is to incorporate an acceleration structure that quickly rejects whole groups of objects during the ray intersection process. This ability to quickly cull irrelevant geometry means that ray tracing frequently runs in O(I log N) time, where I is the number of pixels in the image and N is the number of objects in the scene.2 (Building the acceleration structure is necessarily at least O(N) time.) The geometric interface supported by pbrt is described in Chapter 3, and the acceleration interface is shown in Chapter 4.


大多数的场景必然由多个对象组成。比较暴力的相交计算方法是计算射线和每一个物体是否相交,选择t值最小的那个相交点作为结果。这个方法,虽然正确,但是极慢,即使处理复杂程度并不高的场景来说也是。一个解决方法是建立(特定的)用于构建高效算法的数据结构,对不相交对象进行快速排除,查询耗时可以降低到O(I log N)的时间级别,I是image的pixel数量,N是待检测对象数量。(建立加速用的数据结构需要O(N)的时间。) 
pbrt支持的几何体结构在章节三讨论,加速结构在章节四讨论。


1.2.3 LIGHT DISTRIBUTION
1.2.3 光照分布



The ray-object intersection stage gives us a point to be shaded and some information about the geometry at that point. Recall that our eventual goal is to find the amount of light leaving this point in the direction of the camera. In order to do this, we need to know how much light is arriving at this point. This involves both the geometric and radiometric distribution of light in the scene. For very simple light sources (e.g., point lights), the geometric distribution of lighting is a simple matter of knowing the position of the lights.


计算光线和物体相交的阶段可以为我们提供一个需要被渲染的点和一些这个点的几何信息。回想一下我们的最终目标是得到从这个点出发,沿着射向摄像机方向的射线的光照能量。为了达成这个目的,我们需要知道多少光子到达了这个点。这涉及到在场景中的光的几何和辐射分布。对于非常简单的光源(例如点光源),如果光源位置明确的话,光照的几何分布是一个简单的问题


However, point lights do not exist in the real world, and so physically based lighting is often based on area light sources. This means that the light source is associated with a geometric object that emits illumination from its surface. However, we will use point lights in this section to illustrate the components of light distribution; rigorous discussion of light measurement and distribution is the topic of Chapters 5 and 12. 


不过,点光源在真实世界中是不存在的,因此基于物理学的光照模型通常都是基于面光源的。这意味着光源都是具有几何形状的,它沿着自己的几何表面向外发光。但是在这一节中我们将使用点光源来说明光分布的组成部分,对光的测量和分布的严密讨论是第五章和第十二章的主题。


We frequently would like to know the amount of light energy being deposited on the differential area surrounding the intersection point (Figure 1.3). We will assume that the point light source has some power Φ associated with it, and that it radiates light equally in all directions. This means that the total amount of energy on a sphere surrounding the light isΦ/(4π). (These measurements will be explained and formalized in Chapter 12.) 


我们通常希望知道在交点及其附近(differential area)接收到的辐射量(就是建立数学模型,用于计算光量的吸收之类的效果)(图1.3)。我们假定点光源具有的功率(辐射通量)为Φ,并且这个光源在所有方向上的辐射量是均匀的(各项同性isotropic)。这意味着如果(换一个思路考虑这个问题)有一个球体内包含着这个光源,那么球体内壁受到的辐射总能量为Φ/(4π)。(这些公式参数会在第十二章节进行详解。)


【如果你不懂上面在说什么(和半个小时之前的我一样),快速阅读这些补充知识:】
【立体角:https://zh.wikipedia.org/zh-hans/%E7%AB%8B%E9%AB%94%E8%A7%92 】
【辐射度量与光度量:http://wenku.baidu.com/view/eb11351e59eef8c75fbfb371.html 】
【各向异性:https://zh.wikipedia.org/wiki/%E5%90%84%E5%90%91%E5%BC%82%E6%80%A7 】


If we consider two such spheres (Figure 1.4), it is clear that the energy at a point on the larger sphere must be less than the energy at a point on the smaller sphere because the same total energy is distributed over a larger area. 


如果我们考虑两个球体分别包含同一个光源的情况(一个大球,一个小球,光源不变)(图1.4),很明显大球内表面上的某个点的光照能量要小于小球内壁的情况,因为光源的辐射总量没有发生变化,而大球具有更大的内表面面积,导致光能分布到了更大的表面上。


Specifically, the amount of energy arriving at a point on a sphere of radius r is proportional to 1/r2. Furthermore, it can be shown that if the tiny surface patch dA is tilted by an angle θ away from the vector from the surface point to the light, the amount of energy deposited on dA is proportional to cos θ. 


具体来说,对于一个半径为r的球形,到达一个点的能量与1/ r2成正比。同时,可以证对于面法线和交点到光源方向的夹角(立体角)为θ的一小块面积dA,其接受的能量与cosθ成正比。


Putting this all together, the total light energy dE (the differential irradiance) deposited on dA is
dE=Φcos⁡θ/4πr2


将上述综合起来,可得出dA受到的总能量为:
dE=Φcos⁡θ/4πr2




Readers already familiar with basic lighting in computer graphics will notice two familiar laws encoded in this equation: the cosine falloff of light for tilted surfaces mentioned above, and the one-over-r-squared falloff of light with distance.


已经熟悉了一些基本光照模型的读者可能会发现这里的两个性质:微小表面上的能量与cosθ成正比、与距离r成1/r2的反比。


 
Figure 1.3: Geometric construction for evaluating the light energy at a point due to a point light source. The distance from the point to the light source is denoted by r.
图1.3:计算一个点光源照射到物体表面上的一个点的光照能量的几何示意图。照射点p到点光源的距离为r。
 
Figure 1.4: Since the point light radiates light equally in all directions, the same total energy is deposited on all spheres centered at the light.
图1.4:因为点光源向所有方向都等量的进行光辐射,所以任何将点光源置于其内部(任意位置,放中间是为了方便比较)的球体的内壁都会受到等量的光辐射量。


Scenes with multiple lights are easily handled because illumination is linear: the contribution of each light can be computed separately and summed to obtain the overall contribution.


对于具有多个光源的场景,(因为光的波动性)因为光照是线性叠加的,所以处理起来也比较简单:只需要将所有光源分别进行计算,再将结果进行叠加。




1.2.4 VISIBILITY
1.2.4 可见性

The lighting distribution described in the previous section ignores one very important component: shadows. Each light contributes illumination to the point being shaded only if the path from the point to the light’s position is unobstructed (Figure 1.5).


之前的章节在描述光照的时候(故意)忽略了一个非常重要的部分:影子。每条光线能参与着色的前提是在光线出发点和照射点之前没有被阻挡。(图1.5)


 
Figure 1.5: A light source only deposits energy on a surface if the source is not obscured as seen from the receiving point. The light source on the left illuminates the point p, but the light source on the right does not.


图1.5:照射点和光源之间必须没有阻碍才能获得照明。P点可以被左边的光源照到,但是右边的就照不到。(说的很对,但不知道为什么觉得很囧T_T)


Fortunately, in a ray tracer it is easy to determine if the light is visible from the point being shaded. We simply construct a new ray whose origin is at the surface point and whose direction points toward the light. These special rays are called shadow rays. If we trace this ray through the environment, we can check to see whether any intersections are found between the ray’s origin and the light source by comparing the parametric t value of any intersections found to the parameteric t value along the ray of the light source position. If there is no blocking object between the light and the surface, the light’s contribution is included.


幸运的很,对一个光线追踪器来说,检测着色点是否能被光源照到很简单。我们只需要在被检查点构造一个朝向光源的射线(ray)。这些射线有一个专有名词:阴影线(shadow rays)。我们检查这个射线和环境的相交情况,如果有任何交点,并且交点的t值是否在射线的原点到光源之间。如果检查点和光源之间没有任何阻挡物,这条光线就参与光照计算。


1.2.5 SURFACE SCATTERING
1.2.5 表面散射


We now are able to compute two pieces of information that are vital for proper shading of a point: its location and the incident lighting.3 Now we need to determine how the incident lighting is scattered at the surface. Specifically, we are interested in the amount of light energy scattered back along the ray that we originally traced to find the intersection point, since that ray leads to the camera (Figure 1.6).


现在我们掌握了(对物体表面某个点)进行着色时至关重要的两个部分:如何定位和它的入射光。现在我们需要判断入射光在表面上如何进行散射。特别是散射到摄像机(眼睛)的光线,根据射入光携带的能量和物体表面的散射情况,计算反射光线的能量变化。(图1.6)


Each object in the scene provides a material, which is a description of its appearance properties at each point on the surface. This description is given by the Bidirectional Reflectance Distribution Function (BRDF). This function tells us how much energy is reflected from a given incoming direction ωi to a given outgoing direction ωo. We will write the BRDF at p as fr(p, ωo, ωi). Now, computing the amount of light L scattered back toward the camera is straightforward:


场景中的每个对象都具有一个材质,它描述了这个对象表面每个点的外观属性。这些属性是根据双向反射分布函数(Bidirectional Reflectance Distribution Function (BRDF))得出的。此函数可以告诉我们沿着入射角ωi的光线的能量在沿着反射角ωo 反射时的能量衰减系数。我们将关于P点的BRDF记作fr(p, ωo, ωi)。现在计算散射回摄像机的光照能量L就很简单了:


for each light:
if light is not blocked:
incident_light = light.L(point)
amount_reflected =
surface.BRDF(hit_point, camera_vector, light_vector)
L += amount_reflected * incident_light


 
Figure 1.6: The Geometry of Surface Scattering. Incident light arriving along direction ωi interacts with the surface at point p and is scattered back toward the camera along direction ωo. The amount of light scattered toward the camera is given by the product of the incident light energy and the BRDF.
图1.6:表面散射结构。入射光沿着ωi和物体表面相交于p点,并沿着ωo散射向摄像机。反射光的能量由入射光能量和BRDF(Bidirectional Reflectance Distribution Function)计算得出。


Here we are using L to represent the light; this represents a slightly different unit for light measurement than dE, which was used before. It is easy to generalize the notion of a BRDF to transmitted light (obtaining a BTDF) or to general scattering of light arriving from either side of the surface. A function that describes general scattering is called a Bidirectional Scattering Distribution Function (BSDF). pbrt supports a variety of both physically and phenomenologically based BSDF models; they are described in Chapter 8


我们将光线记作L,它和之前的dE稍微有些不同。我们可以很容易的将BRDF的概念推广到光的折射部分(简称BTDF(Bidirectional Transmittance Distribution Function))或者散射部分。描述一般性的散射的函数称为双向散射分布函数(BSDF)。(B*DF哈哈)。pbrt支持许多基于BSDF模型的物理现象模拟,这些特性会在第八章节进行介绍。


1.2.6 RECURSIVE RAY TRACING
1.2..6光线追踪递归



Turner Whitted’s original paper on ray tracing emphasized its recursive nature. For example, if a ray from the camera hits a shiny object like a mirror, we can reflect the ray about the surface normal at the intersection point and recursively invoke the ray-tracing routine to find the light arriving at the point on the mirror, adding its contribution to the original camera ray. This same technique can be used to trace transmitted rays that intersect transparent objects. For a long time, most early ray-tracing examples showcased mirrors and glass balls (Figure 1.7) because these types of effects were difficult to capture
with other rendering techniques.


Turner Whitted 在论文中强调了光线追踪算法的递归性质。例如如果一条从摄像机发出的光线射中了类似镜子一样的光泽表面,我们可以通过交点的面法线计算出反射光路径,并且用这个反射光当新的入射光,将它纳入有效光照,并对它继续进行光线追踪流程,找出新入射光相关的信息。对于在透明物体中发生的折射现象也使用同样的思路。在很长的一段时间里,对多个镜面球和玻璃球同时进行渲染的场景被当做炫耀光线追踪程序的例子(图1.7),因为对于其他类型的渲染引擎来说渲染这种效果十分困难。
 
Figure 1.7: A Prototypical Example of Early Ray Tracing. Note the use of mirrored and glass objects, which emphasize the algorithm’s ability to handle these kinds of surfaces.




In general, the amount of light that reaches the camera from a point on an object is given by the sum of light emitted by the object (if it is itself a light source) and the amount of reflected light. This idea is formalized by the light transport equation (also often known as the rendering equation), which says that the outgoing radiance Lo(p, ωo) from a point p in direction ωo is the emitted radiance at that point in that direction, Le(p, ωo), plus the incident radiance from all directions on the sphere S2 around p scaled by the BSDF f (p, ωo, ωi) and a cosine term:


一般来讲,一个物体能到达摄像机的光线来自于它的自发光(如果它是个光源)和它所反射的光。
这个思路可以由光传输方程(通常也被称为渲染方程)来表达:对于物体表面上的任意点p,在这个点上的射出辐射量Lo(p, ωo),等于这个点的自发光辐射量Le(p, ωo),加上根据BSDF函数f (p, ωo, ωi)计算得出的在p点周围的微小表面s2的反射的量,以及一个和余弦相关的函数。


Lo(p,ωo)= Le(p,ωo)+∫_s2▒〖 (p,ωo,ωi)Li(p,ωi)|cos⁡θi |dωi〗


We will show a more complete derivation of this equation in Sections 5.6.1 and 15.2. Solving this integral analytically is not possible except for the simplest of scenes, so we must either make simplifying assumptions or use numerical integration techniques. Whitted’s algorithm simplifies this integral by ignoring incoming light from most directions and only evaluating Li(p, ωi) for directions to light sources and for the directions of perfect reflection and refraction. In other words, it turns the integral into a sum over a small number of directions.


这个公式更详细的推导过程会在5.6.1和15.2章节进行介绍。除非场景非常简单,否则求这个方程的解析解比较困难。因此我们需要做一些假设以便简化情况,这样便于对方程求得数值解。Whitted的算法的简化方法是忽略大多数方向的入射光,只计算来自光源的入射光Li(p, ωi)和在理想表面上的反射和折射光。换句话说,算法把积分变成有限方向的累加。




Whitted’s method can be extended to capture more effects than just perfect mirrors and glass. For example, by tracing many recursive rays near the mirror-reflection direction and averaging their contributions, we obtain an approximation of glossy reflection. In fact, we can always recursively trace a ray whenever we hit an object. For example, we can randomly choose a reflection direction ωi and weight the contribution of this newly spawned ray by evaluating the BRDF fr(p, ωo, ωi). This simple but powerful idea can lead to very realistic images because it captures all of the interreflection of light between objects. Of course, we need to know when to terminate the recursion, and choosing directions completely at random may make the rendering algorithm slow to converge to a reasonable result. These problems can be addressed, however; these issues are the topic of Chapters 13 to 15.


可以对Whitted的算法进行扩展,以便处理更多类型的表面,而不仅仅是理想镜面和玻璃。比如说,如果我们相对镜面反射光的方向,对一些在方向上做过微小偏移的光线进行追踪计算,然后取它们的平均值,就可以模拟粗糙表面的效果。事实上不论何时,只要光照射到某个物体上,我们就可以对它进行光线追踪。举个例子,我们可以随机选取任意一个由BRDF函数 fr(p, ωo, ωi)计算出的反射方向ωi,然后规定它的贡献值。这个想法很简单,但是对于实现真实感级别的画质特别有用,因为这意味着我们可以计算任意对象之间的光线相互反射现象。当然,我们需要知道何时结束递归计算,并且如果彻底的使用随机会让渲染算法生成一张达到质量要求的图片时效率降低。不过这些问题都能解决,这些问题将是第十三章和第十五章的主题。




When we trace rays recursively in this manner, we are really associating a tree of rays with each image location (Figure 1.8), with the ray from the camera at the root of this tree. Note that each ray in this tree can have a weight associated with it; this allows us to model, for example, shiny surfaces that do not reflect 100% of the incoming light.


当我们用这种递归的方法进行光线追踪时,实际上我们为图像上每个点都构造了一棵具有多条射线的树型结构(图1.8),树的根节点是从摄像机发出的射线。注意这棵树里的每一条射线都可以有一个权重,这样可以让我们根据需要进行材质建模,举个例子,不是所有的光滑表面都100%反射全部的入射光。


 
Figure 1.8: Recursive ray tracing associates an entire tree of rays with each image location.
图1.8: 递归的光线追踪会为每一个像素点构造一棵射线树。




1.2.7 RAY PROPAGATION
1.2.7 光线传播


The prior discussion has assumed that rays are traveling through a vacuum. For example, when describing the distribution of light from a point source, we assumed that the energy was distributed equally on the surface of a sphere centered at the light without decreasing along the way. The presence of participating media such as smoke, fog, or dust can invalidate this assumption. Many ray tracers ignore these phenomena, though doing so is quite limiting. Even if we are not making a rendering of a smoke-filled room, almost all outdoor scenes are affected substantially by participating media. For example, Earth’s atmosphere causes objects that are farther away to appear less saturated (Figure 1.9). 


之前的讨论都是假设光线在真空里传播。比如说,当一个球体将点光源完全包含,并将光源置为球体的中心位置时,我们说这个点光源向所有方向辐射的能量是相等的,球体内壁接受到的辐射量也是均匀的,特别是没有沿着距离进行衰减。由于传播介质的存在打破没有衰减的这个假设,比如烟、雾、浮尘。许多光线追踪器选择忽视这些现象,不过这样做的话会给渲染效果带来极大的限制。就算我们不渲染一个充满烟雾的房间,大多数室外场景也会受某些传播介质的影响。例如,地球的大气会导致离得远的物体看起来不太饱和(图1.9)。


There are two ways in which a participating medium can affect the light propagating along a ray. First, the medium can extinguish (or attenuate) light, either by absorbing it or by scattering it in a different direction. We can capture this effect by computing the transmittance T between the ray origin and the intersection point. The transmittance tells us how much of the light scattered at the intersection point makes it back to the ray origin.


传播介质可以通过两种方式来影响光线的传播。首先,介质能通过吸收能量或在不同于光线原始传播方向的其他方向上进行散射来熄灭(或减弱)光(遮挡的意思)。我们能通过计算射线原点和相交点之间的透光率T来获得这种效果。透光率指出有多少光在交点处通过散射返回了射线原点。


A participating medium can also add to the light along a ray. This can happen either if the medium emits light (as with a flame) or if the medium scatters light from other directions back along the ray (Figure 1.10). We can find this quantity by numerically evaluating the volume light transport equation, in the same way we evaluated the light transport equation to find the amount of light reflected from a surface. We will leave the description of participating media and volume rendering until Chapters 11 and 16. For now, it will suffice to say that we can compute the effect of participating media and incorporate its effect into the amount of light carried by the ray.


传播介质也可以沿着射线方向增加光的强度。比如介质本身会发光(如火焰)或者介质将其他方向的光散射到射线的方向(图1.10)。我们可以通过体积光传输公式(volume light transport equation)来对这些增加的光强度进行量化计算,同时我们也可以通过同样的方法计算出被一个表面反射的光的总量。我们将传输介质的详细描述和体积光的渲染方法留给第十一章和第十六章。目前我们只需要了解到我们可以计算传输介质对光的影响以及量化地融合介质对射线方向上光强度的影响。


 

 


Figure 1.9: Earth’s Atmosphere Decreases Saturation with Distance. The scene on the top is rendered without simulating this phenomenon, while the scene on the bottom includes an atmospheric model. This sort of atmospheric attenuation is an important depth cue when viewing real scenes and adds a sense of scale to the rendering on the bottom.
图1.9:地球的大气会根据距离减少饱和度。上面的场景是不模拟这个现象的渲染效果,下面的场景则是包含了对大气的建模。这种大气造成的衰减效果对于场景渲染来说在增加景深和构造规模感方面十分重要。


 
Figure 1.10: A Spotlight Shining on a Sphere through Fog. Notice that the shape of the spotlight’s lighting distribution and the sphere’s shadow are clearly visible due to the additional scattering in the participating medium.
图1.10:一个聚光灯透过雾照射到一个球体上。可以观察到聚光灯的光线分布的体型,并且球体的影子的体型在传播介质中清晰可见。(立体的部分,不是地上的圆片)
0 0
原创粉丝点击