PathIntegrator
// PathIntegrator Declarations
class PathIntegrator : public SurfaceIntegrator {
public:
// PathIntegrator Public Methods
Spectrum Li(const Scene *scene, const Renderer *renderer,
const RayDifferential &ray, const Intersection &isect,
const Sample *sample, RNG &rng, MemoryArena &arena) const;
void RequestSamples(Sampler *sampler, Sample *sample, const Scene *scene);
PathIntegrator(int md) { maxDepth = md; }
private:
// PathIntegrator Private Data
int maxDepth;
#define SAMPLE_DEPTH 3
LightSampleOffsets lightSampleOffsets[SAMPLE_DEPTH];
int lightNumOffset[SAMPLE_DEPTH];
BSDFSampleOffsets bsdfSampleOffsets[SAMPLE_DEPTH];
BSDFSampleOffsets pathSampleOffsets[SAMPLE_DEPTH];
};
类的作用:
(路径追踪)
1.
void PathIntegrator::RequestSamples(Sampler *sampler, Sample *sample,
const Scene *scene) {
for (int i = 0; i < SAMPLE_DEPTH; ++i) {
lightSampleOffsets[i] = LightSampleOffsets(1, sample);
lightNumOffset[i] = sample->Add1D(1);
bsdfSampleOffsets[i] = BSDFSampleOffsets(1, sample);
pathSampleOffsets[i] = BSDFSampleOffsets(1, sample);
}
}
作用:
(这里申请 SAMPLE_DEPTH 个采样数据,之后 超过 SAMPLE_DEPTH 就直接使用 随机数)
The integrator uses samples from the Sampler for sampling at the first SAMPLE_DEPTH
vertices of the path. After the first few bounces, the advantages of well-distributed sample
points are greatly reduced, and it switches to using uniform random numbers. The
integrator needs light and BSDF samples formultiple importance sampling for the direct
lighting calculation at each vertex of the path as well as a second set of BSDF samples for
sampling directions when generating the outgoing direction for finding the next vertex
of the path.
2.
Spectrum PathIntegrator::Li(const Scene *scene, const Renderer *renderer,
const RayDifferential &r, const Intersection &isect,
const Sample *sample, RNG &rng, MemoryArena &arena) const {
// Declare common path integration variables
Spectrum pathThroughput = 1., L = 0.;
RayDifferential ray(r);
bool specularBounce = false;
Intersection localIsect;
const Intersection *isectp = &isect;