纹理寻址模式Texture addressing modes

Direct3D 应用程序可以将纹理坐标分配至任何基元的任何顶点。Your Direct3D application can assign texture coordinates to any vertex of any primitive. 通常,你分配至某个顶点的 u 纹理以及 v 纹理坐标的范围介于 0.0-1.0(包含这两个值)。Typically, the u- and v-texture coordinates that you assign to a vertex are in the range of 0.0 to 1.0 inclusive. 但如果在此范围之外分配纹理坐标,则可以创造某些特殊的纹理效果。However, by assigning texture coordinates outside that range, you can create certain special texturing effects. ..

控制 Direct3D 纹理坐标为外部的用途[0.0,1.0]通过设置纹理寻址模式的范围。You control what Direct3D does with texture coordinates that are outside the [0.0, 1.0] range by setting the texture addressing mode. 例如,你可以通过应用程序设置纹理寻址模式,以使得纹理跨基元平铺。For instance, you can have your application set the texture addressing mode so that a texture is tiled across a primitive.

借助 Direct3D,应用程序可以执行纹理环绕。Direct3D enables applications to perform texture wrapping. 参阅纹理环绕See Texture wrapping.

启用纹理包装有效地使外部的纹理坐标[0.0,1.0]范围无效和行为的光栅化此类拖欠纹理坐标是不确定这种情况下。Enabling texture wrapping effectively makes texture coordinates outside the [0.0, 1.0] range invalid, and the behavior for rasterizing such delinquent texture coordinates is undefined in this case. 当纹理环绕处于启用状态时,不能使用纹理寻址模式。When texture wrapping is enabled, texture addressing modes are not used. 请注意,当纹理环绕处于启用状态时,你的应用程序不会指定低于 0.0 或高于 1.0 的纹理坐标。Take care that your application does not specify texture coordinates lower than 0.0 or higher than 1.0 when texture wrapping is enabled.

寻址模式的纹理的摘要Summary of the texture addressing modes

纹理寻址模式Texture addressing mode 描述Description
环绕Wrap 在每个整数点重复纹理。Repeats the texture on every integer junction.
MirrorMirror 以每个整数为界映射纹理。Mirrors the texture at every integer boundary.
ClampClamp 你的纹理坐标到 clamps [0.0,1.0]范围;Clamp 模式将纹理应用一次,然后被抹去边缘像素的颜色。Clamps your texture coordinates to the [0.0, 1.0] range; Clamp mode applies the texture once, then smears the color of edge pixels.
边框颜色Border Color 对于超出 0.0-1.0(包括这两者)范围的任何纹理坐标,使用任意的边框颜色Uses an arbitrary border color for any texture coordinates outside the range of 0.0 through 1.0, inclusive.

 

包装纹理寻址模式Wrap texture address mode

在 Wrap 纹理寻址模式下,Direct3D 可以在每个整数点重复纹理。The Wrap texture address mode makes Direct3D repeat the texture on every integer junction.

例如,假设应用程序创建平方基元并指定纹理坐标为 (0.0,0.0)、(0.0,3.0)、(3.0,3.0) 以及 (3.0,0.0)。Suppose, for example, your application creates a square primitive and specifies texture coordinates of (0.0,0.0), (0.0,3.0), (3.0,3.0), and (3.0,0.0). 将纹理寻址模式设置为“Wrap”会使纹理在 u 和 v 方向应用三次,如下图所示。Setting the texture addressing mode to "Wrap" results in the texture being applied three times in both the u-and v-directions, as shown in the following illustration.

图示为在 u 和 v 方向环绕的正面纹理

将此与下面的镜像纹理寻址模式比较。Contrast this with the following Mirror texture address mode.

镜像纹理寻址模式Mirror texture address mode

在镜像纹理寻址模式下,Direct3D 可以每个整数为界映射纹理。The Mirror texture address mode causes Direct3D to mirror the texture at every integer boundary.

