Texture paving method, device and storage medium
By calculating the vertices and texture coordinates of the polygon plane in the continuous surface, and using a discretization algorithm to render the surface, the problem of poor rendering effects in the existing technology is solved and a higher quality texture rendering effect is achieved.
Patent Information
- Application Number
- CN202110978839.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-08-25
- Publication Date
- 2024-09-03
- Estimated Expiration
- 2041-08-25
AI Technical Summary
In the existing technology, the surface rendering effect of 3D objects is poor because pixel colors can only be interpolated from vertices, resulting in too many gradient colors and a lack of detail and diversity.
By obtaining the proportion of each polygon plane in the continuous surface, calculating its vertex and texture coordinates, and discretizing them into the vertex texture coordinates of the triangular patch, the surface is rendered using the triangle barycentric coordinate system or the inverse bilinear interpolation algorithm.
The rendering effect is improved, ensuring that the overall texture of continuous surfaces is continuous, and the rendering details and diversity are enhanced.
Smart Images

Figure CN113689536B
Abstract
Description
Technical Field
[0001] The invention relates to a texture paving method, a device and a storage medium, and belongs to the technical field of computer 3D modeling. Background Art
[0002] Textures are images used in materials, which are mapped to the surface of 3D objects to which the material is applied. In computer graphics, textures are displayed directly, or the values of their pixels are used as masks in materials or for other algorithms. In simple terms, it can be considered as rendering an image by attaching it to the surface of an object in a certain way.
[0003] In the existing scheme, during the rendering process, the color of each pixel / fragment can only be obtained by interpolating the color of the vertex. However, since the vertices of an object are limited, the surface formed occupies a large part of the pixels on the screen. If the pixel color can only be obtained by interpolating the vertices, the above scheme can only obtain some gradient colors, that is, the rendering effect of the above scheme is poor. Summary of the invention
[0004] The object of the present invention is to provide a texture paving method, device and storage medium to solve the problems existing in the prior art.
[0005] In order to achieve the above object, the present invention provides the following technical solutions:
[0006] According to a first aspect, an embodiment of the present invention provides a texture paving method, the method comprising:
[0007] Obtaining the proportion of each polygonal plane in all continuous surfaces; the multiple polygonal planes are continuous surfaces, which are used to simulate the curved surface;
[0008] Obtaining vertex coordinates and texture coordinates of each polygonal plane according to the ratio;
[0009] Calculate the texture coordinates of the vertices of each triangular facet after discretization of each polygonal plane according to the vertex coordinates and the texture coordinates;
[0010] The surface is rendered according to the texture coordinates of each triangle.
[0011] Optionally, obtaining the vertex coordinates of each polygonal plane includes:
[0012] Determine the UV direction of the texture based on the direction of the initial surface;
[0013] Determine the UV direction of the polygonal plane according to the UV direction and adjacent edges;
[0014] Determine the adjacent side as a reference axis, and determine the farthest opposite side of the adjacent side as a first axis;
[0015] Determine the connected edge between the reference axis and the first axis as a second axis and a third axis in different directions;
[0016] The vertex coordinates of the polygonal plane are determined according to four intersection points of the reference axis, the first axis, the second axis and the third axis.
[0017] Optionally, obtaining the texture coordinates of each polygonal plane includes:
[0018] Generate a plan graph of the continuous surface according to the shared edge search of the initial surface in a preset manner, and update the lower left corner of the plan graph as the head node;
[0019] Traversing the plane graph according to the head node in a preset manner to obtain a range of the plane graph;
[0020] The texture coordinates of the bounding box of each polygonal plane are determined according to the range of the plan view and the size of each continuous face.
[0021] Optionally, the preset method includes breadth-first search.
[0022] Optionally, the method further includes:
[0023] Traverse each continuous surface;
[0024] An initial face is selected from the continuous faces, wherein the initial face is a quadrilateral and four sides of the quadrilateral are all continuous sides.
[0025] Optionally, calculating the texture coordinates of the vertices of each triangular facet after discretization of each polygonal plane according to the vertex coordinates and the texture coordinates includes:
[0026] Determining the shape of a polygon constructed by texture coordinates of the polygonal plane;
[0027] The texture coordinates of the vertices of each triangular facet after discretization of each polygonal plane are calculated according to the determined shape and the vertex coordinates.
[0028] Optionally, if the determined shape is a triangle, calculating the texture coordinates of the vertices of each triangular facet after discretization of each polygonal plane according to the determined shape and the vertex coordinates includes:
[0029] The texture coordinates of the vertices of each triangular facet after discretization of each polygonal plane are calculated through a triangle barycentric coordinate system according to the vertex coordinates.
[0030] Optionally, if the determined shape is a quadrilateral, calculating the texture coordinates of the vertices of each triangular facet after discretization of each polygonal plane according to the determined shape and the vertex coordinates includes:
[0031] The texture coordinates of the vertices of each triangular facet after each polygonal plane is discretized are calculated by an inverse bilinear interpolation algorithm according to the vertex coordinates.
[0032] In a second aspect, a texture paving device is provided, the device comprising a memory and a processor, the memory storing at least one program instruction, the processor implementing the method as described in the first aspect by loading and executing the at least one program instruction.
[0033] According to a third aspect, a computer storage medium is provided, wherein at least one program instruction is stored in the computer storage medium, and the at least one program instruction is loaded and executed by a processor to implement the method according to the first aspect.
[0034] By obtaining the proportion of each polygonal plane in all continuous faces; the multiple polygonal planes are continuous faces, used to simulate the curved surface; according to the proportion, the vertex coordinates and texture coordinates of each polygonal plane are obtained; according to the vertex coordinates and the texture coordinates, the texture coordinates of the vertices of each triangular face after each polygonal plane is discretized are calculated; and the curved surface is rendered according to the texture coordinates of each triangular face. The problem of poor rendering effect in the existing solution is solved, and the texture coordinates of each vertex in each face can be calculated for the continuous face, so as to ensure the overall texture continuity of the continuous face and thus improve the rendering effect.
[0035] The above description is only an overview of the technical solution of the present invention. In order to more clearly understand the technical means of the present invention and implement it according to the contents of the specification, the following is a detailed description of the preferred embodiments of the present invention in conjunction with the accompanying drawings. BRIEF DESCRIPTION OF THE DRAWINGS
[0036] Figure 1 A schematic diagram of a texture rendering primitive provided by an embodiment of the present invention;
[0037] Figure 2 A method flow chart of a texture paving method provided by one embodiment of the present invention;
[0038] Figure 3 A schematic diagram of determining the UV direction of an initial surface provided by an embodiment of the present invention;
[0039] Figure 4a and Figure 4b A schematic diagram of determining vertex coordinates of a polygonal plane provided by an embodiment of the present invention;
[0040] Figure 5 A schematic diagram of a plane diagram obtained by searching according to an embodiment of the present invention;
[0041] Figure 6 A possible schematic diagram of traversing a planar graph according to a head node provided for an embodiment of the present invention;
[0042] Figure 7 and Figure 8 A schematic diagram of a case where the shapes of the texture coordinates of a polygonal plane determined to be obtained are respectively a triangle and a quadrilateral, provided by an embodiment of the present invention;
[0043] Fig. 9 A schematic diagram of calculating coordinates based on inverse bilinear interpolation provided by one embodiment of the present invention;
[0044] Fig.10 A schematic diagram of calculating coordinates based on inverse bilinear interpolation provided by one embodiment of the present invention;
[0045] Fig.11a and 11b is a schematic diagram of a sphere before and after rendering according to the method described in the present application;
[0046] Fig.12a and 12b Schematic diagram of a ring body before and after rendering according to the method described in this application. DETAILED DESCRIPTION
[0047] The technical solution of the present invention will be described clearly and completely below in conjunction with the accompanying drawings. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.
[0048] In the description of the present invention, it should be noted that the terms "center", "upper", "lower", "left", "right", "vertical", "horizontal", "inner", "outer", etc., indicating the orientation or positional relationship, are based on the orientation or positional relationship shown in the drawings, and are only for the convenience of describing the present invention and simplifying the description, rather than indicating or implying that the device or element referred to must have a specific orientation, be constructed and operated in a specific orientation, and therefore cannot be understood as limiting the present invention. In addition, the terms "first", "second", and "third" are used for descriptive purposes only, and cannot be understood as indicating or implying relative importance.
[0049] In the description of the present invention, it should be noted that, unless otherwise clearly specified and limited, the terms "installed", "connected", and "connected" should be understood in a broad sense, for example, it can be a fixed connection, a detachable connection, or an integral connection; it can be a mechanical connection or an electrical connection; it can be a direct connection, or it can be indirectly connected through an intermediate medium, or it can be the internal communication of two components. For ordinary technicians in this field, the specific meanings of the above terms in the present invention can be understood according to specific circumstances.
[0050] In addition, the technical features involved in the different embodiments of the present invention described below can be combined with each other as long as they do not conflict with each other.
[0051] When rendering an image, you need to use textures to draw primitives. Before drawing each vertex, you specify texture coordinates for the vertex. Each vertex of the primitive corresponds to a texture coordinate, which is used to indicate which part of the texture image to sample from, and then interpolate the fragments on other fragments of the graphic. 2D texture coordinates are on the x and y axes, ranging from 0 to 1. Using texture coordinates to get the texture color is called sampling. Texture coordinates start at (0,0), which is the lower left corner of the texture image, and end at (1,1), which is the upper right corner of the texture image.
[0052] Please refer to Figure 2 , which shows a method flow chart of a texture paving method provided by an embodiment of the present application, such as Figure 2 As shown, the method includes:
[0053] Step 201, obtaining the proportion of each polygonal plane in all continuous surfaces; the multiple polygonal planes are continuous surfaces, which are used to simulate the curved surface;
[0054] In 3D modeling, multiple parallel planes connected to each other are used to simulate curved surfaces. This group of polygonal planes is called a continuous surface.
[0055] In one possible embodiment, combining Figure 1 It can be seen that the texture coordinates range from 0 to 1. Assuming that the surface is divided into 10 continuous faces, the horizontal texture coordinates occupied by each continuous face are from 0 to 0.1. At this time, the U coordinate of the leftmost vertex of the first polygonal plane is 0, the U coordinate of the rightmost vertex is 0.1, and so on.
[0056] Step 202, obtaining vertex coordinates and texture coordinates of each polygonal plane according to the ratio;
[0057] The step of obtaining the vertex coordinates of each polygonal plane includes:
[0058] First, determine the UV direction of the texture based on the direction of the initial surface;
[0059] Before this step, the initial surface needs to be determined. The steps of determining the initial surface include:
[0060] (1) Traverse each continuous surface;
[0061] (2) An initial face is selected from the continuous faces, wherein the initial face is a quadrilateral and the four sides of the quadrilateral are all continuous sides.
[0062] The continuous edges mentioned here refer to the straight line edges that simulate the curve through a set of straight line segments.
[0063] Optionally, in addition to the four edges of the quadrilateral being continuous edges, the four edges may also be shared edges, where a shared edge refers to an edge shared by two continuous faces.
[0064] After determining the initial face, determine the direction of the initial face as the UV direction of the texture. For example, please refer to Figure 3 , where the horizontal direction is the U direction and the direction vertical to the U direction is the V direction.
[0065] Second, determining the UV direction of the polygonal plane according to the UV direction and adjacent edges;
[0066] If the expansion direction is the u direction, the adjacent side is the v axis, otherwise it is the u axis.
[0067] Third, the adjacent side is determined as a reference axis, and the farthest opposite side of the adjacent side is determined as a first axis;
[0068] Fourth, determining the connected edge between the reference axis and the first axis as the second axis and the third axis in different directions;
[0069] Fifth, the vertex coordinates of the polygonal plane are determined according to four intersection points of the reference axis, the first axis, the second axis, and the third axis.
[0070] Please refer to Figure 4a and Figure 4b , which shows two possible schematic diagrams for determining vertex coordinates.
[0071] The step of obtaining the texture coordinates of each polygonal plane includes:
[0072] First, a preset method is used to search and generate a plane graph of the continuous surface according to the shared edge of the initial surface, and the lower left corner of the plane graph is updated as the head node;
[0073] The preset method includes breadth-first search. A shared edge is an edge shared by two continuous faces.
[0074] After searching for the plane graph, the coordinates of the four vertices of the plane graph bounding box are recorded. The bounding box is just the smallest quadrilateral that encloses the plane graph.
[0075] For example, please refer to Figure 5 , assuming that the initial face is the face in the box in the figure, then after searching, the plane view shown in the figure can be obtained.
[0076] Second, traverse the plane graph according to the head node in a preset manner to obtain a range of the plane graph;
[0077] Please refer to Figure 6 , which shows a possible schematic diagram of traversing a planar graph based on the head node.
[0078] Third, the texture coordinates of the bounding box of each polygonal plane are determined according to the range of the plan view and the size of each continuous face.
[0079] Step 203, calculating the texture coordinates of the vertices of each triangular facet after discretization of each polygonal plane according to the vertex coordinates and the texture coordinates;
[0080] Optionally, this step includes:
[0081] First, determine the shape of the polygon constructed by the texture coordinates of the polygonal plane;
[0082] Depending on whether the texture coordinates overlap, the shape of the polygon can be determined to be a triangle or a quadrilateral. Specifically, if two texture coordinates overlap, the shape of the polygon plane is determined to be a triangle, and if there is no texture coordinate overlap, the shape of the polygon plane is determined to be a quadrilateral.
[0083] For example, please refer to Figure 7 and Figure 8 , which respectively show schematic diagrams of the determined shapes being a triangle and a quadrilateral.
[0084] Second, the texture coordinates of the vertices of each triangular facet after each polygonal plane is discretized are calculated according to the determined shape and the vertex coordinates.
[0085] In a possible implementation, if the determined shape is a triangle, calculating the texture coordinates of the vertices of each triangular facet after discretization of each polygonal plane according to the determined shape and the vertex coordinates includes:
[0086] The texture coordinates of the vertices of each triangular facet after discretization of each polygonal plane are calculated through a triangle barycentric coordinate system according to the vertex coordinates.
[0087] The corresponding texture coordinates can be calculated directly using the triangle barycentric coordinate system:
[0088] B1=P1-P0
[0089] B2=P2-P0
[0090] P-P0=B1·u+B2·v
[0091] Among them, P0, P1, P2 are the three points of the triangle, and P is the point we are looking for.
[0092] Assumptions:
[0093] x=(P1 x -P0 x ,P2 x -P0 x ,P0 x -P x )
[0094] y=(P1 y -P0 y ,P2 y -P0 y ,P0 y -P y )
[0095] So:
[0096] [uv 1] = x × y
[0097] Finally, u and v can be calculated.
[0098]
[0099]
[0100] in:
[0101] A=(P1.x-P0.x,P2.x-P0.x,P0.xP.x)
[0102] B=(P1.y-P0.y,P2.y-P0.y,P0.yP.y)
[0103] In another possible implementation, if the determined shape is a quadrilateral, calculating the texture coordinates of the vertices of each triangular facet after discretization of each polygonal plane according to the determined shape and the vertex coordinates includes:
[0104] The texture coordinates of the vertices of each triangular facet after each polygonal plane is discretized are calculated by an inverse bilinear interpolation algorithm according to the vertex coordinates.
[0105] The principle of the bilinear interpolation algorithm is as follows: given two points (x0, y0) and (x1, y1), a straight line is constructed based on these two points, and the y value at point x on this line is obtained (x is between x0 and x1). Then we can get the following equation:
[0106]
[0107] This calculation method is called linear interpolation.
[0108] Bilinear interpolation is to apply linear interpolation in two directions. Inverse bilinear interpolation means that we already know the y value and want to reverse the x value, such as Fig. 9 shown.
[0109] Fig. 9 We can get the following equation:
[0110] M=P0+(P1-P0)u
[0111] N=P2+(P3-P2)u
[0112] P=M+(NM)v
[0113] According to the above equation, we can get:
[0114] P(u,v)=P0+(P1-P0)u+(P2-P0)v+(P0-P1+P3-P2)uv
[0115] Assumptions:
[0116] B1=P1-P0
[0117] B2=P2-P0
[0118] B3=P0-P1+P3-P2
[0119] q=P-P0
[0120] So:
[0121] q=B1·u+B2·v+B3·u·v
[0122] like Fig.10 As shown:
[0123] Considering uv as the ij axis, we can get:
[0124] A=B2×B3
[0125] B=B3×q-B1×B2
[0126] C=B1×q
[0127]
[0128] As long as the point is inside the quadrilateral, then B 2 -4AC is always greater than 0. Then substitute the value of v back into the above formula to get the value of u.
[0129]
[0130]
[0131] in,
[0132] A=(p2-p0)×(p0-p1-p2+p3)
[0133] B=(p0-p1-p2+p3)×q-(p1-p0)×(p2-p0)
[0134] C = (p1-p0) × q.
[0135] Step 204: Render the curved surface according to the texture coordinates of each triangular facet.
[0136] Please refer to Fig.11a and Fig.11b , which shows the schematic diagram of the sphere before and after rendering. Fig.12a and Figure 12b , which respectively show schematic diagrams before and after the ring body rendering.
[0137] In summary, by obtaining the proportion of each polygonal plane in all continuous faces; the multiple polygonal planes are continuous faces, which are used to simulate the curved surface; according to the proportion, the vertex coordinates and texture coordinates of each polygonal plane are obtained; according to the vertex coordinates and the texture coordinates, the texture coordinates of the vertices of each triangular face after discretization of each polygonal plane are calculated; and the curved surface is rendered according to the texture coordinates of each triangular face. The problem of poor rendering effect in the existing scheme is solved, and the texture coordinates of each vertex in each face can be calculated for the continuous face, so as to ensure the overall texture continuity of the continuous face and thus improve the rendering effect.
[0138] The present application also provides a texture paving device, which includes a memory and a processor, wherein at least one program instruction is stored in the memory, and the processor implements the above-mentioned method by loading and executing the at least one program instruction.
[0139] The present application also provides a computer storage medium, characterized in that at least one program instruction is stored in the computer storage medium, and the at least one program instruction is loaded and executed by a processor to implement the method as described above.
[0140] The technical features of the above-described embodiments may be arbitrarily combined. To make the description concise, not all possible combinations of the technical features in the above-described embodiments are described. However, as long as there is no contradiction in the combination of these technical features, they should be considered to be within the scope of this specification.
[0141] The above-mentioned embodiments only express several implementation methods of the present invention, and the descriptions thereof are relatively specific and detailed, but they cannot be understood as limiting the scope of the invention patent. It should be pointed out that, for ordinary technicians in this field, several variations and improvements can be made without departing from the concept of the present invention, and these all belong to the protection scope of the present invention. Therefore, the protection scope of the patent of the present invention shall be subject to the attached claims.
Claims
1. A texture paving method, characterized in that: The method comprises: Get the proportion of each polygonal plane in all continuous surfaces; multiple polygonal planes are continuous surfaces, which are used to simulate curved surfaces; Obtaining vertex coordinates and texture coordinates of each polygonal plane according to the ratio; Calculate the texture coordinates of the vertices of each triangular facet after discretization of each polygonal plane according to the vertex coordinates and the texture coordinates; Rendering the surface according to the texture coordinates of each triangle; The step of calculating the texture coordinates of the vertices of each triangular facet after discretization of each polygonal plane according to the vertex coordinates and the texture coordinates comprises: Determine the shape of the polygon constructed by the texture coordinates of the polygonal plane; Calculate the texture coordinates of each vertex of each triangular facet after discretization of each polygonal plane according to the determined shape and the vertex coordinates; If the determined shape is a triangle, calculating the texture coordinates of the vertices of each triangular facet after each polygonal plane is discretized according to the determined shape and the vertex coordinates, comprises: calculating the texture coordinates of the vertices of each triangular facet after each polygonal plane is discretized through a triangle barycentric coordinate system according to the vertex coordinates; If the determined shape is a quadrilateral, the texture coordinates of the vertices of each triangular facet after discretization of each polygonal plane are calculated based on the determined shape and the vertex coordinates, including: calculating the texture coordinates of the vertices of each triangular facet after discretization of each polygonal plane through an inverse bilinear interpolation algorithm based on the vertex coordinates.
2. The method according to claim 1, characterized in that The step of obtaining the vertex coordinates of each polygonal plane includes: Determine the UV direction of the texture based on the direction of the initial surface; Determine the UV direction of the polygonal plane according to the UV direction and adjacent edges; Determine the adjacent side as a reference axis, and determine the farthest opposite side of the adjacent side as a first axis; Determine the connected edge between the reference axis and the first axis as a second axis and a third axis in different directions; The vertex coordinates of the polygonal plane are determined according to four intersection points of the reference axis, the first axis, the second axis and the third axis.
3. The method according to claim 1, characterized in that The step of obtaining the texture coordinates of each polygonal plane includes: Generate a plan graph of the continuous surface according to the shared edge search of the initial surface in a preset manner, and update the lower left corner of the plan graph as the head node; Traversing the plane graph according to the head node in a preset manner to obtain a range of the plane graph; The texture coordinates of the bounding box of each polygonal plane are determined according to the range of the plan view and the size of each continuous face.
4. The method according to claim 3, characterized in that The preset method includes breadth-first search.
5. The method according to any one of claims 2 to 4, characterized in that: The method further comprises: Traverse each continuous surface; An initial face is selected from the continuous faces, wherein the initial face is a quadrilateral and four sides of the quadrilateral are all continuous sides.
6. A texture paving device, characterized in that: The device includes a memory and a processor, wherein at least one program instruction is stored in the memory, and the processor implements the method according to any one of claims 1 to 5 by loading and executing the at least one program instruction.
7. A computer storage medium, characterized in that: The computer storage medium stores at least one program instruction, and the at least one program instruction is loaded and executed by a processor to implement the method according to any one of claims 1 to 5.
