00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #include "shinymetal.h"
00025 #include "bxdf.h"
00026 #include "fresnelconductor.h"
00027 #include "blinn.h"
00028 #include "anisotropic.h"
00029 #include "microfacet.h"
00030 #include "specularreflection.h"
00031 #include "paramset.h"
00032
00033 using namespace lux;
00034
00035
00036 BSDF *ShinyMetal::GetBSDF(const DifferentialGeometry &dgGeom, const DifferentialGeometry &dgShading, float) const {
00037
00038 DifferentialGeometry dgs;
00039 if (bumpMap)
00040 Bump(bumpMap, dgGeom, dgShading, &dgs);
00041 else
00042 dgs = dgShading;
00043 BSDF *bsdf = BSDF_ALLOC( BSDF)(dgs, dgGeom.nn);
00044 SWCSpectrum spec(Ks->Evaluate(dgs).Clamp());
00045 SWCSpectrum R(Kr->Evaluate(dgs).Clamp());
00046
00047 float u = nu->Evaluate(dgs);
00048 float v = nv->Evaluate(dgs);
00049
00050 MicrofacetDistribution *md;
00051 if(u == v)
00052 md = BSDF_ALLOC( Blinn)(1.f / u);
00053 else
00054 md = BSDF_ALLOC( Anisotropic)(1.f/u, 1.f/v);
00055
00056 SWCSpectrum k = 0.;
00057 Fresnel *frMf = BSDF_ALLOC( FresnelConductor)(FresnelApproxEta(spec), k);
00058 Fresnel *frSr = BSDF_ALLOC( FresnelConductor)(FresnelApproxEta(R), k);
00059 bsdf->Add(BSDF_ALLOC( Microfacet)(1., frMf, md));
00060 bsdf->Add(BSDF_ALLOC( SpecularReflection)(1., frSr));
00061 return bsdf;
00062 }
00063 Material* ShinyMetal::CreateMaterial(const Transform &xform,
00064 const TextureParams &mp) {
00065 boost::shared_ptr<Texture<Spectrum> > Kr = mp.GetSpectrumTexture("Kr", Spectrum(1.f));
00066 boost::shared_ptr<Texture<Spectrum> > Ks = mp.GetSpectrumTexture("Ks", Spectrum(1.f));
00067 boost::shared_ptr<Texture<float> > uroughness = mp.GetFloatTexture("uroughness", .1f);
00068 boost::shared_ptr<Texture<float> > vroughness = mp.GetFloatTexture("vroughness", .1f);
00069 boost::shared_ptr<Texture<float> > bumpMap = mp.GetFloatTexture("bumpmap", 0.f);
00070 return new ShinyMetal(Ks, uroughness, vroughness, Kr, bumpMap);
00071 }