DIRECTX11 Texture coordinates

Source: Internet
Author: User
Texture coordinates 1. What is texture coordinates?

The Direct3D texture coordinate system consists of a U-axis that represents the horizontal orientation of the image and a V-axis that represents the vertical orientation of the image. The coordinates (U,V) specify an element on the texture, which we call the texture element (Texel, the translator Note: Texel is the abbreviation for the texture Element), where 0≤u,v≤1. Note that the positive direction of the V-axis is "vertically downward" (see Figure 8.2). In addition, the normalized coordinate interval is set to [0,1] because it enables Direct3D to have a coordinate space independent of the texture size, for example, whether the actual size of the texture is 256x256, 512x1024, or 2048x2048, (0.5, 0.5) Always represents the middle of the texture element. Similarly, (0.25, 0.75) is a texture element that is located horizontally at 1/4 of the total width, and at 3/4 of the total height in the vertical direction. Now we'll just discuss the texture coordinates in the [0,1] interval, and we'll talk about how to handle the texture coordinates when they're out of range.


(The texture coordinate system (texture coordinate system), sometimes referred to as the texture space (texture spaces). )

For each 3D triangle, we define a corresponding 2D triangle on the texture to map the texture to the 3D triangle (see figure below).
(the diagram on the left is a triangle in 3D space, and the right is the 2D triangle we defined on the texture, which is mapped to the 3D triangle.) )

If the vertex coordinates of the triangle are p0,p1 and P2, the corresponding texture coordinates are q0, Q1, and Q2. For any point on the 3D triangle (x, y, z), its texture coordinates (U,V) are worth the linear interpolation of vertex texture coordinates on the 3D triangular surface, while the parameters s and T in the linear interpolation are the same, i.e.:

(x, Y, z) =p=p0+s (p1−p0) +t (P2−P0)

If the s≥0,t≥0,s+t≤1

(u,v) =q=q0+s (q1−q0) +t (q2−q0)

In one way, each point on the triangle can be given a corresponding texture coordinate. 2. How texture coordinates are represented.

To use textures, we need to modify the vertex structure again, add a pair of texture coordinates, and specify the points on the texture so that each 3D point has a corresponding 2D texture point. Thus, each 3D triangle made up of 3 vertices will have a corresponding 2D texture triangle in the texture space (i.e., a correspondence between each 2D texture triangle and the 3D triangle).

Base 32-bit vertex struct
struct Basic32
{
    XMFLOAT3 Pos;
    XMFLOAT3 Normal;
    XMFLOAT2 Tex;
};
Const D3D11_INPUT_ELEMENT_DESC INPUTLAYOUTDESC::BASIC32[3] =
{
    {"POSITION", 0, Dxgi_format_r32g32b32_float, 0, 0,d3d11_input_per_vertex_data, 0},
    {"NORMAL", 0, dxgi_format_r32g32b32_float, 0, 12,d3d11_input_per_vertex_ DATA, 0},
    {"Texcoord", 0, dxgi_format_r32g32_float, 0, 24,d3d11_input_per_vertex_data, 0}
};

Note: You can create a 2D texture triangle and a 3D triangle with a very different "strange" texture map. As a result, when the 2D texture is mapped to a 3D triangle, it appears to be stretched and distorted and looks bad. For example, stretching occurs when you map a pointed triangle to a positive triangle. Often, texture distortions should be avoided unless the artist expects this distorted effect.

Looking at the image below, we map the entire texture to each face of the cube, but this is not necessary. We can map only a portion of the texture to the geometry. We can combine several unrelated images on a large texture map called texture Atlas texture, and then use it for different objects. The texture coordinates determine which part of the texture is mapped to the triangle.


(a texture atlas that stores 4 textures.) Set the texture coordinates of each vertex to map the desired part of the texture to the geometry. )

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.