例如,假设应用程序创建平方基元并指定纹理坐标为 (0.0,0.0)、(0.0,3.0)、(3.0,3.0) 以及 (3.0,0.0)。Suppose, for example, your application creates a square primitive and specifies texture coordinates of (0.0,0.0), (0.0,3.0), (3.0,3.0), and (3.0,0.0). 将纹理寻址模式设置为“镜像”会使纹理在 u 和 v 方向应用三次。Setting the texture addressing mode to "Mirror" results in the texture being applied three times in both the u- and v-directions. 纹理应用到的所有其他行和列均为前一行或前一列的镜像,如下图所示。Every other row and column that it is applied to is a mirror image of the preceding row or column, as shown in the following illustration.

图示为采用 3x3 网格的镜像

将此与前面的 Wrap 纹理寻址模式比较。Contrast this with the previous Wrap texture address mode.

将纹理寻址模式Clamp texture address mode

将纹理地址模式将导致要固定其范围为你的纹理坐标的 Direct3D [0.0,1.0]范围;Clamp 模式将纹理应用一次,然后被抹去边缘像素的颜色。The Clamp texture address mode causes Direct3D to clamp your texture coordinates to the [0.0, 1.0] range; Clamp mode applies the texture once, then smears the color of edge pixels.

例如,假设应用程序创建了一个平方基元,并将 (0.0,0.0)、(0.0,3.0)、(3.0,3.0) 以及 (3.0,0.0) 纹理坐标分配至该基元的顶点。Suppose that your application creates a square primitive and assigns texture coordinates of (0.0,0.0), (0.0,3.0), (3.0,3.0), and (3.0,0.0) to the primitive's vertices. 将纹理寻址模式设置为"Clamp"会使纹理应用一次。Setting the texture addressing mode to "Clamp" results in the texture being applied once. 列顶部和行结尾的像素颜色将分别延伸到基元的顶部和右侧。The pixel colors at the top of the columns and the end of the rows are extended to the top and right of the primitive respectively.

下图所示为固定的纹理。The following illustration shows a clamped texture.

图示为纹理以及一个固定的纹理

边框颜色纹理寻址模式Border Color texture address mode

在边框颜色纹理寻址模式下,对于超出 0.0-1.0(包括这两者)范围的任何纹理坐标,Direct3D 可以使用任意颜色(称为边框颜色)。The Border Color texture address mode causes Direct3D to use an arbitrary color, known as the border color, for any texture coordinates outside the range of 0.0 through 1.0, inclusive.

在下图中,应用程序指定必须将纹理应用到使用红色边框的基元。In the following illustration, the application specifies that the texture be applied to the primitive using a red border.

图示为纹理以及使用红色边框的纹理

设备限制Device limitations

尽管系统一般情况下支持超出 0.0-1.0(包括这两者)范围的纹理坐标,但硬件限制通常会影响纹理坐标可超出的范围。Although the system generally allows texture coordinates outside the range of 0.0 and 1.0, inclusive, hardware limitations often affect how far outside that range texture coordinates can be. 当你检索设备功能时,呈现设备将显示对设备所允许的所有纹理坐标的限制。A rendering device communicates the limit for the full range of texture coordinates allowed by the device, when you retrieve the device's capabilities.

例如,如果限值为 128,则输入的纹理坐标必须控制在 -128.0 至 +128.0 的范围内。For instance, if this value is 128, then the input texture coordinates must be kept in the range -128.0 to +128.0. 使超出该范围的纹理坐标通过顶点是无效的。Passing vertices with texture coordinates outside this range is invalid. 相同的限制适用于因纹理坐标自动生成以及纹理坐标变换而生成的纹理坐标。The same restriction applies to the texture coordinates generated as a result of automatic texture coordinate generation and texture coordinate transformations.

纹理重复限制取决于按纹理坐标编索引的纹理的大小。Texture repeating limitations can depend on the size of the texture indexed by the texture coordinates. 假设在此情况下,纹理大小为 32,设备允许的纹理坐标的范围为 512,则实际有效的纹理坐标范围应为 512/32 = 16,也就是说,该设备的纹理坐标范围必须介于 -16.0 至 +16.0。In that case, supposing the texture dimension is 32, and the range of texture coordinates allowed by the device is 512, the actual valid texture coordinate range would therefore be 512/32 = 16, so the texture coordinates for this device must be within the range of -16.0 to +16.0.

相关主题Related topics

纹理Textures