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/subsurface.h"
00028 #include "textures/constant.h"
00029 #include "volume.h"
00030 #include "spectrum.h"
00031 #include "reflection.h"
00032 #include "texture.h"
00033 #include "paramset.h"
00034
00035
00036 BSDF *SubsurfaceMaterial::GetBSDF(const DifferentialGeometry &dgGeom,
00037 const DifferentialGeometry &dgShading, MemoryArena &arena) const {
00038
00039 DifferentialGeometry dgs;
00040 if (bumpMap)
00041 Bump(bumpMap, dgGeom, dgShading, &dgs);
00042 else
00043 dgs = dgShading;
00044 BSDF *bsdf = BSDF_ALLOC(arena, BSDF)(dgs, dgGeom.nn);
00045 Spectrum R = Kr->Evaluate(dgs).Clamp();
00046 float e = eta->Evaluate(dgs);
00047 if (!R.IsBlack())
00048 bsdf->Add(BSDF_ALLOC(arena, SpecularReflection)(R,
00049 BSDF_ALLOC(arena, FresnelDielectric)(1., e)));
00050 return bsdf;
00051 }
00052
00053
00054 BSSRDF *SubsurfaceMaterial::GetBSSRDF(const DifferentialGeometry &dgGeom,
00055 const DifferentialGeometry &dgShading, MemoryArena &arena) const {
00056 float e = eta->Evaluate(dgShading);
00057 return BSDF_ALLOC(arena, BSSRDF)(scale * sigma_a->Evaluate(dgShading),
00058 scale * sigma_prime_s->Evaluate(dgShading), e);
00059 }
00060
00061
00062 SubsurfaceMaterial *CreateSubsurfaceMaterial(const Transform &xform,
00063 const TextureParams &mp) {
00064 float sa_rgb[3] = { .0011f, .0024f, .014f }, sps_rgb[3] = { 2.55f, 3.21f, 3.77f };
00065 Spectrum sa = Spectrum::FromRGB(sa_rgb), sps = Spectrum::FromRGB(sps_rgb);
00066 string name = mp.FindString("name");
00067 bool found = GetVolumeScatteringProperties(name, &sa, &sps);
00068 if (name != "" && !found)
00069 Warning("Named material \"%s\" not found. Using defaults.", name.c_str());
00070 float scale = mp.FindFloat("scale", 1.f);
00071
00072 Reference<Texture<Spectrum> > sigma_a, sigma_prime_s;
00073 sigma_a = mp.GetSpectrumTexture("sigma_a", sa);
00074 sigma_prime_s = mp.GetSpectrumTexture("sigma_prime_s", sps);
00075 Reference<Texture<float> > ior = mp.GetFloatTexture("index", 1.3f);
00076 Reference<Texture<Spectrum> > Kr = mp.GetSpectrumTexture("Kr", Spectrum(1.f));
00077 Reference<Texture<float> > bumpMap = mp.GetFloatTexture("bumpmap", 0.f);
00078 return new SubsurfaceMaterial(scale, Kr, sigma_a, sigma_prime_s, ior, bumpMap);
00079 }
00080
00081