1. 程式人生 > >PBRT_V2 總結記錄 DiffuseAreaLight::Sample_f 和 DiffuseAreaLight::Pdf

PBRT_V2 總結記錄 DiffuseAreaLight::Sample_f 和 DiffuseAreaLight::Pdf


Spectrum DiffuseAreaLight::Sample_L(const Point &p, float pEpsilon,
        const LightSample &ls, float time, Vector *wi, float *pdf,
        VisibilityTester *visibility) const {
    PBRT_AREA_LIGHT_STARTED_SAMPLE();
    Normal ns;
    Point ps = shapeSet->Sample(p, ls, &ns);
    *wi = Normalize(ps - p);
    *pdf = shapeSet->Pdf(p, *wi);
    visibility->SetSegment(p, pEpsilon, ps, 1e-3f, time);
    Spectrum Ls = L(ps, ns, -*wi);
    PBRT_AREA_LIGHT_FINISHED_SAMPLE();
    return Ls;
}

作用:

(其實 DiffuseAreaLight 的 Sample 主要的還是呼叫 ShapeSet的Sample 函式來輔助實現,這裡就是呼叫 ShapeSet的Sample 函式 返回 一個 在 Shape的取樣點 ps,利用 ps 和 引數 p 就可以計算出 wi,pdf的也是直接呼叫 ShapeSet的Pdf函式計算出來的)

Given shape sampling methods, the DiffuseAreaLight::Sample_L() methods are quite
straightforward. Most of the hard work is done by the Shapes, and the DiffuseAreaLight
mostly just needs to compute emitted radiance values.

Recall that the shape or shapes
that define the light are stored in a ShapeSet that handles sampling from collections of
shapes.

 

 

float DiffuseAreaLight::Pdf(const Point &p, const Vector &wi) const {
    return shapeSet->Pdf(p, wi);
}

作用:

The variant of Shape::Pdf() called here is the one that returns a density with respect to
solid angle, so the value from the light’s Pdf() method can be returned directly.

 

 

Spectrum DiffuseAreaLight::Sample_L(const Scene *scene,
        const LightSample &ls, float u1, float u2, float time,
        Ray *ray, Normal *Ns, float *pdf) const {
    PBRT_AREA_LIGHT_STARTED_SAMPLE();
    Point org = shapeSet->Sample(ls, Ns);
    Vector dir = UniformSampleSphere(u1, u2);
    if (Dot(dir, *Ns) < 0.) dir *= -1.f;
    *ray = Ray(org, dir, 1e-3f, INFINITY, time);
    *pdf = shapeSet->Pdf(org) * INV_TWOPI;
    Spectrum Ls = L(org, *Ns, dir);
    PBRT_AREA_LIGHT_FINISHED_SAMPLE();
    return Ls;
}

作用:

(這個Sample_L 利用取樣點生成一條 ray,這條Ray 是從 Light 發出的 ,那麼這裡就是先通過 shapeSet->Sample 在 shape 取樣出一個點,這個點作用 射線的 原點,那麼這條射線的方向就是 通過 u1,u2 隨機生成出來的,最後這個函式的返回值 這個取樣點 所產生的 Spectrum 值  )

The method for sampling a ray leaving an area light is also easily implemented in terms of
the shape sampling methods. The first variant of Shape::Sample() is used to find the ray
origin, sampled fromsome density over the surface. Because the DiffuseAreaLight emits
uniform radiance in all directions, a uniformdistribution of directions is used for the ray
direction.
Because radiance is only emitted from the side of the light the surface normal
lies on, if the sampled direction is in the opposite hemisphere than the surface normal, it
is flipped to lie in the same hemisphere so that samples aren’t wasted in directions where
there is no emission.

 

The PDF for sampling the ray is the product of the PDF for sampling its origin with
respect to area on the surface with the PDF for sampling a uniform direction on the
hemisphere, 1/(2π).