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/metal.h"
00028 #include "reflection.h"
00029 #include "paramset.h"
00030 #include "texture.h"
00031
00032
00033 MetalMaterial::MetalMaterial(Reference<Texture<Spectrum> > et,
00034 Reference<Texture<Spectrum> > kk, Reference<Texture<float> > rough,
00035 Reference<Texture<float> > bump) {
00036 eta = et;
00037 k = kk;
00038 roughness = rough;
00039 bumpMap = bump;
00040 }
00041
00042
00043 BSDF *MetalMaterial::GetBSDF(const DifferentialGeometry &dgGeom,
00044 const DifferentialGeometry &dgShading, MemoryArena &arena) const {
00045
00046 DifferentialGeometry dgs;
00047 if (bumpMap)
00048 Bump(bumpMap, dgGeom, dgShading, &dgs);
00049 else
00050 dgs = dgShading;
00051 BSDF *bsdf = BSDF_ALLOC(arena, BSDF)(dgs, dgGeom.nn);
00052
00053 float rough = roughness->Evaluate(dgs);
00054 MicrofacetDistribution *md = BSDF_ALLOC(arena, Blinn)(1.f / rough);
00055
00056 Fresnel *frMf = BSDF_ALLOC(arena, FresnelConductor)(eta->Evaluate(dgs),
00057 k->Evaluate(dgs));
00058 bsdf->Add(BSDF_ALLOC(arena, Microfacet)(1., frMf, md));
00059 return bsdf;
00060 }
00061
00062
00063 const int CopperSamples = 56;
00064 const float CopperWavelengths[CopperSamples] = {
00065 298.7570554, 302.4004341, 306.1337728, 309.960445, 313.8839949, 317.9081487, 322.036826,
00066 326.2741526, 330.6244747, 335.092373, 339.6826795, 344.4004944, 349.2512056, 354.2405086,
00067 359.374429, 364.6593471, 370.1020239, 375.7096303, 381.4897785, 387.4505563, 393.6005651,
00068 399.9489613, 406.5055016, 413.2805933, 420.2853492, 427.5316483, 435.0322035, 442.8006357,
00069 450.8515564, 459.2006593, 467.8648226, 476.8622231, 486.2124627, 495.936712, 506.0578694,
00070 516.6007417, 527.5922468, 539.0616435, 551.0407911, 563.5644455, 576.6705953, 590.4008476,
00071 604.8008683, 619.92089, 635.8162974, 652.5483053, 670.1847459, 688.8009889, 708.4810171,
00072 729.3186941, 751.4192606, 774.9011125, 799.8979226, 826.5611867, 855.0632966, 885.6012714 };
00073
00074 const float CopperN[CopperSamples] = {
00075 1.400313, 1.38, 1.358438, 1.34, 1.329063, 1.325, 1.3325, 1.34, 1.334375, 1.325,
00076 1.317812, 1.31, 1.300313, 1.29, 1.281563, 1.27, 1.249062, 1.225, 1.2, 1.18, 1.174375, 1.175,
00077 1.1775, 1.18, 1.178125, 1.175, 1.172812, 1.17, 1.165312, 1.16, 1.155312, 1.15, 1.142812, 1.135,
00078 1.131562, 1.12, 1.092437, 1.04, 0.950375, 0.826, 0.645875, 0.468, 0.35125, 0.272, 0.230813, 0.214,
00079 0.20925, 0.213, 0.21625, 0.223, 0.2365, 0.25, 0.254188, 0.26, 0.28, 0.3
00080 };
00081
00082
00083
00084 const float CopperK[CopperSamples] = {
00085 1.662125, 1.687, 1.703313, 1.72, 1.744563, 1.77, 1.791625, 1.81, 1.822125, 1.834,
00086 1.85175, 1.872, 1.89425, 1.916, 1.931688, 1.95, 1.972438, 2.015, 2.121562, 2.21, 2.177188, 2.13,
00087 2.160063, 2.21, 2.249938, 2.289, 2.326, 2.362, 2.397625, 2.433, 2.469187, 2.504, 2.535875, 2.564,
00088 2.589625, 2.605, 2.595562, 2.583, 2.5765, 2.599, 2.678062, 2.809, 3.01075, 3.24, 3.458187, 3.67,
00089 3.863125, 4.05, 4.239563, 4.43, 4.619563, 4.817, 5.034125, 5.26, 5.485625, 5.717 };
00090 MetalMaterial *CreateMetalMaterial(const Transform &xform, const TextureParams &mp) {
00091 static Spectrum copperN = Spectrum::FromSampled(CopperWavelengths, CopperN, CopperSamples);
00092 Reference<Texture<Spectrum> > eta = mp.GetSpectrumTexture("eta", copperN);
00093
00094 static Spectrum copperK = Spectrum::FromSampled(CopperWavelengths, CopperK, CopperSamples);
00095 Reference<Texture<Spectrum> > k = mp.GetSpectrumTexture("k", copperK);
00096
00097 Reference<Texture<float> > roughness = mp.GetFloatTexture("roughness", .01f);
00098 Reference<Texture<float> > bumpMap = mp.GetFloatTexture("bumpmap", 0.f);
00099 return new MetalMaterial(eta, k, roughness, bumpMap);
00100 }
00101
00102