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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值