1. 程式人生 > >PBRT_V2 總結記錄 PointLight 補充(Sample_L) 和 SpotLight 補充(Sample_L)

PBRT_V2 總結記錄 PointLight 補充(Sample_L) 和 SpotLight 補充(Sample_L)

1. 

Spectrum PointLight::Sample_L(const Scene *scene, const LightSample &ls,
        float u1, float u2, float time, Ray *ray, Normal *Ns,
        float *pdf) const {
    *ray = Ray(lightPos, UniformSampleSphere(ls.uPos[0], ls.uPos[1]),
               0.f, INFINITY, time);
    *Ns = (Normal)ray->d;
    *pdf = UniformSpherePdf();
    return Intensity;
}

Spectrum Sample_L(const Scene *scene, const LightSample &ls, float u1,
                      float u2, float time, Ray *ray, Normal *Ns, float *pdf) const;

作用:

(點光源的 Sample_L 根據取樣點發出一條射線,取樣分佈是 UniformSampleSphere,均勻的球分佈,pdf 是 均勻球分佈 pdf )

The sampling method for generating rays leaving point lights is also straightforward.
The origin of the ray must be the light’s position; this part of the density is described
with a delta distribution. Directions are uniformly sampled over the sphere, and the
overall sampling density is the product of these two densities. As usual, we’ll ignore
the delta distribution that is in the actual PDF because it is canceled out by a (missing)
corresponding delta term in the radiance value in the Spectrum returned by the sampling
routine.

 

2. 

Spectrum SpotLight::Sample_L(const Scene *scene, const LightSample &ls,
        float u1, float u2, float time, Ray *ray, Normal *Ns,
        float *pdf) const {
    Vector v = UniformSampleCone(ls.uPos[0], ls.uPos[1], cosTotalWidth);
    *ray = Ray(lightPos, LightToWorld(v), 0.f, INFINITY, time);
    *Ns = (Normal)ray->d;
    *pdf = UniformConePdf(cosTotalWidth);
    return Intensity * Falloff(ray->d);
}

Vector UniformSampleCone(float u1, float u2, float costhetamax) {
    float costheta = (1.f - u1) + u1 * costhetamax;
    float sintheta = sqrtf(1.f - costheta*costheta);
    float phi = u2 * 2.f * M_PI;
    return Vector(cosf(phi) * sintheta, sinf(phi) * sintheta, costheta);
}

float UniformConePdf(float cosThetaMax) {
    return 1.f / (2.f * M_PI * (1.f - cosThetaMax));
}

Spectrum Sample_L(const Scene *scene, const LightSample &ls,
        float u1, float u2, float time, Ray *ray, Normal *Ns, float *pdf) const;

作用:

(SpotLight 發出的射線是 處於某一個圓錐體 (cosTotalWidth) 內部的, 取樣分佈也是 在這個圓錐體內進行取樣分佈,具體的數學原理可以參考 PBRT P712)

we will sample from a uniform distribution over the cone of directions in which the light casts
illumination. Although the sampling distribution does not try to account for the falloff
toward the edges of the beam, this is only a minor shortcoming in practice.