1. 程式人生 > >PBRT_V2 總結記錄 BxDF::rho

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