delta tracking
what is a Ray?
上一章,我们理解了什么是光线投影(ray casting)和光线追踪(ray tracing)。这章节我们细致来看什么是光线。
ABSTRACT
We define a ray, show how to use ray intervals, and demonstrate how to specify a ray using DirectX Raytracing (DXR).
在本节中,我们会定义一条光线,展示了如何使用光线间隔(ray intervals),并演示了如何使用DirectX光线跟踪(DXR)来指定一个光线。
2.1 MATHEMATICAL DESCRIPTION OF A RAY
For ray tracing, an important computational construct is a three-dimensional ray. In both mathematics and ray tracing, a ray usually refers to a three-dimensional half-line. A ray is usually specified as an interval on a line. There is no implicit equation for a line in three dimensions analogous to the two-dimensional line y = mx + b, so usually the parametric form is used. In this chapter, all lines, points, and vectors are assumed to be three-dimensional.
对于光线追踪,一个重要的计算结构就是三维光线(3D ray)。 不管是在数学还是在光线追踪中,光线通常是指三维半线(half-line)(射线?)。一条光线通常会被指定为在一条直线(line)上的一部分(interval)。对于一条直线,在三维空间中很难找到一个类似二维空间中 y = m x + b y=mx+b y=mx+b这样的直线方程来隐式表示。因此,通常使用参数化形式来表示。在本章中,所有的直线、点和矢量均假定为三维空间中。
A parametric line can be represented as a weighted average of points A and B:
一条参数化表示的线可以记为点A和B的加权平均值:
P ( t ) = ( 1 − t ) A + t B P(t)=(1-t)A+tB P(t)=(1−t)A+tB
In programming, we might think of this representation as a function P(t) that takes a real number t as input and returns a point P. For the full line, the parameter can take any real value, i.e., t ∈ [−∞, +∞], and the point P moves continuously along the line as t changes, as shown in Figure 2-1. To implement this function, we need a way to represent points A and B. These can use any coordinate system, but Cartesian coordinates are almost always used. In APIs and programming languages, this representation is often called a vec3 or float3 and contains three real numbers x, y, and z. The same line can be represented with any two distinct points along the line. However, choosing different points changes the location defined by a given t-value.
在实际编程中,我们会将这种表示形式视为函数 P ( t ) P(t) P(t),该函数以实数 t t t作为输入并返回点 P P P。对于一个完整的直线,参数可以取任何实数,即 t ∈ [ − ∞ , + ∞ ] t∈[-∞,+∞] t∈[−∞,+∞]。点P随着 t t t的变化而沿直线连续移动,如图2-1所示
。 要实现这个思路,我们需要一种方式来表示点A和B。这里可以使用任何坐标系,但我们常用笛卡尔坐标系(Cartesian coordinates)。 在API和编程语言中,这种表示形式通常被称为vec3
或float3
,其中包含三个实数 x x x, y y y和 z z z。同一条线可以用沿线的任意两个不同的点表示。但是,选择不同的点会更改由给定 t t t值定义的位置。
It is common to use a point and a direction vector rather than two points. As visualized in Figure 2-2, we can choose our ray direction d as B − A and our ray origin O as point A, giving
但更常见的做法是使用一个点和一个方向向量而非两个点。 如图2-2所示,我们可以将射线方向d选择为B − A,将射线原点O选择为A点,得出
P 9 ( t ) = O + t d P9(t)=O+td P9(t)=O+td
For various reasons, e.g., computing cosines between vectors via dot products, some programs find it useful to restrict d to be a unit vector dˆ, i.e., normalized. One useful consequence of normalizing direction vectors is that t directly represents the signed distance from the origin. More generally, the difference in any two t-values is then the actual distance between the points,
由于各种原因,例如,我们可以通过点积计算向量之间的余弦,一些程序发现很有必要去对向量d做单位化处理变为 d ^ \hat{d} d^,如标准
。标准化后一个有用的结果就是 t t t可以直接表示原点开始的有符号距离。一般来说,任何两个t值之差就是两点之间的距离。
∥ P ( t 1 ) − P ( t 2 ) ∥ = ∣ t 2 − t 1 ∣ \Vert P(t_1)-P(t_2)\Vert =|t_2-t_1| ∥P(t1)−P(t2