Skip to content

Commit 206b725

Browse files
committed
add lecture 13
1 parent b2b0d5d commit 206b725

14 files changed

+108
-6
lines changed

Notes13.md

Lines changed: 74 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,22 +21,92 @@ glossy 表示有点反光, 但是又有些粗糙的物体 (铜镜)
2121

2222
光线的一个性质: 光路可逆 (也就是追踪的意思)
2323

24+
![image](https://github.com/lumixraku/NotesForGraphics/raw/master/images/raytracing4.png)
25+
26+
27+
沿着一根光线, 记录最近的交点
28+
2429
![image](https://github.com/lumixraku/NotesForGraphics/raw/master/images/raytracing.png)
2530

2631
光线追踪因为 ray 是从眼睛( 摄像机 ) 发出, 因此天然的解决了遮挡(深度测试)的问题,
2732

33+
34+
2835
## Whitted Style Ray tracing
2936

37+
Whitted Style: 多次递归反射, 就是在模拟光线在不断弹射的过程.
38+
3039
![image](https://github.com/lumixraku/NotesForGraphics/raw/master/images/raytracing2.png)
3140

41+
下面是一个玻璃球, 既有折射, 又有反射. 同时还要计算和光源的情况.
42+
43+
![image](https://github.com/lumixraku/NotesForGraphics/raw/master/images/raytracing5.png)
44+
45+
其实从这个图可以看到 光路有很多条, 最终我们要计算的是他们的和 (每条光路存在能量损失, 不然加起来光线亮度就很亮了)
46+
47+
48+
![image](https://github.com/lumixraku/NotesForGraphics/raw/master/images/raytracing6.png)
49+
50+
51+
52+
### 和球的交点
53+
54+
![image](https://github.com/lumixraku/NotesForGraphics/raw/master/images/raytracing7.png)
55+
56+
### 和显式表面怎么做呢?
57+
刚才 f(xx) = 0 是一个隐式表面的几何表达形式.
58+
59+
显式表面其实是求光线和三角形面的交点.
60+
61+
PS
62+
63+
如果一个点在封闭物体内部, 不论物体形状如何, 从这个点出发任意一条射线, 与物体的交点一定是奇数
64+
65+
### 和三角形面的交点
66+
67+
先判断和平面相交, 再判断交点是否在三角形中.
68+
69+
如何判断和平面是否相交呢?
70+
光线的定义已经有了 o + td 那么如何定义平面呢?
71+
72+
通过法线 和某一个点 其实就定义了平面
73+
74+
![image](https://github.com/lumixraku/NotesForGraphics/raw/master/images/raytracing8.png)
75+
76+
两个向量点乘是0 表示相互垂直 (p' 是平面上任意一个点)
77+
78+
79+
和前面和球球交点问题一样, 交点即在平面上 有在光线上. 因此两个公式都满足.
80+
![image](https://github.com/lumixraku/NotesForGraphics/raw/master/images/raytracing9.png)
81+
82+
### 上面的方式是先和平面求交点, 再判断是否在三角形内. 有么有更加直接的办法呢?
83+
![image](https://github.com/lumixraku/NotesForGraphics/raw/master/images/raytracing10.png)
84+
85+
注意公式中的 1 - b1 -b2 , 点既然在三角形内, 那么这个点可以使用中心坐标去表示. (重心坐标的一个性质就是 b1+ b2 + b3 = 1)
86+
87+
剩下的部分就是接方程组了
88+
89+
3290
## AABB 轴对齐包围盒
3391
用来减少没有必要的计算
3492

35-
基于这么一条结论: 如果光线都不和包
36-
\围盒相交, 那么光线更不和可能和包围盒中的物体相交.
93+
我们的摄像机, 也就是你所看到的屏幕. 每个像素都要发出一条光线, 和场景中所有的三角形求交点, 然后光线还要不断反射. 这样太慢了 怎么帮
3794

38-
![image](https://github.com/lumixraku/NotesForGraphics/raw/master/images/aabb1.png)
3995

40-
最终的包围盒中的射线, 是这三者求交集
96+
97+
基于这么一条结论: 如果光线都不和包围盒相交, 那么光线更不和可能和包围盒中的物体相交. 所以可以利用包围盒做加速
98+
99+
上下左右前后 3对对面, 形成一个包围盒.
100+
101+
![image](https://github.com/lumixraku/NotesForGraphics/raw/master/images/aabb3.png)
102+
103+
104+
先看2D 情况下的包围盒
105+
106+
光线射入, 记录下碰到对面1 的时间 和 离开对面2 的时间.
107+
108+
![image](https://github.com/lumixraku/NotesForGraphics/raw/master/images/aabb1.png)
41109

42110
![image](https://github.com/lumixraku/NotesForGraphics/raw/master/images/aabb2.png)
111+
112+
最终的包围盒中的射线, 是这三者求交集

Notes14.md

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,40 @@
11
# Lecture 14 Ray tracing 2
22

3-
## 包围盒切分
3+
## AABB 如何帮助加速光线追踪
4+
5+
与物体相交的格子标记为某一种类型 (右上角漏标记了)
6+
7+
![image](https://github.com/lumixraku/NotesForGraphics/raw/master/images/accray.png)
8+
9+
10+
假设: 光线和盒子相交很快, 光线和物体三角面求交很快.
11+
12+
![image](https://github.com/lumixraku/NotesForGraphics/raw/master/images/accray2.png)
13+
14+
因此很重要的是如何合理的将空间划分成各种格子. 如果这个光线经过的格子中有物体, 就要开始求光线和物体是否相交.
15+
16+
格子不能太密(不然光线和太多格子求交点效率低) 不能太稀疏(不然很容易要和格子中的物体求交点)
17+
18+
19+
20+
![image](https://github.com/lumixraku/NotesForGraphics/raw/master/images/accray3.png)
21+
22+
根据经验, 格子数 = 某个常数 * 空间中物体数
23+
24+
不过这种格子划分, 似乎太呆板了. 每个格子大小都一样, 实际上在物体稀疏的地方, 可以不用那么多格子.
25+
26+
27+
28+
如何在一个体育场中找到一个茶壶呢?
29+
30+
## 空间切分
31+
32+
![image](https://github.com/lumixraku/NotesForGraphics/raw/master/images/spatial.png)
33+
434

535
### Oct-Tree
36+
通过对空间的切分, 切分成了一些不均匀的结构.
37+
638
八叉树是针对三维世界而言, 图中看起像是四叉树, 但是这只是一个立方体的截面.
739
所以
840

@@ -17,7 +49,7 @@
1749

1850
## KD-tree
1951
从空间开始划分
20-
![image](https://github.com/lumixraku/NotesForGraphics/raw/master/images/kdtree.jpg)
52+
![image](https://github.com/lumixraku/NotesForGraphics/raw/master/images/kdtree.png)
2153

2254

2355
## BVH

images/aabb3.png

315 KB
Loading

images/accray.png

164 KB
Loading

images/accray2.png

183 KB
Loading

images/accray3.png

153 KB
Loading

images/raytracing10.png

314 KB
Loading

images/raytracing4.png

266 KB
Loading

images/raytracing5.png

165 KB
Loading

images/raytracing6.png

1.42 MB
Loading

0 commit comments

Comments
 (0)