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.