Uv texture coordinate settings and texture rules

Source: Internet
Author: User

1. What is UV?


For a 3D model, there are two most important coordinate systems. One is the coordinate of the vertex position (X, Y, Z), and the other is the UV coordinate. What is UV? To put it simply, it is the basis for the texture to film on the model surface. To put it completely, it should be UVW (because XYZ has already been used, so it should be represented by three other letters ). U and V are the coordinates of the image in the horizontal and vertical directions of the monitor. The values are generally 0 ~ 1, that is (U pixel/Image width in the horizontal direction, V pixel/Image height in the vertical direction ). What about W? A texture is two-dimensional. Why are there three coordinates? Well, W is perpendicular to the display surface. It is generally used for program pasters or some 3D pasters (remember, there is a concept of 3D pasters !), Games are not often used, so we are generally referred to as UV.

All image files are two-dimensional planes. The horizontal direction is U, and the vertical direction is V. Through this plane, the two-dimensional UV coordinate system is used. We can locate any pixel in an image. But one question is, how can we mount the two-dimensional plane to the three-dimensional surface of the Green chart and the Polygon surface? For the surface of a green surface. Because it has UV parameters, although this UV value is used to locate the point on the surface, it is also two-dimensional, therefore, it is easy to correspond the points on the surface to the pixels on the plane image through conversion. Therefore, it is very straightforward to attach an image to a company with a single place. However, for a multi-deformation model, textures become a troublesome task. Therefore, an additional UV coordinate is introduced for the polygon to map the vertices of the polygon to the pixels in the image file so that texture maps can be located on the polygon surface. Therefore, in addition to three-dimensional spatial coordinates, the vertices of a polygon. It also has two-dimensional UV coordinates.

UV "here refers to the abbreviation of the coordinates of the u and v texture textures (it is similar to the X, Y, and z axes of the spatial model ). it defines the position of each vertex on the image. these points are associated with the 3D model to determine the position of the surface texture map. UV precisely maps each point in the image to the surface of the model object. the software performs smooth image interpolation on the gap between points. this is the so-called UV texture.
So why do we use UV coordinates instead of standard projection coordinates? Generally, the most standard method for texture textures is to use planar (plane), cylindrical (cylindrical), spherical (spherical), and cubic (square box) coordinates to project textures.
Planar projection directly projects an image along the x, y, or Z axes to an object. this method is used for paper, announcements, book covers, and other objects with smooth surface. the disadvantage of plane projection is that if the surface is uneven or the edge of the object is bent, an unsatisfactory joint and deformation of A will occur. to avoid this, you need to create an image with an alpha channel to mask the adjacent plane projection seams, which is very cumbersome. therefore, do not apply plane projection to objects with a large thickness or uneven surface. plane projection can be performed on cubes in the x and y directions, but the fusion of edge seams must be noted. or use seamless continuous textures and cubic projection. most software supports automatic image scaling to make the image match the surface. obviously, if your image is different from the surface shape, auto scaling will change the image proportion to match the surface. this usually produces unsatisfactory results, so measure your object size before creating a texture.

2. uv texture coordinate settings and texture rules

When opengl maps a square, it defines the texture coordinates, a series of arrays. I believe that beginners of openggl es will have a headache and do not know what to write. Now I will share my research results with you!

When texture ING is started, you must provide other data for OpenGL ES, that is, the texture coordinates of each vertex in the vertex array. Texture coordinates define which part of the image will be mapped to a polygon. It works in a strange way.

The following figure shows the coordinates of the Opengl texture system on the android platform, with the origin in the lower left corner.

We now discuss how to use these texture coordinates. When we specify the vertex in the vertex array, we need to provide texture coordinates in another array, which is called the texture coordinate array. It is critical to define the sequence of coordinate arrays.

 

 

 

Float texCoords [] = new float [] {
// FRONT
0.0f, 0.0f,
1.0f, 0.0f,
0.0f, 1.0f,
1.0f, 1.0f,
};

The effect is as follows:

 

If we want to capture images without any texture, we can obtain the array according to the above method.

Float texCoords [] = new float [] {
// FRONT
0.5f, 0.5f,
1f, 0.5f,
0.5f, 1f,
1f, 1f
};

The effect is as follows:

 

 

Let's look at the original texture file.

You will find that the y axis of the screenshot is reversed, because the android image coordinate system is inconsistent with the Opengl es coordinate system. The simplest correction method is to use a tool to flip the original image, which saves a lot of performance and resources are valuable.

Triangle texture ING can be completed smoothly as long as we follow our ing rules.

Float texCoords [] = new float [] {
0.0f, 0.0f,
1.0f, 0.0f,
0.5f, 1.0f,
};

Effect:

 

We should know the meaning of the rule definition of the texture coordinate array.

 

Tile and foil pull

Our texture coordinate system ranges from 0.0 to 1.0 on both axes. What if we set a value beyond this range? There are two options based on The View setting method.

Tile (also called repetition)
One option is tile texture. In OpenGL terminology, it is also called "repetition ". If we change all 1.0 of the first texture coordinate array to 2.0:
Static const GLfloat texCoords [] = {
0.0, 2.0,
2.0, 2.0,
0.0, 0.0,
2.0, 0.0
};

You can set it through the glTexParameteri () function.

GlTexParameterf (GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL10.GL _ REPEAT );
GlTexParameterf (GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL10.GL _ REPEAT );

 

Clamping position
Another possible option is to allow OpenGL ES to simply limit over 1.0 to 1.0, and limit any value lower than 0.0 to 0.0. This will actually cause duplicate edge pixels.

 

You can set it through the glTexParameteri () function.

GlTexParameterf (GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE );
GlTexParameterf (GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE );

 

Uv texture coordinate settings and texture rules

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.