Ray Tracing
1.光栅化存在的问题:soft shadows, glossy reflection, Indirect illumination。
2.Basic ray racing
Three ideas about light rays;
- Light travels in straight lines
- Light rays do not “collide” with each other if they cross
- Light rays travel from the light sources to the eye(but the physics is invariant under path reversal )(光路可逆)
3.Ray Casting
连接人眼与像素,连线与场景内物体相交(只与最近的相交,已经解决了深度测试的问题),将交点与光源相连,看连线是否被遮挡,得知该点是否会被照亮/是否在阴影中
4.Recursive(Whitted-Style)Ray Tracing
连接人眼与像素,连线与场景内最近的物体相交得到交点,考虑在该交点处的无能量损失的反射,以及折射。每个反射点、折射点都与光源进行连线,计算每个点的色素值,最后都加到最开始的像素值(理解光路可逆的含义)。
考虑能量损失,区分shadow rays、secondary rays等等
技术问题:
Ray-Surface Intersection(求光线与物体表面的交点):
Ray equation:
$$
r(t) = o + td
$$
o是光源起点,d是光线传播方向
Ray Intersection With Triangle:先光与平面求交,再判断交点是否在三角形内部
求交点的方程出处:平面法线与平面内任何一条线垂直
Moller Trumbore Algorithm可以直接写出方法是用重心坐标表示交点
如何加速ray tracing
Bounding Volumes:用框将物体包围,所以一条光线如何碰不到包围核,那就更碰不到核内物体。经常使用Axis-Aligned Bounding Box