MatteMaterial 类
// MatteMaterial Declarations
class MatteMaterial : public Material {
public:
// MatteMaterial Public Methods
MatteMaterial(Reference<Texture<Spectrum> > kd,
Reference<Texture<float> > sig,
Reference<Texture<float> > bump)
: Kd(kd), sigma(sig), bumpMap(bump) {
}
BSDF *GetBSDF(const DifferentialGeometry &dgGeom,
const DifferentialGeometry &dgShading,
MemoryArena &arena) const;
private:
// MatteMaterial Private Data
Reference<Texture<Spectrum> > Kd;
Reference<Texture<float> > sigma, bumpMap;
};
类的作用:
(Kd表示的 漫反射值,sigma 表示的是粗糙值(如果是0的话,使用 Lambertion BRDF,不是的话,使用 OrenNayar BRDF),还有一个可选的参数bumpMap,偏移法线用的,这些参数都是一张 Texture)
The MatteMaterial material is the simplest material in pbrt and describes a purely diffuse surface. It is parameterized
by a spectral diffuse reflection value, Kd, and a scalar roughness value, sigma. If sigma
has the value zero at the point on a surface, MatteMaterial returns a Lambertian BRDF;
otherwise, the OrenNayar model is used. Like all of the other Material implementations in
this chapter, it also takes an optional scalar texture that defines an offset function over the
surface. If non-NULL, this texture is used to compute a shading normal at each point based
on the function it defines.
1.
BSDF *GetBSDF(const DifferentialGeometry &dgGeom,
const DifferentialGeometry &dgShading,
MemoryArena &arena) const;
BSDF *MatteMaterial::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);
// Evaluate textures for _MatteMaterial_ material and allocate BRDF
Spectrum r = Kd->Evaluate(dgs).Clamp();
float sig = Clamp(sigma->Evaluate(dgs), 0.f, 90.f);
if (!r.IsBlack()) {
if (sig == 0.)
bsdf->Add(BSDF_ALLOC(arena, Lambertian)(r));
else
bsdf->Add(BSDF_ALLOC(arena, OrenNayar)(r, sig));
}
return bsdf;
}
作用:
(如果有 bump map 的话,就利用 bump 来计算 交点的新的法线出来,之后 传入 dgs 到 Kd 和 sigma Texture 中 ,计算出 交点在图片中的值,得到值之后,就可以判断使用 Lambertion 还是 OrenNayar )
If a bump map was provided to the MatteMaterial constructor, the Material::Bump()
method is called to calculate the shading normal at the point. This method will be defined
in the next section.
Next, the Textures that give the values of the diffuse reflection coefficient and the roughness
are evaluated; these may return constant values, look up values from image maps, or
do complex procedural shading calculations to compute these values (the texture evaluation
process is the subject of Chapter 10). Given these values, all that needs to be done is
to allocate a BSDF and the appropriate BRDF component using the BSDF memory allocation
macros and return the result. Because Textures may return negative values or values
otherwise outside of the expected range, these values are clamped before they are passed
to the BRDF constructor.