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
00032 using namespace lux;
00033
00034
00035 BSDF *RoughGlass::GetBSDF(const DifferentialGeometry &dgGeom, const DifferentialGeometry &dgShading, float u) 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 float cb = cauchyb->Evaluate(dgs);
00045 BSDF *bsdf = BSDF_ALLOC( BSDF)(dgs, dgGeom.nn, ior);
00046
00047 SWCSpectrum R(Kr->Evaluate(dgs).Clamp(0.f, 1.f));
00048 SWCSpectrum T(Kt->Evaluate(dgs).Clamp(0.f, 1.f));
00049 float urough = uroughness->Evaluate(dgs);
00050 float vrough = vroughness->Evaluate(dgs);
00051 if (!R.Black()) {
00052 Fresnel *fresnel = BSDF_ALLOC( FresnelDielectric)(1.f, ior);
00053 if(urough == vrough)
00054 bsdf->Add(BSDF_ALLOC( Microfacet)(R, fresnel,
00055 BSDF_ALLOC( Blinn)(1.f / urough)));
00056 else
00057 bsdf->Add(BSDF_ALLOC( Microfacet)(R, fresnel,
00058 BSDF_ALLOC( Anisotropic)(1.f / urough, 1.f / vrough)));
00059 }
00060 if (!T.Black()) {
00061 Fresnel *fresnel = BSDF_ALLOC( FresnelDielectricComplement)(1.f, ior, cb);
00062
00063 if(urough == vrough)
00064 bsdf->Add(BSDF_ALLOC( BRDFToBTDF)(BSDF_ALLOC( Microfacet)(T, fresnel,
00065 BSDF_ALLOC( Blinn)(1.f / urough))));
00066 else
00067 bsdf->Add(BSDF_ALLOC( BRDFToBTDF)(BSDF_ALLOC( Microfacet)(T, fresnel,
00068 BSDF_ALLOC( Anisotropic)(1.f / urough, 1.f / vrough))));
00069 }
00070 return bsdf;
00071 }
00072 Material* RoughGlass::CreateMaterial(const Transform &xform,
00073 const TextureParams &mp) {
00074 boost::shared_ptr<Texture<Spectrum> > Kr = mp.GetSpectrumTexture("Kr", Spectrum(1.f));
00075 boost::shared_ptr<Texture<Spectrum> > Kt = mp.GetSpectrumTexture("Kt", Spectrum(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", 0.f);
00081 return new RoughGlass(Kr, Kt, uroughness, vroughness, index, cbf, bumpMap);
00082 }