我正在为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 :(得分:4)
我首先按顺序编写以下辅助方法:
// 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对象重新设计你的实现,这将有点组织逻辑,如果你想扩展你的跟踪器以支持折射,可以帮助你下线。 p>