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 "mattetranslucent.h"
00025 #include "bxdf.h"
00026 #include "lambertian.h"
00027 #include "orennayar.h"
00028 #include "paramset.h"
00029 #include "dynload.h"
00030
00031 using namespace lux;
00032
00033
00034 BSDF *MatteTranslucent::GetBSDF(const TsPack *tspack, const DifferentialGeometry &dgGeom,
00035 const DifferentialGeometry &dgShading) const {
00036
00037 DifferentialGeometry dgs;
00038 if (bumpMap)
00039 Bump(bumpMap, dgGeom, dgShading, &dgs);
00040 else
00041 dgs = dgShading;
00042
00043 MultiBSDF *bsdf = BSDF_ALLOC(tspack, MultiBSDF)(dgs, dgGeom.nn);
00044
00045 SWCSpectrum R = Kr->Evaluate(tspack, dgs).Clamp(0.f, 1.f);
00046 SWCSpectrum T = Kt->Evaluate(tspack, dgs).Clamp(0.f, 1.f);
00047 float sig = Clamp(sigma->Evaluate(tspack, dgs), 0.f, 90.f);
00048
00049 if (!R.Black()) {
00050 if (sig == 0.)
00051 bsdf->Add(BSDF_ALLOC(tspack, Lambertian)(R));
00052 else
00053 bsdf->Add(BSDF_ALLOC(tspack, OrenNayar)(R, sig));
00054 }
00055 if (!T.Black()) {
00056 BxDF *base;
00057 if (sig == 0.)
00058 base = BSDF_ALLOC(tspack, Lambertian)(T);
00059 else
00060 base = BSDF_ALLOC(tspack, OrenNayar)(T, sig);
00061 bsdf->Add(BSDF_ALLOC(tspack, BRDFToBTDF)(base));
00062 }
00063
00064
00065 bsdf->SetCompositingParams(compParams);
00066
00067 return bsdf;
00068 }
00069 Material* MatteTranslucent::CreateMaterial(const Transform &xform,
00070 const TextureParams &mp) {
00071 boost::shared_ptr<Texture<SWCSpectrum> > Kr = mp.GetSWCSpectrumTexture("Kr", RGBColor(1.f));
00072 boost::shared_ptr<Texture<SWCSpectrum> > Kt = mp.GetSWCSpectrumTexture("Kt", RGBColor(1.f));
00073 boost::shared_ptr<Texture<float> > sigma = mp.GetFloatTexture("sigma", 0.f);
00074 boost::shared_ptr<Texture<float> > bumpMap = mp.GetFloatTexture("bumpmap");
00075
00076
00077 CompositingParams cP;
00078 FindCompositingParams(mp, &cP);
00079
00080 return new MatteTranslucent(Kr, Kt, sigma, bumpMap, cP);
00081 }
00082
00083 static DynamicLoader::RegisterMaterial<MatteTranslucent> r("mattetranslucent");