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 "glossy.h"
00027 #include "bxdf.h"
00028 #include "fresnelblend.h"
00029 #include "blinn.h"
00030 #include "anisotropic.h"
00031 #include "paramset.h"
00032 #include "dynload.h"
00033
00034 using namespace lux;
00035
00036
00037 BSDF *Glossy::GetBSDF(const TsPack *tspack, const DifferentialGeometry &dgGeom, const DifferentialGeometry &dgShading) const {
00038
00039 DifferentialGeometry dgs;
00040 if (bumpMap)
00041 Bump(bumpMap, dgGeom, dgShading, &dgs);
00042 else
00043 dgs = dgShading;
00044
00045 SWCSpectrum d = Kd->Evaluate(tspack, dgs).Clamp(0.f, 1.f);
00046 SWCSpectrum s = Ks->Evaluate(tspack, dgs);
00047 float i = index->Evaluate(tspack, dgs);
00048 if(i > 0.0) {
00049 const float ti = (i-1)/(i+1);
00050 s *= ti*ti;
00051 }
00052 s.Clamp(0.f, 1.f);
00053
00054 SWCSpectrum a = Ka->Evaluate(tspack, dgs).Clamp(0.f, 1.f);
00055
00056 float u = nu->Evaluate(tspack, dgs);
00057 float v = nv->Evaluate(tspack, dgs);
00058 float ld = depth->Evaluate(tspack, dgs);
00059
00060 BxDF *bxdf;
00061 if(u == v)
00062 bxdf = BSDF_ALLOC(tspack, FresnelBlend)(d, s, a, ld, BSDF_ALLOC(tspack, Blinn)(1.f/u));
00063 else
00064 bxdf = BSDF_ALLOC(tspack, FresnelBlend)(d, s, a, ld, BSDF_ALLOC(tspack, Anisotropic)(1.f/u, 1.f/v));
00065 SingleBSDF *bsdf = BSDF_ALLOC(tspack, SingleBSDF)(dgs, dgGeom.nn, bxdf);
00066
00067
00068 bsdf->SetCompositingParams(compParams);
00069
00070 return bsdf;
00071 }
00072 Material* Glossy::CreateMaterial(const Transform &xform,
00073 const TextureParams &mp) {
00074 boost::shared_ptr<Texture<SWCSpectrum> > Kd = mp.GetSWCSpectrumTexture("Kd", RGBColor(1.f));
00075 boost::shared_ptr<Texture<SWCSpectrum> > Ks = mp.GetSWCSpectrumTexture("Ks", RGBColor(1.f));
00076 boost::shared_ptr<Texture<SWCSpectrum> > Ka = mp.GetSWCSpectrumTexture("Ka", RGBColor(.0f));
00077 boost::shared_ptr<Texture<float> > i = mp.GetFloatTexture("index", 0.0f);
00078 boost::shared_ptr<Texture<float> > d = mp.GetFloatTexture("d", .0f);
00079 boost::shared_ptr<Texture<float> > uroughness = mp.GetFloatTexture("uroughness", .1f);
00080 boost::shared_ptr<Texture<float> > vroughness = mp.GetFloatTexture("vroughness", .1f);
00081 boost::shared_ptr<Texture<float> > bumpMap = mp.GetFloatTexture("bumpmap");
00082
00083
00084 CompositingParams cP;
00085 FindCompositingParams(mp, &cP);
00086
00087 return new Glossy(Kd, Ks, Ka, i, d, uroughness, vroughness, bumpMap, cP);
00088 }
00089
00090 static DynamicLoader::RegisterMaterial<Glossy> r("glossy");
00091 static DynamicLoader::RegisterMaterial<Glossy> r1("substrate");
00092 static DynamicLoader::RegisterMaterial<Glossy> r2("plastic");