1. 程式人生 > >PBRT_V2 總結記錄 <42> MeasuredMaterial

PBRT_V2 總結記錄 <42> MeasuredMaterial

MeasuredMaterial 類

class MeasuredMaterial : public Material {
public:
    // MeasuredMaterial Public Methods
    MeasuredMaterial(const string &filename, Reference<Texture<float> > bump);
    BSDF *GetBSDF(const DifferentialGeometry &dgGeom,
                  const DifferentialGeometry &dgShading,
                  MemoryArena &arena) const;
private:
    // MeasuredMaterial Private Data
    KdTree<IrregIsotropicBRDFSample> *thetaPhiData;
    float *regularHalfangleData;
    uint32_t nThetaH, nThetaD, nPhiD;
    Reference<Texture<float> > bumpMap;
};

作用:

The MeasuredMaterial class supports two forms of measured isotropic BRDF data: irregular and regular, corresponding to the BxDFs implemented in Sections 8.6.1 and 8.6.2

1. 建構函式:

MeasuredMaterial(const string &filename, Reference<Texture<float> > bump);

作用:

(根據檔案的字尾(.brdf / .merl),來決定使用RegularHalfangleBRDF(.brdf ) 還是 IrregIsotropicBRDF(.merl), 主要是從檔案中讀取需要用到的資料,再整理好,傳入到 RegularHalfangleBRDF 還是 IrregIsotropicBRDF 中 )

For irregularly sampled BRDFs, the MeasuredMaterial constructor creates a kd-tree of the BRDF samples, using the BRDFRemap() function to map 4D pairs of directions to the 3D space that the IrregIsotropicBRDF uses for interpolation. For regularly sampled data, the table and its sampling resolution in the θh, θd, and φd dimensions are stored in corresponding member variables. (Only one of thetaPhiData or regularHalfangleData will be non-NULL.)

2. 

BSDF *MeasuredMaterial::GetBSDF(const DifferentialGeometry &dgGeom,                                 const DifferentialGeometry &dgShading,                                 MemoryArena &arena) const


BSDF *MeasuredMaterial::GetBSDF(const DifferentialGeometry &dgGeom,
                                const DifferentialGeometry &dgShading,
                                MemoryArena &arena) const {
    // Allocate _BSDF_, possibly doing bump mapping with _bumpMap_
    DifferentialGeometry dgs;
    if (bumpMap)
        Bump(bumpMap, dgGeom, dgShading, &dgs);
    else
        dgs = dgShading;
    BSDF *bsdf = BSDF_ALLOC(arena, BSDF)(dgs, dgGeom.nn);
    if (regularHalfangleData)
        bsdf->Add(BSDF_ALLOC(arena, RegularHalfangleBRDF)
            (regularHalfangleData, nThetaH, nThetaD, nPhiD));
    else if (thetaPhiData)
        bsdf->Add(BSDF_ALLOC(arena, IrregIsotropicBRDF)(thetaPhiData));
    return bsdf;
}

作用:

(先判斷是否使用了Bump,之後就直接判斷 regularHalfangleData 和 thetaPhiData 哪一個有資料,這兩個 東西都是在建構函式中進行賦值的,regularHalfangleData 有資料,就用 RegularHalfangleBRDF, thetaPhiData 有資料就用 IrregIsotropicBRDF)

Once the data is in memory, the GetBSDF() method’s task is straightforward. After the usual bump-mapping computation, it just has to allocate the appropriate BxDF implementation based on whether this instance of the MeasuredMaterial has regularly or irregularly sampled data.