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