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 "glass.h"
00025 #include "bxdf.h"
00026 #include "specularreflection.h"
00027 #include "speculartransmission.h"
00028 #include "fresneldielectric.h"
00029 #include "paramset.h"
00030
00031 using namespace lux;
00032
00033
00034 BSDF *Glass::GetBSDF(const DifferentialGeometry &dgGeom, const DifferentialGeometry &dgShading, float u) const {
00035
00036 DifferentialGeometry dgs;
00037 if (bumpMap)
00038 Bump(bumpMap, dgGeom, dgShading, &dgs);
00039 else
00040 dgs = dgShading;
00041
00042 float ior = index->Evaluate(dgs);
00043 float cb = cauchyb->Evaluate(dgs);
00044 BSDF *bsdf = BSDF_ALLOC( BSDF)(dgs, dgGeom.nn, ior);
00045
00046 SWCSpectrum R(Kr->Evaluate(dgs).Clamp(0.f, 1.f));
00047 SWCSpectrum T(Kt->Evaluate(dgs).Clamp(0.f, 1.f));
00048 if (!R.Black()) {
00049 if (architectural)
00050 bsdf->Add(BSDF_ALLOC( ArchitecturalReflection)(R,
00051 BSDF_ALLOC( FresnelDielectric)(1., ior)));
00052 else
00053 bsdf->Add(BSDF_ALLOC( SpecularReflection)(R,
00054 BSDF_ALLOC( FresnelDielectric)(1., ior)));
00055 }
00056 if (!T.Black())
00057 bsdf->Add(BSDF_ALLOC( SpecularTransmission)(T, 1., ior, cb, architectural));
00058 return bsdf;
00059 }
00060 Material* Glass::CreateMaterial(const Transform &xform,
00061 const TextureParams &mp) {
00062 boost::shared_ptr<Texture<Spectrum> > Kr = mp.GetSpectrumTexture("Kr", Spectrum(1.f));
00063 boost::shared_ptr<Texture<Spectrum> > Kt = mp.GetSpectrumTexture("Kt", Spectrum(1.f));
00064 boost::shared_ptr<Texture<float> > index = mp.GetFloatTexture("index", 1.5f);
00065 boost::shared_ptr<Texture<float> > cbf = mp.GetFloatTexture("cauchyb", 0.f);
00066 bool archi = mp.FindBool("architectural", false);
00067 boost::shared_ptr<Texture<float> > bumpMap = mp.GetFloatTexture("bumpmap", 0.f);
00068 return new Glass(Kr, Kt, index, cbf, archi, bumpMap);
00069 }