PBRT_V2 总结记录 DistantLight 补充(Sample_L)


Spectrum DistantLight::Sample_L(const Scene *scene,
        const LightSample &ls, float u1, float u2, float time,
        Ray *ray, Normal *Ns, float *pdf) const {
    // Choose point on disk oriented toward infinite light direction
    Point worldCenter;
    float worldRadius;
    scene->WorldBound().BoundingSphere(&worldCenter, &worldRadius);
    Vector v1, v2;
    CoordinateSystem(lightDir, &v1, &v2);
    float d1, d2;
    ConcentricSampleDisk(ls.uPos[0], ls.uPos[1], &d1, &d2);
    Point Pdisk = worldCenter + worldRadius * (d1 * v1 + d2 * v2);

    // Set ray origin and direction for infinite light ray
    *ray = Ray(Pdisk + worldRadius * lightDir, -lightDir, 0.f, INFINITY,
               time);
    *Ns = (Normal)ray->d;

    *pdf = 1.f / (M_PI * worldRadius * worldRadius);
    return L;
}

作用:

(其实也是生成一条射线,但是射线的生成方式与 其他的光源不一样而已,ray的原点 通过场景的包围球中心进行偏移包围球半径那么多来确定。)

Figure 14.9: To sample an outgoing ray direction for a distant light source, the DistantLight::
Sample_L() method finds the disk oriented in the light’s direction that is large enough so that the
entire scene can be intersected by rays leaving the disk in the light’s direction. Ray origins are sampled
uniformly by area on this disk, and ray directions are given directly by the light’s direction.

The desired property is that rays intersect points in the scene that are illuminated by
the distant light with uniform probability. One way to do this is to construct a disk
that has the same radius as the scene’s bounding sphere and has a normal that is oriented
with the light’s direction, and then choose a random point on this disk, using the
ConcentricSampleDisk() function
(Figure 14.9). Once this point has been chosen, if the
point is displaced along the light’s direction by the scene’s bounding sphere radius and
used as the origin of the light ray, the ray origin will be outside the bounding sphere of
the scene, but will intersect it.


This is a valid sampling approach, since by construction it has nonzero probability of
sampling all incident rays into the sphere due to the directional light. The area component
of the sampling density is uniform and therefore equal to the reciprocal of the area
of the disk that was sampled. The directional density is given by a delta distribution based
on the light’s direction; therefore, it isn’t included in the returned PDF value.

细节1

    // Choose point on disk oriented toward infinite light direction
    Point worldCenter;
    float worldRadius;
    scene->WorldBound().BoundingSphere(&worldCenter, &worldRadius);
    Vector v1, v2;
    CoordinateSystem(lightDir, &v1, &v2);
    float d1, d2;
    ConcentricSampleDisk(ls.uPos[0], ls.uPos[1], &d1, &d2);
    Point Pdisk = worldCenter + worldRadius * (d1 * v1 + d2 * v2);

作用:

(看上面的代码可以知道,

scene->WorldBound().BoundingSphere(&worldCenter, &worldRadius); 计算 场景中所有物体的 总的包围球 的 球中心和 球半径,是基于世界坐标的,

CoordinateSystem(lightDir, &v1, &v2); 基于 lightDir 建立一个坐标系,lightDir,v1,v2

ConcentricSampleDisk(ls.uPos[0], ls.uPos[1], &d1, &d2);, 利用 uPos 均匀采样 一个 圆盘,返回 d1,d2 坐标

 Point Pdisk = worldCenter + worldRadius * (d1 * v1 + d2 * v2);, 利用上面的信息,得到圆盘中的一个随机点。)

Choosing the point on the oriented disk is a simple application of vector algebra. We
construct a coordinate system with two vectors perpendicular to the disk’s normal (the
light’s direction); see Figure 14.10. Given a random point on the canonical unit disk,
computing the offsets from the disk’s center with respect to its coordinate vectors gives
the corresponding point.

Figure 14.10: Given sample points (d1, d2) on the canonical unit disk, points on an arbitrarily oriented
and sized disk with normal n can be found by computing an arbitrary coordinate system (v1, v2, n),
and then computing points on the disk with the offset d1v1
+ d2v2 from the disk’s center.

细节2

*ray = Ray(Pdisk + worldRadius * lightDir, -lightDir, 0.f, INFINITY,
               time);

作用:

(pdisk 是场景球包围盒的 中心点,那么ray 的原点就是 球中心点 沿 lightDir 进行 偏移 worldRadius ,保证 ray 的原点在 包围球的外面,这样可以保存ray 与 球进行相交)

Once this point has been chosen, if the
point is displaced along the light’s direction by the scene’s bounding sphere radius and
used as the origin of the light ray, the ray origin will be outside the bounding sphere of
the scene, but will intersect it.

猜你喜欢

转载自blog.csdn.net/aa20274270/article/details/84971633