PBRT_V2 总结记录 BxDF::rho

Spectrum BxDF::rho(const Vector &w, int nSamples,
                   const float *samples) const {
    Spectrum r = 0.;
    for (int i = 0; i < nSamples; ++i) {
        // Estimate one term of $\rho_\roman{hd}$
        Vector wi;
        float pdf = 0.f;
        Spectrum f = Sample_f(w, &wi, samples[2*i], samples[2*i+1], &pdf);
        if (pdf > 0.) r += f * AbsCosTheta(wi) / pdf;
    }
    return r / float(nSamples);
}

作用:

(在《PBRT_V2 总结记录 BxDF 和 BRDFToBTDF 和 ScaledBxDF》中提及过,上面的rho的作用就是:入射的wi 贡献了多少 光给wo,但是这里的 phd 的返回值的意思就是,对于所有的入射wi,一共贡献了多少光给wo这个方向上,那么这里 就是演示怎么使用 Monte Carlo estimate 来计算 一个积分,并且也可以看到Sample_f 的用法)

Recall from Section 8.1.1 that BxDF::rho() method implementations take two additional
parameters, nSamples and samples; here, we can see how they are used for Monte Carlo
sampling. For BxDF implementations that can’t compute the reflectance in closed form,
the nSamples parameter specifies the number ofMonte Carlo samples to take, and sample
values themselves are provided in the samples array. The samples array should have
2*nSamples entries, where the first two values provide the first 2D sample value and so
forth.

The generic BxDF::rho() method computes a Monte Carlo estimate of this value for any
BxDF, using the provided samples and taking advantage of the BxDF’s sampling method to
compute the estimate with importance sampling.

Actually evaluating the estimator is a matter of sampling the reflection function’s distribution,
finding its value, and dividing it by the value of the PDF. Each term of the
estimator

is easily evaluated. The BxDF’s Sample_f() method returns all of ωj , p(ωj ) and the value
of fr(ωo, ωj ). The only tricky part is when p(ωj ) = 0, which must be detected here,
since otherwise a division by zero would place an infinite value in r.


Spectrum BxDF::rho(int nSamples, const float *samples1,
                   const float *samples2) const {
    Spectrum r = 0.;
    for (int i = 0; i < nSamples; ++i) {
        // Estimate one term of $\rho_\roman{hh}$
        Vector wo, wi;
        wo = UniformSampleHemisphere(samples1[2*i], samples1[2*i+1]);
        float pdf_o = INV_TWOPI, pdf_i = 0.f;
        Spectrum f = Sample_f(wo, &wi, samples2[2*i], samples2[2*i+1], &pdf_i);
        if (pdf_i > 0.)
            r += f * AbsCosTheta(wi) * AbsCosTheta(wo) / (pdf_o * pdf_i);
    }
    return r / (M_PI*nSamples);
}

作用:

(在《PBRT_V2 总结记录 BxDF 和 BRDFToBTDF 和 ScaledBxDF》中提及过,上面的rho的作用就是:ρhh 返回的是一个常量,描述的就是,一个表面总有反射了百分之多少的光)

The hemispherical–hemispherical reflectance can be estimated similarly. Given

two vectors, ω‘and ω’‘, must be sampled for each term of the estimate

猜你喜欢

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