PlasticMaterial 类
class PlasticMaterial : public Material {
public:
// PlasticMaterial Public Methods
PlasticMaterial(Reference<Texture<Spectrum> > kd,
Reference<Texture<Spectrum> > ks,
Reference<Texture<float> > rough,
Reference<Texture<float> > bump)
: Kd(kd), Ks(ks), roughness(rough), bumpMap(bump) {
}
BSDF *GetBSDF(const DifferentialGeometry &dgGeom,
const DifferentialGeometry &dgShading,
MemoryArena &arena) const;
private:
// PlasticMaterial Private Data
Reference<Texture<Spectrum> > Kd, Ks;
Reference<Texture<float> > roughness, bumpMap;
};
作用:
(塑料材质,是混合 diffuse 和 glossy 来 模拟塑料的,Kd 和 Ks主要是控制 diffuse 和 glossy的反射率,而roughness控制的是高光的大小)
Plastic(塑料) can be modeled as a mixture of a diffuse and glossy scattering function with
parameters controlling the particular colors and specular highlight size. The parameters
to PlasticMaterial are two reflectivities, Kd and Ks, which respectively control the
amounts of diffuse reflection and glossy specular reflection. Next is a roughness parameter
(which ranges from zero to one) that determines the size of the specular highlight; the
higher the roughness value, the larger the highlight.
1. BSDF *GetBSDF(const DifferentialGeometry &dgGeom,
const DifferentialGeometry &dgShading,
MemoryArena &arena) const;
BSDF *PlasticMaterial::GetBSDF(const DifferentialGeometry &dgGeom,
const DifferentialGeometry &dgShading,
MemoryArena &arena) const {
// Allocate _BSDF_, possibly doing bump mapping with _bumpMap_
DifferentialGeometry dgs;
if (bumpMap)
Bump(bumpMap, dgGeom, dgShading, &dgs);
else
dgs = dgShading;
BSDF *bsdf = BSDF_ALLOC(arena, BSDF)(dgs, dgGeom.nn);
Spectrum kd = Kd->Evaluate(dgs).Clamp();
if (!kd.IsBlack()) {
BxDF *diff = BSDF_ALLOC(arena, Lambertian)(kd);
bsdf->Add(diff);
}
Spectrum ks = Ks->Evaluate(dgs).Clamp();
if (!ks.IsBlack()) {
Fresnel *fresnel = BSDF_ALLOC(arena, FresnelDielectric)(1.5f, 1.f);
float rough = roughness->Evaluate(dgs);
BxDF *spec = BSDF_ALLOC(arena, Microfacet)
(ks, fresnel, BSDF_ALLOC(arena, Blinn)(1.f / rough));
bsdf->Add(spec);
}
return bsdf;
}
作用:
(先判断是否使用 Bump,再判断相交点是否有Diffuse,有的话就直接添加 Lambertion,之后再判断是否有Glossy,有的话就直接添加 Microfacet,用Blinn作为 D函数,FresnelDielectric 作为F函数)