1. 程式人生 > >PBRT_V2 總結記錄 <46> TextureMapping2D 和 UVMapping2D

PBRT_V2 總結記錄 <46> TextureMapping2D 和 UVMapping2D

概述:

(TextureMapping2D 和  TextureMapping3D 提供介面 來 計算 2D 或者 3D 的紋理座標,Texture 會儲存它們的一個指標,使用它們來為每一個點計算紋理座標)

TextureMapping2D and TextureMapping3D—that provide an interface for computing these 2D and 3D texture 

coordinates. We will then implement a number of standard mappings using this interface

Figure 10.7: A checkerboard texture, applied to a hyperboloid with different texture coordinate generation techniques. From left to right, (u, v) mapping, spherical mapping, cylindrical mapping, and planar mapping.

Texture implementations store a pointer to a 2D or 3D mapping function as appropriate and use it to compute the texture coordinates at each point. Thus, it’s easy to add new mappings to the system without having to modify all of the Texture implementations, and different mappings can be used for different textures associated with the same surface. In pbrt, we will use the convention that 2D texture coordinates are denoted by (s , t); this helps make clear the distinction between the intrinsic (u, v) parameterization of the underlying surface and the (possibly different) coordinate values used for texturing.

TextureMapping2D 類


// Texture Declarations
class TextureMapping2D {
public:
    // TextureMapping2D Interface
    virtual ~TextureMapping2D() { }
    virtual void Map(const DifferentialGeometry &dg,
                     float *s, float *t, float *dsdx, float *dtdx,
                     float *dsdy, float *dtdy) const = 0;
};

作用:

(Map 函式 主要是傳入一個 DifferentialGeometry  ,就會返回  (s,t)的紋理座標出來,並且,還會返回 dsdx,dtdx,dsdy, dtdy, 的偏導數出來,這些偏導數其實就是 sampling rate,就可以判斷是否過濾這個point)

The TextureMapping2D base class has a single method, TextureMapping2D::Map(), which is given the DifferentialGeometry at the shading point and returns the (s , t) texture coordinates via float pointers. It also returns estimates for the change in s and t with respect to pixel x and y coordinates in the dsdx, dtdx, dsdy, and dtdy parameters so that textures that use the mapping can determine the (s , t) sampling rate and filter accordingly.

UVMapping2D 類


class UVMapping2D : public TextureMapping2D {
public:
    // UVMapping2D Public Methods
    UVMapping2D(float su = 1, float sv = 1, float du = 0, float dv = 0);
    void Map(const DifferentialGeometry &dg, float *s, float *t,
        float *dsdx, float *dtdx, float *dsdy, float *dtdy) const;
private:
    float su, sv, du, dv;
};

UVMapping2D::UVMapping2D(float ssu, float ssv, float ddu, float ddv)
    : su(ssu), sv(ssv), du(ddu), dv(ddv) { }
void UVMapping2D::Map(const DifferentialGeometry &dg,
                      float *s, float *t, float *dsdx, float *dtdx,
                      float *dsdy, float *dtdy) const {
    *s = su * dg.u + du;
    *t = sv * dg.v + dv;
    // Compute texture differentials for 2D identity mapping
    *dsdx = su * dg.dudx;
    *dtdx = sv * dg.dvdx;
    *dsdy = su * dg.dudy;
    *dtdy = sv * dg.dvdy;
}

作用:

(縮放 + 偏移 紋理座標)

The simplest mapping uses the 2D parametric (u, v) coordinates in the Differential Geometry to compute the texture coordinates. Their values can be offset and scaled with user-supplied values in each dimension.

scale-and-shift computation to compute (s , t) coordinates