关于程序员:GAMES101-NotesRay-Tracing-Introduction-L13

3次阅读

共计 2932 个字符,预计需要花费 8 分钟才能阅读完成。

Ray Tracing – Introduction(L13)

0.Introduction

0.1 光栅化无奈解决的问题

Rasterization couldn’t handle global effects well.

1.Soft Shadows(软暗影)

2.light bounces more than once(屡次反射)

0.2 Rasterization vs. Ray Tracing

Rasterization
-fast, but low-quality
-real-time

Ray Tracing
-accurate, but very slow
-offline
-~10K CPU core hours to render one frame in production

品质和工夫为“Trade-off”

1.Recursive (Whitted-Style) Ray Tracing

1.1 Light Rays

根本假如:直线传播;不产生碰撞;光路可逆

(将物体发射到观察者的光线等效成由观察者发向物体一道“感知光线”,光路仍成立,这也是光线 “追踪“ 的命名由来)

1. Light travels in straight lines (though this is wrong) 
2. Light rays do not“collide”with each other if they cross (though this is still wrong) 
3. Light rays travel from the light sources to the eye (but the physics is invariant under path reversal - reciprocity[可逆性]).

Eyes send out feeling rays to the world

1.2 Ray Casting(光线投射:生成不同的光线)

1.2.1 概述

根本流程:1. Generate an image by casting one ray per pixel 
2. Check for shadows by sending a ray to the light

1.2 2 An Example:

Assumptions
1. 光源为点光源,眼睛为针孔摄像机(即疏忽光源和相机的大小和尺寸)

Step 1

Step 2

根本步骤:1. 对于每个像素,与眼睛连线造成 Ray,计算这条光线照亮的场景中最近的点
2. 该点与光源连线[这条连线叫做 Shadow Ray],断定是否被照亮以及计算色彩
3. 将计算结果写回原像素

1.2.3 Recursive Ray Casting(Whitted-Style) 概述

模仿光线一直弹射的过程,将屡次反射和折射的后果都退出到该点的像素值上

留神:屡次反射和折射当然要思考能量衰减。

效果图

1.3 Ray-surface Intersection

1.3.1 Ray Equation

Ray is defined by its origin and a direction vector.

$$
\vec{r}(t)=\vec{o}+t\vec{d}(0\leq t<\infty)
$$

ATTENTION:图形学中个别不纠结边界条件(如 t >0 还是 t >=0)

Example: Ray Intersection With Sphere

$$
Ray:\vec{r}(t)=\vec{o}+t\vec{d}(0\leq t<\infty)\\
Sphere:(\vec{p}-\vec{c})^2-R^2=0\\
Solve\space for\space intersection:(\vec{o}+t\vec{d}-\vec{c})^2-R^2=0
$$

最初能够化为二次方程进行求解,留神依据光线与球面的地位关系分类探讨。

1.3.2 For implicit surface

$$
General\space implicit\space surface:f(\vec{p})=0\\
Substitute\space ray\space equation:f(\vec{o}+t\vec{d})=0\\
[Solve\space for\space positive\space roots.]
$$

<center>Examples of implicit surfaces</center>

1.3.3 For Triangle Mesh(Explicit surfaces)

(作为显式示意的最重要代表,选用三角形面)


[Point in polygon Test]

查看一点是否在多边形之内,可作一射线从该点开始往任意方向投射,如果射线与多边形边的交点个数为奇数,则该点位于多边形外部。


然而间接按此办法断定光线和三角形面的地位关系计算量过大。

改良:问题转化为 求出光线和三角形所在立体的交点,再判断交点是否在三角形外部

示意

定义立体:法线 + 立体上任意一点 P ’

$$
Plane\space Equation:(\vec{p}-\vec{p’})\cdot \vec{N}=0\\
能够写成 \space ax+by+cz+d=0
$$

至此曾经能够解出光线与立体的交点,再断定是否在三角形外部。

改良:(能够间接解出光线和三角形的交点,并验证其解的合理性)

重心坐标均非负,则交点在三角形内

1.4 Accelerating Ray-Surface Intersection

在像素数过多、光线弹射状况简单时,上述办法效率过低。

San Miguel Scene(经典场景), 10.7M triangles

1.4.1 Bounding Volumes

引入”突围盒“Bounding Volumes,即 光线如果不会碰到 Bounding Volumes,则它肯定不会碰到物体

对于 Bounding Volumes 的进一步定义:Bounding Box is the intersection of 3 pairs of slabs

即:突围盒是三组立体的交加

罕用突围盒:Axis-Aligned Bounding Box(AABB,轴对齐突围盒)

1.4.2 Ray Intersection with AABB
KEY ideas
The ray enters the box only when it enters all pairs of slabs 
The ray exits the box as long as it exits any pair of slabs

即:进入任何一对立体即认为进入 box,来到所有立体才认为来到 box。

因而对于每一对立体计算 $t_{min}$ 和 $t_{max}$,求出进入工夫和来到工夫:

$$
For\space 3D\space box,\\ t_{enter}=max\{t_{min}\}\\t_{exit}=min\{t_{max}\}\\
$$

再思考因为光线理论为射线带来的正负号问题。

$$
若 t_{exit}<0,\space 则 box 在光线前方 \Rightarrow 无交点 \\
若 t_{exit}\geq0,t_{enter}<0,\space 则光线终点位于 box 外部 \Rightarrow 有交点
$$

综上,失去论断:

$$
Ray\space and\space AABB\space intersect\space iff (if\space and\space only\space if)\\
t_{enter}<t_{exit}\\t_{exit}\geq0
$$

1.4.3 Why Axis-Aligned?

因为计算更不便。

正文完
 0