1

I'm attempting to implement soft shadows in my raytracer. To do so, I plan to shoot multiple shadow rays from the intersection point towards the area light source. I'm aiming to use a spherical area light--this means I need to generate random points on the sphere for the direction vector of my ray (recall that ray's are specified with a origin and direction).

I've looked around for ways to generate a uniform distribution of random points on a sphere, but they seem a bit more complicated than what I'm looking for. Does anyone know of any methods for generating these points on a sphere? I believe my sphere area light source will simply be defined by its XYZ world coordinates, RGB color value, and r radius.

I was referenced this code from Graphics Gems III, page 126 (which is also the same method discussed here and here):

void random_unit_vector(double v[3]) {    
double theta = random_double(2.0 * PI);
double x = random_double(2.0) - 1.0;
double s = sqrt(1.0 - x * x);
v[0] = x;
v[1] = s * cos(theta);
v[2] = s * sin(theta);

}

This is fine and I understand this, but my sphere light source will be at some point in space specified by 3D X-Y-Z coordinates and a radius. I understand that the formula works for unit spheres, but I'm not sure how the formula accounts for the location of the sphere.

Thanks and I appreciate the help!

4

1 回答 1

1

您似乎混淆了生成方向的公式 - 即球体上的一个点 - 以及您试图生成方向 /toward/ 球体的事实。

您给出的公式均匀地采样随机射线:它在单位球体上找到一个 X、Y、Z 三元组,可以将其视为一个方向。

您实际尝试实现的是仍然生成一个方向(球体上的一个点),但它有利于指向一个球体的特定方向(或仅限于一个锥体:您从相机中心获得的锥体和球体光源的轮廓)。这样的事情可以通过两种方式完成:

  • 使用余弦波瓣对球形光源中心进行重要性采样。
  • 上述定义的锥体中的均匀采样。

在第一种情况下,公式在“全球照明指南”中给出:http://people.cs.kuleuven.be/~philip.dutre/GI/TotalCompendium.pdf 第 38 页第 21 页)。在第二个在这种情况下,你可以做一些拒绝抽样,但我很确定有一些封闭的公式。

最后,还有最后一个选项:您可以使用您的公式,将生成的 (X,Y,Z) 视为场景中的一个点,然后将其转换为球体的位置,并从您的相机制作一个指向矢量朝着它。但是,它会带来严重的问题:

  • 您将生成朝向球体光背面的矢量
  • 对于生成的方向集的 pdf,您将没有任何公式,您将在以后的蒙特卡洛积分中需要这些公式。
于 2012-12-09T07:53:10.440 回答