我正在为 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 /讲座/37raytracing.pdf
如果我理解正确而不是像标准反射那样跟踪单条光线,我必须在随机方向上跟踪 n 条光线。我如何为每条射线获得这个随机方向?我如何生成这些样本?

我将首先按顺序编写以下辅助方法:
// 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);
Run Code Online (Sandbox Code Playgroud)
一旦你开始工作,你可能希望根据实际的 BRDF 对象重新设计你的实现,如果你想扩展你的跟踪器来支持折射,这将在一定程度上组织逻辑并帮助你。