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 "roughglass.h"
00025 #include "bxdf.h"
00026 #include "fresneldielectric.h"
00027 #include "microfacet.h"
00028 #include "blinn.h"
00029 #include "anisotropic.h"
00030 #include "paramset.h"
00031 #include "dynload.h"
00032
00033 using namespace lux;
00034
00035
00036 BSDF *RoughGlass::GetBSDF(const TsPack *tspack, const DifferentialGeometry &dgGeom, const DifferentialGeometry &dgShading) const {
00037
00038 DifferentialGeometry dgs;
00039 if (bumpMap)
00040 Bump(bumpMap, dgGeom, dgShading, &dgs);
00041 else
00042 dgs = dgShading;
00043
00044 float ior = index->Evaluate(tspack, dgs);
00045 float cb = cauchyb->Evaluate(tspack, dgs);
00046 MultiBSDF *bsdf = BSDF_ALLOC(tspack, MultiBSDF)(dgs, dgGeom.nn, ior);
00047
00048 SWCSpectrum R = Kr->Evaluate(tspack, dgs).Clamp(0.f, 1.f);
00049 SWCSpectrum T = Kt->Evaluate(tspack, dgs).Clamp(0.f, 1.f);
00050 float urough = uroughness->Evaluate(tspack, dgs);
00051 float vrough = vroughness->Evaluate(tspack, dgs);
00052 MicrofacetDistribution *md;
00053
00054 if(urough == vrough)
00055 md = BSDF_ALLOC(tspack, Blinn)(1.f / urough);
00056 else
00057 md = BSDF_ALLOC(tspack, Anisotropic)(1.f / urough, 1.f / vrough);
00058 if (!R.Black()) {
00059 Fresnel *fresnel = BSDF_ALLOC(tspack, FresnelDielectric)(1.f, ior, cb);
00060 bsdf->Add(BSDF_ALLOC(tspack, Microfacet)(R, fresnel, md));
00061 }
00062 if (!T.Black()) {
00063 Fresnel *fresnel = BSDF_ALLOC(tspack, FresnelDielectricComplement)(1.f, ior, cb);
00064 bsdf->Add(BSDF_ALLOC(tspack, BRDFToBTDF)(BSDF_ALLOC(tspack, Microfacet)(T, fresnel, md), 1.f, ior, cb));
00065 }
00066
00067
00068 bsdf->SetCompositingParams(compParams);
00069
00070 return bsdf;
00071 }
00072 Material* RoughGlass::CreateMaterial(const Transform &xform,
00073 const TextureParams &mp) {
00074 boost::shared_ptr<Texture<SWCSpectrum> > Kr = mp.GetSWCSpectrumTexture("Kr", RGBColor(1.f));
00075 boost::shared_ptr<Texture<SWCSpectrum> > Kt = mp.GetSWCSpectrumTexture("Kt", RGBColor(1.f));
00076 boost::shared_ptr<Texture<float> > uroughness = mp.GetFloatTexture("uroughness", .001f);
00077 boost::shared_ptr<Texture<float> > vroughness = mp.GetFloatTexture("vroughness", .001f);
00078 boost::shared_ptr<Texture<float> > index = mp.GetFloatTexture("index", 1.5f);
00079 boost::shared_ptr<Texture<float> > cbf = mp.GetFloatTexture("cauchyb", 0.f);
00080 boost::shared_ptr<Texture<float> > bumpMap = mp.GetFloatTexture("bumpmap");
00081
00082
00083 CompositingParams cP;
00084 FindCompositingParams(mp, &cP);
00085
00086 return new RoughGlass(Kr, Kt, uroughness, vroughness, index, cbf, bumpMap, cP);
00087 }
00088
00089 static DynamicLoader::RegisterMaterial<RoughGlass> r("roughglass");