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
00026 #include "stdafx.h"
00027 #include "materials/plastic.h"
00028 #include "spectrum.h"
00029 #include "reflection.h"
00030 #include "paramset.h"
00031 #include "texture.h"
00032
00033
00034 BSDF *PlasticMaterial::GetBSDF(const DifferentialGeometry &dgGeom,
00035 const DifferentialGeometry &dgShading,
00036 MemoryArena &arena) const {
00037
00038 DifferentialGeometry dgs;
00039 if (bumpMap)
00040 Bump(bumpMap, dgGeom, dgShading, &dgs);
00041 else
00042 dgs = dgShading;
00043 BSDF *bsdf = BSDF_ALLOC(arena, BSDF)(dgs, dgGeom.nn);
00044 Spectrum kd = Kd->Evaluate(dgs).Clamp();
00045 BxDF *diff = BSDF_ALLOC(arena, Lambertian)(kd);
00046 Fresnel *fresnel = BSDF_ALLOC(arena, FresnelDielectric)(1.5f, 1.f);
00047 Spectrum ks = Ks->Evaluate(dgs).Clamp();
00048 float rough = roughness->Evaluate(dgs);
00049 BxDF *spec = BSDF_ALLOC(arena, Microfacet)
00050 (ks, fresnel, BSDF_ALLOC(arena, Blinn)(1.f / rough));
00051 bsdf->Add(diff);
00052 bsdf->Add(spec);
00053 return bsdf;
00054 }
00055
00056
00057 PlasticMaterial *CreatePlasticMaterial(const Transform &xform,
00058 const TextureParams &mp) {
00059 Reference<Texture<Spectrum> > Kd = mp.GetSpectrumTexture("Kd", Spectrum(0.25f));
00060 Reference<Texture<Spectrum> > Ks = mp.GetSpectrumTexture("Ks", Spectrum(0.25f));
00061 Reference<Texture<float> > roughness = mp.GetFloatTexture("roughness", .1f);
00062 Reference<Texture<float> > bumpMap = mp.GetFloatTexture("bumpmap", 0.f);
00063 return new PlasticMaterial(Kd, Ks, roughness, bumpMap);
00064 }
00065
00066