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π).

猜你喜欢

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