wahn/rs_pbrt

Implement UberMaterial

Closed this issue · 1 comments

wahn commented

I'm looking for more PBRT test scenes and stumbled upon Benedikt Bitterli's Rendering Resources. The first test scene already needs a new material, which I haven't implemented yet, the UberMaterial:

pbrt

> rg uber bathroom
bathroom/scene.pbrt
20:	MakeNamedMaterial "Rug" "string type" [ "uber" ] "rgb Ks" [ 0.000000 0.000000 0.000000 ] "texture Kd" [ "Texture01" ] "texture opacity" [ "Texture02" ] 
29:	MakeNamedMaterial "BulbGlass" "string type" [ "uber" ] "rgb Kd" [ 0.000000 0.000000 0.000000 ] "rgb Ks" [ 0.000000 0.000000 0.000000 ] "rgb opacity" [ 0.000000 0.000000 0.000000 ] 

On the C++ side the class to convert to Rust looks like this:

// UberMaterial Declarations
class UberMaterial : public Material {
  public:
    UberMaterial(const std::shared_ptr<Texture<Spectrum>> &Kd,
                 const std::shared_ptr<Texture<Spectrum>> &Ks,
                 const std::shared_ptr<Texture<Spectrum>> &Kr,
                 const std::shared_ptr<Texture<Spectrum>> &Kt,
                 const std::shared_ptr<Texture<Float>> &roughness,
                 const std::shared_ptr<Texture<Float>> &roughnessu,
                 const std::shared_ptr<Texture<Float>> &roughnessv,
                 const std::shared_ptr<Texture<Spectrum>> &opacity,
                 const std::shared_ptr<Texture<Float>> &eta,
                 const std::shared_ptr<Texture<Float>> &bumpMap,
                 bool remapRoughness)
        : Kd(Kd),
          Ks(Ks),
          Kr(Kr),
          Kt(Kt),
          opacity(opacity),
          roughness(roughness),
          roughnessu(roughnessu),
          roughnessv(roughnessv),
          eta(eta),
          bumpMap(bumpMap),
          remapRoughness(remapRoughness) {}

    void ComputeScatteringFunctions(SurfaceInteraction *si, MemoryArena &arena,
                                    TransportMode mode,
                                    bool allowMultipleLobes) const;

  private:
    // UberMaterial Private Data
    std::shared_ptr<Texture<Spectrum>> Kd, Ks, Kr, Kt, opacity;
    std::shared_ptr<Texture<Float>> roughness, roughnessu, roughnessv, eta,
        bumpMap;
    bool remapRoughness;
};

UberMaterial *CreateUberMaterial(const TextureParams &mp);

This shouldn't be too much work:

> wc ~/git/github/pbrt-v3/src/materials/uber.h
  89  322 3285 /home/jan/git/github/pbrt-v3/src/materials/uber.h
> wc ~/git/github/pbrt-v3/src/materials/uber.cpp 
 129  479 5190 /home/jan/git/github/pbrt-v3/src/materials/uber.cpp
wahn commented

Commit b3ad5e4 resolves the issue:

pbrt