文章目录
Basic Ray-Tracing Algorithm
Recursive Ray Tracing:递归地弹射光线
Ray-Surface Intersection
Ray Intersection With Implicit Surface
光线与隐式表面求交,解方程即可
Ray Intersection With Triangle
光线与显式表面求交,则要求光线与三角形面的交点
思路:先求光线与三角形所在平面的交点,再判断交点是否在三角形内
用点法式求光线与平面的交点:
Accelerating Ray-Surface Intersection
Bounding Volumes
先检测光线与包围盒是否相交,如果光线与包围盒不相交,也不会和物体相交
Axis-Aligned Bounding Box(AABB):轴对齐包围盒,盒子的边与坐标轴平行
Ray Intersection With Axis Aligned Box
-
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
t e n t e r = max ( t m i n ) t e x i t = min ( t m a x ) t_{enter}=\max (t_{min}) \\ t_{exit}=\min (t_{max}) tenter=max(tmin)texit=min(tmax)
光线与包围盒相交的条件:
(
t
e
n
t
e
r
<
t
e
x
i
t
)
∧
(
t
e
x
i
t
≥
0
)
(t_{enter} \lt t_{exit}) \land (t_{exit} \ge 0)
(tenter<texit)∧(texit≥0)
Spatial Partitions
按照空间划分包围盒
KD-Tree
叶子结点:store list of objects
中间结点:store split axis, split position, and pointers to child nodes
缺点:可能有一个物体在多个包围盒中的情况
Object Partitions
Bounding Volume Hierarchy(BVH)
BVH划分后可以保证一个物体只在一个包围盒中,但包围盒与包围盒之间可能有重叠的地方
每次选择最长的一条边,从中间物体的位置划分
Radiometry
用物理正确的方式描述光线能量的传播
Radiant Energy and Flux
Radiant Energy:the energy of electromagnetic radiation,光源辐射出的能量
Q [ J = J o u l e ] Q[J=Joule] Q[J=Joule]
Radiant Flux(Power):the energy emitted, reflected, transmitted or received, per unit time,单位时间内辐射的能量
photons flowing through a sensor in unit time
Φ ≡ d Q d t [ W = W a t t ] [ l m = l u m e n ] \Phi \equiv \frac{dQ}{dt}[W=Watt][lm=lumen] Φ≡dtdQ[W=Watt][lm=lumen]
Radiant Intensity / Irradiance / Radiance
Solid Angle
Ω = A r 2 \Omega = \frac{A}{r^{2}} Ω=r2A
球的立体角是
4
π
4\pi
4π
d A = ( r d θ ) ( r s i n θ d ϕ ) = r 2 s i n θ d θ d ϕ d ω = d A r 2 = s i n θ d θ d ϕ dA=(rd\theta)(rsin\theta d\phi)=r^{2}sin\theta d\theta d\phi \\ d\omega=\frac{dA}{r^{2}}=sin\theta d\theta d\phi dA=(rdθ)(rsinθdϕ)=r2sinθdθdϕdω=r2dA=sinθdθdϕ
Radiant Intensity:the power per unit solid angle emitted by a point light source
I ( ω ) ≡ d Φ d ω [ W s r ] [ l m s r = c d = c a n d e l a ] I(\omega) \equiv \frac{d\Phi}{d\omega}[\frac{W}{sr}][\frac{lm}{sr}=cd=candela] I(ω)≡dωdΦ[srW][srlm=cd=candela]
Irradiance:the power per unit area incident on a surface point
E ( x ⃗ ) ≡ d Φ ( x ⃗ ) d A [ W m 2 ] [ l m m 2 = l u x ] E(\vec x)\equiv \frac{d\Phi(\vec x)}{dA}[\frac{W}{m^{2}}][\frac{lm}{m^{2}=lux}] E(x)≡dAdΦ(x)[m2W][m2=luxlm]
Radiance:the power emitted, reflected, transmitted or received by a surface, per unit solid angle, per projected unit area
L ( P , ω ) ≡ d 2 Φ ( p , ω ) d ω d A cos θ L(P,\omega)\equiv \frac{d^{2}\Phi(p,\omega)}{d\omega dA\cos\theta} L(P,ω)≡dωdAcosθd2Φ(p,ω)
The quantity associated with a ray
-
Radiance: Irradiance per solid angle
-
Radiance: Intensity per projected unit area
Irradiance就是Radiance在半球上的积分
BRDF
Bidirectional Reflectance Distribution Function
Radiance from direction ω i \omega_{i} ωi turns into the power E that dA receives, then power E will become the radiance to any other direction ω o \omega_{o} ωo
BRDF: represents how much light is reflected into each outgoing direction
ω
r
\omega_{r}
ωr from each incoming direction
ω
i
\omega_{i}
ωi
Rendering Equation
L o ( p , ω o ) = L e ( p , ω o ) + ∫ Ω + L i ( p , ω i ) f r ( p , ω i , ω o ) ( n ⋅ ω i ) d ω i L_{o}(p,\omega_{o}) = L_{e}(p,\omega_{o}) + \int_{\Omega +}L_{i}(p,\omega_{i}) f_{r}(p,\omega_{i},\omega_{o})(n\cdot \omega_{i})d\omega_{i} Lo(p,ωo)=Le(p,ωo)+∫Ω+Li(p,ωi)fr(p,ωi,ωo)(n⋅ωi)dωi
上面铺垫了很多,都是为了得到这个方程。到了这里,却不必再有什么多余的解释。
大道至简!
Monte Carlo Integration
hard to solve an integral, then estimate it by averaging random samples of the function’s value
∫ f ( x ) d x = 1 N ∑ i = 1 N f ( X i ) p ( X i ) \int f(x)dx = \frac{1}{N}\sum_{i=1}^{N}\frac{f(X_{i})}{p(X_{i})} ∫f(x)dx=N1i=1∑Np(Xi)f(Xi)
Path Tracing
Whitted-Style Ray Tracing
-
Specular reflections / refractions
-
Stop bouncing at diffuse surfaces
缺点:无法实现glossy,diffuse表面也没有反射
Monte Carlo in Solving Path Tracing
渲染方程就是
ω
i
\omega_{i}
ωi在半球上的定积分,用蒙特卡洛方法可以求解
伪代码:
If ray r hits object q, use the direct illumination value at q as the light it reflects to p
Problem 1: Explosion of rays
当N很大时,计算量非常大
Path Tracing: only 1 ray is traced at each shading point,在一个着色点上只追踪一个
ω
i
\omega_{i}
ωi
Generate N rays in a pixel
Problem 2: Recursive never stop
保持期望不变的情况下,有一定概率停止递归
Problem 3: Waste of rays
Sampling the Light
defination of solid angle: projected area on the unit sphere
把对
d
ω
d\omega
dω的积分改写为对
d
A
dA
dA的积分
Final Version of the Algorithm
把radiance分为两部分,一部分是直接来自光源的,另一部分是来自其它物体反射的