PBRT_V2 总结记录 Texture 和 ConstantTexture 和 ScaleTexture 和 MixTexture 和 BilerpTexture

Texture 类

template <typename T> class Texture : public ReferenceCounted {
public:
    // Texture Interface
    virtual T Evaluate(const DifferentialGeometry &) const = 0;
    virtual ~Texture() { }
};

作用:

(Texture 是一个 模板类,evaluation 函数返回的值得类型就可以多样化,目前 pbrt 中,evaluation 返回的类型主要是 float 和 Spectrum)

Texture is a template class parameterized by the return type of its evaluation function.
This design makes it possible to reuse almost all of the texturing code between textures
that return different types.
pbrt currently uses only float and Spectrum textures.

1. virtual T Evaluate(const DifferentialGeometry &) const = 0;

作用:

(Evaluate 函数 主要的就是 利用 1个 DifferentialGeometry  作为参数,计算图片中 一个 模板类型T的值)

The key to Texture’s interface is its evaluation function; it returns a value of the template
type T.
The only information it has access to in order to evaluate its value is the
DifferentialGeometry at the point being shaded. Different textures in this chapter will
use different parts of this structure to drive their evaluation.

扫描二维码关注公众号,回复: 4154421 查看本文章

ConstantTexture 类

template <typename T> class ConstantTexture : public Texture<T> {
public:
    // ConstantTexture Public Methods
    ConstantTexture(const T &v) { value = v; }
    T Evaluate(const DifferentialGeometry &) const {
        return value;
    }
private:
    T value;
};

类的作用:

(Evaluate 计算出来都是同一个值,存在这个 ConstantTexture ,可以把材质的所有的参数都可以当做 Texture来处理)

ConstantTexture returns the same value no matter where it is evaluated. Because it
represents a constant function, it can be accurately reconstructed with any sampling
rate and therefore needs no antialiasing. Although this texture is trivial, it is actually
quite useful. By providing this class, all parameters to all Materials can be represented
as Textures, whether they are spatially varying or not.
For example, a red diffuse object
will have a ConstantTexture that always returns red as the diffuse color of the material.
This way, the shading system always evaluates a texture to get the surface properties at
a point, avoiding the need for separate textured and nontextured versions of materials.

ScaleTexture 类

template <typename T1, typename T2>
class ScaleTexture : public Texture<T2> {
public:
    // ScaleTexture Public Methods
    ScaleTexture(Reference<Texture<T1> > t1, Reference<Texture<T2> > t2)
        : tex1(t1), tex2(t2) { }
    T2 Evaluate(const DifferentialGeometry &dg) const {
        return tex1->Evaluate(dg) * tex2->Evaluate(dg);
    }
private:
    Reference<Texture<T1> > tex1;
    Reference<Texture<T2> > tex2;
};

类的作用:

(ScaleTexture 取两个Texture,计算它们的乘积)

The ScaleTexture takes two textures and returns the product of their values when evaluated.

MixTexture类

template <typename T> class MixTexture : public Texture<T> {
public:
    // MixTexture Public Methods
    MixTexture(Reference<Texture<T> > t1, Reference<Texture<T> > t2,
               Reference<Texture<float> > amt)
        : tex1(t1), tex2(t2), amount(amt) { }
    T Evaluate(const DifferentialGeometry &dg) const {
        T t1 = tex1->Evaluate(dg), t2 = tex2->Evaluate(dg);
        float amt = amount->Evaluate(dg);
        return (1.f - amt) * t1 + amt * t2;
    }
private:
    Reference<Texture<T> > tex1, tex2;
    Reference<Texture<float> > amount;
};

类的作用:

(MixTexture 需要3个Texture,主要的作用就是利用第3张Texture来混合前两张Texture)

The MixTexture class is a more general variation of ScaleTexture. It takes three textures
as input: two may be of any type, and the third must return a floating-point value. The
floating-point texture is then used to linearly interpolate between the two other textures.

Note that a ConstantTexture could be used for the floating-point value to achieve a
uniform blend, or a more complex Texture to blend in a spatially nonuniform way.

BilerpTexture 类

template <typename T> class BilerpTexture : public Texture<T> {
public:
    // BilerpTexture Public Methods
    BilerpTexture(TextureMapping2D *m, const T &t00, const T &t01,
                  const T &t10, const T &t11)
        : mapping(m), v00(t00), v01(t01), v10(t10), v11(t11) {
    }
    ~BilerpTexture() {
        delete mapping;
    }
    T Evaluate(const DifferentialGeometry &dg) const {
        float s, t, dsdx, dtdx, dsdy, dtdy;
        mapping->Map(dg, &s, &t, &dsdx, &dtdx, &dsdy, &dtdy);
        return (1-s)*(1-t) * v00 + (1-s)*(  t) * v01 +
               (  s)*(1-t) * v10 + (  s)*(  t) * v11;
    }
private:
    // BilerpTexture Private Data
    TextureMapping2D *mapping;
    T v00, v01, v10, v11;
};

类的作用:

(传入4个常量值,这4个常量分别是 纹理空间上(0, 0), (1, 0), (0, 1),(1, 1)  位置上的值,那么 TextureMapping2D 计算出来的纹理坐标(s,t) 其实就是 这 4个常量的 插值时候的权重,也就是说,这个 BilerpTexture 利用 纹理坐标来 双线性插值 纹理坐标空间4个角的常量)

The BilerpTexture class provides bilinear interpolation between four constant values.
Values are defined at (0, 0), (1, 0), (0, 1), and (1, 1) in (s , t) parameter space. The value
at a particular (s , t) position is found by interpolating between them.

1. T Evaluate(const DifferentialGeometry &dg) const

T Evaluate(const DifferentialGeometry &dg) const {
        float s, t, dsdx, dtdx, dsdy, dtdy;
        mapping->Map(dg, &s, &t, &dsdx, &dtdx, &dsdy, &dtdy);
        return (1-s)*(1-t) * v00 + (1-s)*(  t) * v01 +
               (  s)*(1-t) * v10 + (  s)*(  t) * v11;
    }

思路:

(Evaluate 先 利用 s 来插值 v00 和 v10 得到 tmp1,再利用 s 来 插值 v01 和 v11 得到 tmp2,之后 利用 t 来插值 tmp1 和 tmp2, 得到最后的结果 )

The interpolated value of the four values at an (s , t) position can be computed by three
linear interpolations. For example, we can first use s to interpolate between the values
at (0, 0) and (1, 0) and store that in a temporary tmp1. We can then do the same for the
(0, 1) and (1, 1) values and store the result in tmp2. Finally, we use t to interpolate between
tmp1 and tmp2 and obtain the final result. Mathematically, this is

Rather than storing the intermediate values explicitly, some algebraic rearrangement
gives us the same result from an appropriately weighted average of the four corner values:

猜你喜欢

转载自blog.csdn.net/aa20274270/article/details/83743870
今日推荐