1. 程式人生 > >PBRT_V2 總結記錄 DistantLight 補充(Sample_L)

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.