BSDFSample
struct BSDFSample {
// BSDFSample Public Methods
BSDFSample(float up0, float up1, float ucomp) {
Assert(up0 >= 0.f && up0 < 1.f);
Assert(up1 >= 0.f && up1 < 1.f);
Assert(ucomp >= 0.f && ucomp < 1.f);
uDir[0] = up0;
uDir[1] = up1;
uComponent = ucomp;
}
BSDFSample(RNG &rng) {
uDir[0] = rng.RandomFloat();
uDir[1] = rng.RandomFloat();
uComponent = rng.RandomFloat();
}
BSDFSample(const Sample *sample, const BSDFSampleOffsets &offsets, uint32_t num);
BSDFSample() { }
float uDir[2], uComponent;
};
作用:
(BSDF::Sample_f() 需要3个随机数,1个用来 在 BSDF中 随机选择 某一个BxDF,2个用来 传入 BxDF->Sample_f 的函数中,因为BSDF::Sample_f 是随机采样,所以会随机采样其中1个 它自己保存的BxDF,那么这3个随机数 直接 封装到 BSDFSample 中。)
The BSDF::Sample_f() method takes three random variables to drive this process; one is
used to select among the BxDFs, and the other two to pass along to the particular sampling
method chosen. These sample values are encapsulated by the BSDFSample structure.
1. float uDir[2], uComponent;
作用:
uDir[2] : 在 BSDF::Sample_f() 中,是直接给 BxDF::Sample_f() 使用。
uComponent :这个就是用来 随机采样 BSDF 中某一个 BxDF 用的。
2. 构造函数
BSDFSample(float up0, float up1, float ucomp) {
Assert(up0 >= 0.f && up0 < 1.f);
Assert(up1 >= 0.f && up1 < 1.f);
Assert(ucomp >= 0.f && ucomp < 1.f);
uDir[0] = up0;
uDir[1] = up1;
uComponent = ucomp;
}
BSDFSample(RNG &rng) {
uDir[0] = rng.RandomFloat();
uDir[1] = rng.RandomFloat();
uComponent = rng.RandomFloat();
}
作用:
(BSDFSample 的构造函数,1个构造函数是直接传入3个随机数,1个构造函数是直接 通过 rng 来生成随机数)
The BSDFSample can be initialized by directly passing in values for the three samples.
Alternatively, a convenience method takes a pseudo-random number generator and initializes
the samples using it.
3. 常用的构造函数
BSDFSample::BSDFSample(const Sample *sample,
const BSDFSampleOffsets &offsets, uint32_t n) {
Assert(n < sample->n2D[offsets.dirOffset]);
Assert(n < sample->n1D[offsets.componentOffset]);
uDir[0] = sample->twoD[offsets.dirOffset][2*n];
uDir[1] = sample->twoD[offsets.dirOffset][2*n+1];
uComponent = sample->oneD[offsets.componentOffset][n];
Assert(uDir[0] >= 0.f && uDir[0] < 1.f);
Assert(uDir[1] >= 0.f && uDir[1] < 1.f);
Assert(uComponent >= 0.f && uComponent < 1.f);
}
作用:
(通过一个BSDFSampleOffsets 结构体来进行 初始化 BSDFSample , 这里简单理解就是,BSDFSampleOffsets 保存了 sample 中 oneD,twoD 数组的索引,也就是说 BSDFSample 是用过 BSDFSampleOffsets 结构体,取 sample 中的oneD,twoD的随机数据)
Most commonly, we’ll want to initialize the BSDFSample with values from a Sample object
filled in by the Sampler. The BSDFSampleOffsets structure helps with the bookkeeping for
this case.
BSDFSampleOffsets
struct BSDFSampleOffsets {
BSDFSampleOffsets() { }
BSDFSampleOffsets(int count, Sample *sample);
int nSamples, componentOffset, dirOffse