Texture Wrapping

[Previous] [Next]

Texture wrapping affects the way Direct3D rasterizes textured polygons and the way it utilizes the texture coordinates specified for each vertex. As polygons are rasterized, Direct3D interpolates between the texture coordinates of each polygon's vertices to determine which texels to use for each pixel in the polygon. Direct3D usually treats a texture as a 2D plane, interpolating new texels by taking the shortest route from point A to point B (where each point represents a u, v position).

By enabling texture wrapping of the u and v coordinates, you change how Direct3D defines the shortest route between texture coordinates in the u and v directions. Texture wrapping always makes the rasterizer take the shortest route between texture coordinate sets, assuming that 0.0 and 1.0 are coincident (occupy the same point in space). Enabling texture wrapping in one direction causes DirectX to treat a texture as if it's "wrapped" around a cylinder.

Wrapping in the u direction will change how Direct3D interpolates texture coordinates. Figure 8-6 illustrates how the shortest route between points A and B on a "normal" (nonwrapped) texture differs from the shortest route between the same points on a wrapped surface. On a flat, nonwrapped texture, the shortest path between points A and B in the figure is across the texture's middle. On a surface wrapped in the u direction, the shortest path between the points in the figure is across the border, where 0.0 and 1.0 coexist. Wrapping a texture in the v direction will make it appear as though it's wrapped around a cylinder lying on its side. Finally, when you wrap a surface in both the u and v directions, the texture is applied (wrapped) as if around a torus.

click to view at full size.

Figure 8-6 Direct3D's perception of the shortest distance between points with and without texture wrapping

Applying a Texture Wrap

When you use the IDirect3DDevice7 interface, Direct 3D enables texture wrapping individually for texture coordinate sets that are used by vertices rather than for the texture stages themselves. You call the IDirect3DDevice7::SetRenderState method to enable texture wrapping. By passing one of the D3DRENDERSTATE_WRAP0 through D3DRENDERSTATE_WRAP7 enumerated values as the first argument, you specify the stage with the wrapping state you want to set. You can set the second argument to one of the D3DWRAPCOORD_0 through D3DWRAPCOORD_3 flags to enable texture wrapping in the u or v direction. By using these flags together, you can enable wrapping in multiple directions. You can also disable texture wrapping for a set of texture coordinates by setting the value for the render state to 0. Be aware that when you activate texture wrapping, it makes texture coordinates outside the 0.0 to 1.0 range invalid and texture-addressing modes unavailable for use.



Inside Direct3D
Inside Direct3D (Dv-Mps Inside)
ISBN: 0735606137
EAN: 2147483647
Year: 1999
Pages: 131

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net