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 "translucent.h"
00025 #include "bxdf.h"
00026 #include "lambertian.h"
00027 #include "fresneldielectric.h"
00028 #include "microfacet.h"
00029 #include "blinn.h"
00030 #include "paramset.h"
00031
00032 using namespace lux;
00033
00034
00035 BSDF *Translucent::GetBSDF(const DifferentialGeometry &dgGeom, const DifferentialGeometry &dgShading) const {
00036
00037 DifferentialGeometry dgs;
00038 if (bumpMap)
00039 Bump(bumpMap, dgGeom, dgShading, &dgs);
00040 else
00041 dgs = dgShading;
00042
00043 float ior = index->Evaluate(dgs);
00044 BSDF *bsdf = BSDF_ALLOC( BSDF)(dgs, dgGeom.nn, ior);
00045
00046 SWCSpectrum r(reflect->Evaluate(dgs).Clamp(0.f, 1.f));
00047 SWCSpectrum t(transmit->Evaluate(dgs).Clamp(0.f, 1.f));
00048 if (r.Black() && t.Black()) return bsdf;
00049
00050 SWCSpectrum kd(Kd->Evaluate(dgs).Clamp());
00051 if (!kd.Black()) {
00052 if (!r.Black()) bsdf->Add(BSDF_ALLOC( Lambertian)(r * kd));
00053 if (!t.Black()) bsdf->Add(BSDF_ALLOC( BRDFToBTDF)(BSDF_ALLOC( Lambertian)(t * kd)));
00054 }
00055 SWCSpectrum ks(Ks->Evaluate(dgs).Clamp());
00056 if (!ks.Black()) {
00057 float rough = roughness->Evaluate(dgs);
00058 if (!r.Black()) {
00059
00060 Fresnel *fresnel = BSDF_ALLOC( FresnelDielectric)(1.f, ior);
00061 bsdf->Add(BSDF_ALLOC( Microfacet)(r * ks, fresnel,
00062 BSDF_ALLOC( Blinn)(1.f / rough)));
00063 }
00064 if (!t.Black()) {
00065
00066 Fresnel *fresnel = BSDF_ALLOC( FresnelDielectric)(1.f, ior);
00067 bsdf->Add(BSDF_ALLOC( BRDFToBTDF)(BSDF_ALLOC( Microfacet)(t * ks, fresnel,
00068 BSDF_ALLOC( Blinn)(1.f / rough))));
00069 }
00070 }
00071 return bsdf;
00072 }
00073 Material* Translucent::CreateMaterial(const Transform &xform,
00074 const TextureParams &mp) {
00075 boost::shared_ptr<Texture<Spectrum> > Kd = mp.GetSpectrumTexture("Kd", Spectrum(1.f));
00076 boost::shared_ptr<Texture<Spectrum> > Ks = mp.GetSpectrumTexture("Ks", Spectrum(1.f));
00077 boost::shared_ptr<Texture<Spectrum> > reflect = mp.GetSpectrumTexture("reflect", Spectrum(0.5f));
00078 boost::shared_ptr<Texture<Spectrum> > transmit = mp.GetSpectrumTexture("transmit", Spectrum(0.5f));
00079 boost::shared_ptr<Texture<float> > roughness = mp.GetFloatTexture("roughness", .1f);
00080
00081 boost::shared_ptr<Texture<float> > index = mp.GetFloatTexture("index", 1.5f);
00082 boost::shared_ptr<Texture<float> > bumpMap = mp.GetFloatTexture("bumpmap", 0.f);
00083 return new Translucent(Kd, Ks, roughness, reflect, transmit, index, bumpMap);
00084 }