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