00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026 #include "stdafx.h"
00027 #include "materials/translucent.h"
00028 #include "spectrum.h"
00029 #include "reflection.h"
00030 #include "paramset.h"
00031 #include "texture.h"
00032
00033
00034 BSDF *TranslucentMaterial::GetBSDF(const DifferentialGeometry &dgGeom, const DifferentialGeometry &dgShading, MemoryArena &arena) const {
00035 float ior = 1.5f;
00036 DifferentialGeometry dgs;
00037 if (bumpMap)
00038 Bump(bumpMap, dgGeom, dgShading, &dgs);
00039 else
00040 dgs = dgShading;
00041 BSDF *bsdf = BSDF_ALLOC(arena, BSDF)(dgs, dgGeom.nn, ior);
00042
00043 Spectrum r = reflect->Evaluate(dgs).Clamp();
00044 Spectrum t = transmit->Evaluate(dgs).Clamp();
00045 if (r.IsBlack() && t.IsBlack()) return bsdf;
00046
00047 Spectrum kd = Kd->Evaluate(dgs).Clamp();
00048 if (!kd.IsBlack()) {
00049 if (!r.IsBlack()) bsdf->Add(BSDF_ALLOC(arena, Lambertian)(r * kd));
00050 if (!t.IsBlack()) bsdf->Add(BSDF_ALLOC(arena, BRDFToBTDF)(BSDF_ALLOC(arena, Lambertian)(t * kd)));
00051 }
00052 Spectrum ks = Ks->Evaluate(dgs).Clamp();
00053 if (!ks.IsBlack()) {
00054 float rough = roughness->Evaluate(dgs);
00055 if (!r.IsBlack()) {
00056 Fresnel *fresnel = BSDF_ALLOC(arena, FresnelDielectric)(ior, 1.f);
00057 bsdf->Add(BSDF_ALLOC(arena, Microfacet)(r * ks, fresnel,
00058 BSDF_ALLOC(arena, Blinn)(1.f / rough)));
00059 }
00060 if (!t.IsBlack()) {
00061 Fresnel *fresnel = BSDF_ALLOC(arena, FresnelDielectric)(ior, 1.f);
00062 bsdf->Add(BSDF_ALLOC(arena, BRDFToBTDF)(BSDF_ALLOC(arena, Microfacet)(t * ks, fresnel,
00063 BSDF_ALLOC(arena, Blinn)(1.f / rough))));
00064 }
00065 }
00066 return bsdf;
00067 }
00068
00069
00070 TranslucentMaterial *CreateTranslucentMaterial(const Transform &xform,
00071 const TextureParams &mp) {
00072 Reference<Texture<Spectrum> > Kd = mp.GetSpectrumTexture("Kd", Spectrum(0.25f));
00073 Reference<Texture<Spectrum> > Ks = mp.GetSpectrumTexture("Ks", Spectrum(0.25f));
00074 Reference<Texture<Spectrum> > reflect = mp.GetSpectrumTexture("reflect", Spectrum(0.5f));
00075 Reference<Texture<Spectrum> > transmit = mp.GetSpectrumTexture("transmit", Spectrum(0.5f));
00076 Reference<Texture<float> > roughness = mp.GetFloatTexture("roughness", .1f);
00077 Reference<Texture<float> > bumpMap = mp.GetFloatTexture("bumpmap", 0.f);
00078 return new TranslucentMaterial(Kd, Ks, roughness, reflect, transmit, bumpMap);
00079 }
00080
00081