PBRT_V2 总结记录 <111> Light::SHProject 和 PointLight::SHProject

1. 


void Light::SHProject(const Point &p, float pEpsilon, int lmax,
        const Scene *scene, bool computeLightVisibility, float time,
        RNG &rng, Spectrum *coeffs) const {
    for (int i = 0; i < SHTerms(lmax); ++i)
        coeffs[i] = 0.f;
    uint32_t ns = RoundUpPow2(nSamples);
    uint32_t scramble1D = rng.RandomUInt();
    uint32_t scramble2D[2] = { rng.RandomUInt(), rng.RandomUInt() };
    float *Ylm = ALLOCA(float, SHTerms(lmax));
    for (uint32_t i = 0; i < ns; ++i) {
        // Compute incident radiance sample from _light_, update SH _coeffs_
        float u[2], pdf;
        Sample02(i, scramble2D, u);
        LightSample lightSample(u[0], u[1], VanDerCorput(i, scramble1D));
        Vector wi;
        VisibilityTester vis;
        Spectrum Li = Sample_L(p, pEpsilon, lightSample, time, &wi, &pdf, &vis);
        if (!Li.IsBlack() && pdf > 0.f &&
            (!computeLightVisibility || vis.Unoccluded(scene))) {
            // Add light sample contribution to MC estimate of SH coefficients
            SHEvaluate(wi, lmax, Ylm);
            for (int j = 0; j < SHTerms(lmax); ++j)
                coeffs[j] += Li * Ylm[j] / (pdf * ns);
        }
    }
}

作用:

(这里的 Light::SHProject() method  是计算 SH 的系数,这个系数 就是 光源的 incident radiance function 在 SH basis up to the band l = lmax 上的系数。

默认是使用蒙特卡洛积分的方式去计算 ci, 这里要参考:《PBRT_V2 总结记录 <109> Spherical Harmonic (SH) Basis Functions

we will add methods to the various light sources to project their incident radiance functions into SH coefficients.

The Light::SHProject() method computes the SH coefficients that represent the incident
radiance function due to the light source in the SH basis up to the band l = lmax.
In
this case, the coefficients aren’t just scalars but are spectra; they are returned in the array
coeffs.
Here, we will define specific implementations of this method for point and infinite
area light sources as well as a general implementation that uses quasi-Monte Carlo
integration to compute SH coefficients at a point for the incident radiance function from
arbitrary light sources.

 

For general light sources without specialized implementations of the method, the default
implementation of Light::SHProject() uses quasi-Monte Carlo integration to estimate
the SH coefficient values.
The implementation here starts by computing random scramble
values for generating low-discrepancy samples using the routines from Section 7.4.3

and allocating a temporary array, Ylm, for holding values of the SH basis functions returned
by SHEvaluate().

 

 

2. 


void PointLight::SHProject(const Point &p, float pEpsilon, int lmax,
        const Scene *scene, bool computeLightVisibility, float time,
        RNG &rng, Spectrum *coeffs) const {
    for (int i = 0; i < SHTerms(lmax); ++i)
        coeffs[i] = 0.f;
    if (computeLightVisibility &&
        scene->IntersectP(Ray(p, Normalize(lightPos - p), pEpsilon,
                              Distance(lightPos, p), time)))
        return;
    // Project point light source to SH
    float *Ylm = ALLOCA(float, SHTerms(lmax));
    Vector wi = Normalize(lightPos - p);
    SHEvaluate(wi, lmax, Ylm);
    Spectrum Li = Intensity / DistanceSquared(lightPos, p);
    for (int i = 0; i < SHTerms(lmax); ++i)
        coeffs[i] = Li * Ylm[i];
}

作用:

After initializing the coefficients to zero, the PointLight::SHProject() method checks to
see if the point light source is visible from the given point. If not, the incident radiance is
zero and its work is done. Note that the user can indicate whether occlusion of geometric
objects in the scene should be ignored or not. For some applications, it’s useful to use the
unoccluded incident radiance function; for others, the effect of shadowing by geometry
should be incorporated.

Because point light sources are defined by a delta distribution, projecting their contribution
into SH with Equation (17.8) is straightforward. If we define ωi to be the normalized
direction from the point p to the point light source position pl and take advantage of the
fact that the point light is defined by a delta distribution
(recall Section 14.6.2), then the
integral turns into a single term to evaluate:

 

 

 

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值