PBRT_V2 总结记录 <85> BSDFSample 和 BSDFSampleOffsets 和 BSDF::Sample_f() 和BSDF:Pdf

本文详细介绍了PBRT_V2中BSDFSample、BSDFSampleOffsets结构及其在BSDF::Sample_f()和BSDF::Pdf方法中的应用。BSDFSample用于封装随机变量,BSDFSampleOffsets保存样本的一维和二维数组索引,BSDF::Sample_f()负责选择并采样BxDF,而BSDF::Pdf计算与特定标志相关的BxDF的PDF平均值。
摘要由CSDN通过智能技术生成

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
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值