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 Plastic : public Material {
00029 public:
00030
00031 Plastic(Reference<Texture<Spectrum> > kd,
00032 Reference<Texture<Spectrum> > ks,
00033 Reference<Texture<float> > rough,
00034 Reference<Texture<float> > bump) {
00035 Kd = kd;
00036 Ks = ks;
00037 roughness = rough;
00038 bumpMap = bump;
00039 }
00040 BSDF *GetBSDF(const DifferentialGeometry &dgGeom,
00041 const DifferentialGeometry &dgShading) const;
00042 private:
00043
00044 Reference<Texture<Spectrum> > Kd, Ks;
00045 Reference<Texture<float> > roughness, bumpMap;
00046 };
00047
00048 BSDF *Plastic::GetBSDF(const DifferentialGeometry &dgGeom,
00049 const DifferentialGeometry &dgShading) const {
00050
00051 DifferentialGeometry dgs;
00052 if (bumpMap)
00053 Bump(bumpMap, dgGeom, dgShading, &dgs);
00054 else
00055 dgs = dgShading;
00056 BSDF *bsdf = BSDF_ALLOC(BSDF)(dgs, dgGeom.nn);
00057 Spectrum kd = Kd->Evaluate(dgs).Clamp();
00058 BxDF *diff = BSDF_ALLOC(Lambertian)(kd);
00059 Fresnel *fresnel =
00060 BSDF_ALLOC(FresnelDielectric)(1.5f, 1.f);
00061 Spectrum ks = Ks->Evaluate(dgs).Clamp();
00062 float rough = roughness->Evaluate(dgs);
00063 BxDF *spec = BSDF_ALLOC(Microfacet)(ks, fresnel,
00064 BSDF_ALLOC(Blinn)(1.f / rough));
00065 bsdf->Add(diff);
00066 bsdf->Add(spec);
00067 return bsdf;
00068 }
00069
00070 extern "C" DLLEXPORT Material * CreateMaterial(const Transform &xform,
00071 const TextureParams &mp) {
00072 Reference<Texture<Spectrum> > Kd = mp.GetSpectrumTexture("Kd", Spectrum(1.f));
00073 Reference<Texture<Spectrum> > Ks = mp.GetSpectrumTexture("Ks", Spectrum(1.f));
00074 Reference<Texture<float> > roughness = mp.GetFloatTexture("roughness", .1f);
00075 Reference<Texture<float> > bumpMap = mp.GetFloatTexture("bumpmap", 0.f);
00076 return new Plastic(Kd, Ks, roughness, bumpMap);
00077 }