光线追踪光泽反射:采样光线方向

Ray tracing glossy reflection: sampling ray direction

我正在为 iPad 编写光线追踪器。现在我正在尝试为对象添加光泽反射。我该如何实施?我在线阅读了一些文档:

http://www.cs.cmu.edu/afs/cs/academic/class/15462-s09/www/lec/13/lec13.pdf http://www.cs.cornell.edu/courses/cs4620/2012fa/lectures/37raytracing.pdf

如果我理解正确,而不是像标准反射那样追踪单条射线,我必须在随机方向上追踪 n 条射线。 如何获得每条光线的随机方向?我如何生成这些样本?

  • 镜面反射是指入射方向与表面法线的夹角等于出射方向与表面法线的夹角
  • 漫反射是指出射方向的角度随机均匀分布在表面法线的半球上。
  • 您可以将光泽反射视为这两个极端之间的光谱,其中该光谱上的位置(或光泽度)由范围为 0 到 1 的 "glossiness" 因子定义。
  • 对于漫反射或光泽反射,您需要能够从可能的反射方向分布中随机生成一条光线,然后跟随它。
  • 然后,取很多样本并取平均结果。
  • 因此,对于光泽反射,关键是反射光线的分布以镜面反射方向为中心。光线分布越宽,光泽度扩散得越多。

我将从按顺序编写以下辅助方法开始:

// get a random point on the surface of a unit sphere
public Vector getRandomPointOnUnitSphere(); 

// get a Ray (with origin and direction) that points towards a 
// random location on the unit hemisphere defined by the given normal
public Ray getRandomRayInHemisphere(Normal n); 

// you probably already have something like this
public Ray getSpecularReflectedRayInHemisphere(Normal n, Ray incomingRay);

// get a Ray whose direction is perturbed by a random amount (up to the
// glossiness factor) from the specular reflection direction
public Ray getGlossyReflectedRayInHemisphere(Normal n, Ray incomingRay, double glossiness);

一旦你完成这项工作,你可能想要根据实际的 BRDF 对象重新设计你的实现,这将在一定程度上组织逻辑,并在你想要扩展你的跟踪器以支持折射时帮助你完成。