Lec 13 Ray Tracing 1 (Whitted-Style Ray Tracing)
阅读信息
约 186 个字 3 分钟 本页总访问量:加载中... 次
Why ray tracing?
Rasterization couldn't handle global effects well.
e.g. soft shadows, and especially when the light bounces more than once (glossy relection, indirect illumination).
Rasterization is fast, but quality is relatively low.
Ray tracing is accurate, but is very slow.
Rasterization: real-time; ray tracing: offline
Three ideas about light rays:
- Light travels in straight lines
- Light rays do not "collide" with each other if thay cross
- Light rays travel from the light sources to the eye (but the physics is invariant under path reversal - reviprocity)
基本方法:
对每一个像素,从相机出发连线穿过像素(eye ray),打到场景中最近的交点(closest scene),再将这个点和光源连线(shadow ray)。如果能连线,则这个点能被光源可见。
Whitted-Style Ray Tracing
Whitted 风格:在任意点光线可继续传播(反射,折射...)
着色时,在每一个弹跳的点判断能否被光源照亮,考虑能量损失。最终像素的着色是所有弹跳点的着色之和。
从相机和像素连接的光线是primary ray,弹跳后形成的光线是secondary ray,和光源连接的光线是shadow ray。

Ray-Surface Intersection
Ray Equation:
Ray is defined by its origin and a direction vector.
(ray(time) = origin + time * direction)
Ray intersection with sphere:
联立光线方程和球的方程,解二次方程。
根据解的个数分为相离、相交和相切。相交时取更近的点。
Ray intersection with implicit surface:
Substitute ray equation:
Solve for real, positive roots.
How to compute?
Simple idea: just intersect ray with each triangle.
Ignore multiple intersections, each ray can have 0 or 1 intersections.
Ray Intersection with Triangle
- ray-plane intersection
- test if hit point is inside triangle
Plane equation:
plane is defined by normal vector (N) and a point (P') on plane.
Solve for intersection:
Then test if \(\mathbf{o}+t\mathbf{d}\) is inside triangle.
Faster: Moller Trunbore Algorithm
Give barycentric coordinate directly.
where \(t\), \(b_1\) and \(b_2\) are variables.
where
Ray Intersection with Axis-Aligned Box
Bounding Volumes :
Quick way to avoid intersections: bound complex object with a simple volume.
Box: the intersection of 3 pairs of slabs.
esp. we often use an Axis-Aligned Bounding Box (AABB), any side of the BB is along either x, y, or z axis.
Key ideas:
- The ray enters the box only when it enters all pairs of s;abs.
- The ray exits the box as long as it exits any pair of slabs.
For the 3D box, \(t_{enter}=max\{t_{min}\}, t_{exit}=min\{t_{max}\}\)
If \(t_{exit}<0\), the box is "behind" the ray, no intersections.
Else if \(t_{exit}\ge 0\) and \(t_{enter}<0\), the ray's origin is inside the box, have intersections.
If \(t_{enter}<t_{exit}\), the ray stays a while in the box, so they must intersect.
In Summary, ray and AABB intersect iff \(t_{enter}<t_{exit}\) and \(t_{exit} \ge 0\).