00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 #include "pbrt.h"
00026 #include "material.h"
00027
00028 class Matte : public Material {
00029 public:
00030
00031 Matte(Reference<Texture<Spectrum> > kd,
00032 Reference<Texture<float> > sig,
00033 Reference<Texture<float> > bump) {
00034 Kd = kd;
00035 sigma = sig;
00036 bumpMap = bump;
00037 }
00038 BSDF *GetBSDF(const DifferentialGeometry &dgGeom,
00039 const DifferentialGeometry &dgShading) const;
00040 private:
00041
00042 Reference<Texture<Spectrum> > Kd;
00043 Reference<Texture<float> > sigma, bumpMap;
00044 };
00045
00046 BSDF *Matte::GetBSDF(const DifferentialGeometry &dgGeom,
00047 const DifferentialGeometry &dgShading) const {
00048
00049 DifferentialGeometry dgs;
00050 if (bumpMap)
00051 Bump(bumpMap, dgGeom, dgShading, &dgs);
00052 else
00053 dgs = dgShading;
00054 BSDF *bsdf = BSDF_ALLOC(BSDF)(dgs, dgGeom.nn);
00055
00056 Spectrum r = Kd->Evaluate(dgs).Clamp();
00057 float sig = Clamp(sigma->Evaluate(dgs), 0.f, 90.f);
00058 if (sig == 0.)
00059 bsdf->Add(BSDF_ALLOC(Lambertian)(r));
00060 else
00061 bsdf->Add(BSDF_ALLOC(OrenNayar)(r, sig));
00062 return bsdf;
00063 return bsdf;
00064 }
00065 extern "C" DLLEXPORT Material * CreateMaterial(const Transform &xform,
00066 const TextureParams &mp) {
00067 Reference<Texture<Spectrum> > Kd = mp.GetSpectrumTexture("Kd", Spectrum(1.f));
00068 Reference<Texture<float> > sigma = mp.GetFloatTexture("sigma", 0.f);
00069 Reference<Texture<float> > bumpMap = mp.GetFloatTexture("bumpmap", 0.f);
00070 return new Matte(Kd, sigma, bumpMap);
00071 }