PBRT_V2 总结记录 Sampling Shapes

Shape


// Shape Declarations
class Shape : public ReferenceCounted {
public:
    // Shape Interface
    Shape(const Transform *o2w, const Transform *w2o, bool ro);
    virtual ~Shape();

    virtual Point Sample(float u1, float u2, Normal *Ns) const {
        Severe("Unimplemented Shape::Sample() method called");
        return Point();
    }
    virtual float Pdf(const Point &Pshape) const {
        return 1.f / Area();
    }
    virtual Point Sample(const Point &P, float u1, float u2,
                         Normal *Ns) const {
        return Sample(u1, u2, Ns);
    }
    virtual float Pdf(const Point &p, const Vector &wi) const;

};

1. 

virtual Point Sample(float u1, float u2, Normal *Ns) const {
    Severe("Unimplemented Shape::Sample() method called");
    return Point();
}

作用:

(有两个sample 函数,这个是第一个,这个sample主要的作用就是利用 参数 u1,u2,在shape的表面上随机采样一个点,返回出去,并且 保存这个点的法线在参数 Ns 上)

There are two shape sampling methods, both named Shape::Sample(). The first chooses
points on the surface using some sampling distribution with respect to surface area on
the shape and returns the position and surface normal of the point chosen.

2. 

    virtual float Pdf(const Point &Pshape) const {
        return 1.f / Area();
    }

作用:

(pdf 是 1/Area )

The Shapes that implement this method will almost always sample uniformly by area on
their surface. Therefore, we will provide a default implementation of the Shape::Pdf()
method corresponding to this sampling method that returns the corresponding PDF:
the reciprocal of the surface area.

3. 

    virtual Point Sample(const Point &P, float u1, float u2,
                         Normal *Ns) const {
        return Sample(u1, u2, Ns);
    }

作用:

(这个是第二个 sample 函数,这个函数的主要作用就是,传入一个 点 P,这个P点是要被area light 照亮的,  那么 这个函数实现的就是,计算出这个area light 的哪一些区域 相对于 点P 是可视的,那么就在这些区域进行采样,返回采样点)

The second shape sampling method also takes the point from which the surface of the
shape is being integrated over. This method is particularly useful for lighting, since the
caller can pass in the point to be lit and allow shape implementations to ensure that
they only sample the portion of the shape that is potentially visible from that point.

The default implementation ignores the additional point and calls the earlier sampling
method.

4. 


float Shape::Pdf(const Point &p, const Vector &wi) const {
    // Intersect sample ray with area light geometry
    DifferentialGeometry dgLight;
    Ray ray(p, wi, 1e-3f);
    ray.depth = -1; // temporary hack to ignore alpha mask
    float thit, rayEpsilon;
    if (!Intersect(ray, &thit, &rayEpsilon, &dgLight)) return 0.;

    // Convert light sample weight to solid angle measure
    float pdf = DistanceSquared(p, ray(thit)) /
                (AbsDot(dgLight.nn, -wi) * Area());
    if (isinf(pdf)) pdf = 0.f;
    return pdf;
}

作用:

(这个pdf其实主要的作用就是,用面积表示的的pdf ( 1/ Area ),换成用 立体角来 表示 (1/dw),那么他们之间的关系就是 , 所有 1/dw 就是 这个公式的倒数,而且,这里计算的pdf 是会考虑到 点P的可视区域,也就是说,这个pdf 其实可以理解为 可视区域的 pdf)

Unlike the first Shape sampling method, which generates points on the shape according
to a probability density with respect to surface area on the shape, the second one uses a
density with respect to solid angle from the point p
. This difference stems(起源) from the fact
that the area light sampling routines evaluate the direct lighting integral as an integral
over directions from p—expressing these sampling densities with respect to solid angle
at p is more convenient. Therefore, the standard implementation of the second Pdf()

method here transforms the density from one defined over area to one defined over solid
angle from p.

细节

a.

    DifferentialGeometry dgLight;
    Ray ray(p, wi, 1e-3f);
    ray.depth = -1; // temporary hack to ignore alpha mask
    float thit, rayEpsilon;
    if (!Intersect(ray, &thit, &rayEpsilon, &dgLight)) return 0.;

作用:

(先发射线来判断 ray(p, wi) 与 shape 是否相关,如果不是相关的话,就默认pdf 是0,)

Given a point p and direction ωi, the Pdf() method determines if the ray (p, ωi) intersects
the shape. If the ray doesn’t intersect the shape at all, the probability that the shape
would have chosen the direction ωi can be assumed to be zero
(a well-written sampling
algorithm wouldn’t generate such a sample, and in any case the light’s contribution will
be zero for such directions, so using a zero probability density is fine).
Note that this ray intersection test is only between the ray and the single shape that is the
area light source. The rest of the scene geometry is ignored, thus the intersection test is
reasonably efficient.

b.

float pdf = DistanceSquared(p, ray(thit)) / (AbsDot(dgLight.nn, -wi) * Area());

作用:

这里其实就是公式:

,立体角与面积的关系,用立体角来表示 pdf。

To compute the value of the PDF with respect to solid angle from p, this method starts by
computing the PDF with respect to surface area. Conversion from a density with respect
to area to a density with respect to solid angle requires division by the factor

where θo is the angle between the ray from the point on the light to the receiving point p
and the light’s surface normal, and r^2 is the distance between the point on the light and
the point being shaded

猜你喜欢

转载自blog.csdn.net/aa20274270/article/details/84989926
今日推荐