Terrain rendering method and device, electronic equipment and computer readable storage medium
By downsampling the three-dimensional terrain and adjusting the displacement map, it solves the problem of insufficient vertex coordinate description in the existing technology, improves the accuracy and efficiency of terrain rendering, and is suitable for different platforms.
Patent Information
- Application Number
- CN202410722620.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-06-05
- Publication Date
- 2024-10-01
AI Technical Summary
Existing three-dimensional terrain rendering technology requires a large number of redundant vertex coordinates in areas with small gradient changes. On the contrary, in areas with large gradient changes, the vertex density is insufficient, resulting in poor rendering effects.
By downsampling the elevation map of the terrain to be rendered, the terrain grid is obtained, and a displacement map is generated during the process of optimizing the difference in pixel values between the elevation map and the terrain grid, and the vertex coordinates of the terrain grid are adjusted to enhance the terrain grid. geometric accuracy.
It improves the geometric accuracy and efficiency of terrain rendering, reduces the amount of stored geometric data, is suitable for fixed and mobile terminals, and is cross-platform.
Smart Images

Figure CN118736080A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of terrain rendering, and in particular to a terrain rendering method, device, electronic device and computer-readable storage medium. Background Art
[0002] 3D terrain rendering refers to coloring and mapping the 3D modeled terrain. In 3D terrain rendering, a regular grid is generally used to evenly divide the horizontal dimension of the terrain. In the vertex shader, the texture is mapped through the horizontal coordinates to obtain the height displacement information and construct the geometric shape. The problem with this method is that in areas with small gradient changes, a large number of redundant vertex coordinates are required to describe the terrain. Conversely, in areas with large gradient changes, the vertex density is not enough to accurately describe the geometric shape of the terrain, which seriously affects the rendering effect. Summary of the invention
[0003] In view of this, an object of the present invention is to provide a terrain rendering method, device, electronic device and computer-readable storage medium, which can effectively enhance the terrain rendering effect.
[0004] In order to achieve the above purpose, the technical solution adopted by the embodiment of the present invention is as follows:
[0005] In a first aspect, the present invention provides a terrain rendering method, the method comprising:
[0006] Downsampling the elevation map of the terrain to be rendered to obtain a terrain grid; the terrain grid includes a plurality of vertex coordinates;
[0007] determining an initial error based on the terrain grid and the elevation map; the initial error characterizing an initial difference in pixel values between the elevation map and the terrain grid;
[0008] Determining a displacement map according to the elevation map and the initial error; the displacement map is used to record adjustment information corresponding to at least one of the vertex coordinates, the adjustment information being generated in the process of optimizing the difference in pixel values between the elevation map and the terrain grid;
[0009] Terrain rendering is performed according to the terrain grid and the displacement map.
[0010] In an optional implementation, the elevation map includes a plurality of pixel coordinates; and determining the initial error according to the terrain grid and the elevation map includes:
[0011] For each pixel coordinate, determining a target triangle to which the pixel coordinate belongs in the terrain grid; the mapping coordinate of the pixel coordinate in the terrain grid is located on the edge or inside the target triangle;
[0012] Converting the vertex coordinates of the target triangle into corresponding target coordinates in the elevation map according to the downsampling rate;
[0013] Determining the center of gravity coordinates according to the pixel coordinates and the target coordinates;
[0014] Determine a pixel error corresponding to the pixel coordinates according to a pixel value corresponding to the pixel coordinates, the barycenter coordinates, and a pixel value corresponding to the target coordinates;
[0015] The initial error is determined according to the pixel errors corresponding to all pixel coordinates in the elevation map.
[0016] In an optional implementation, the terrain grid includes a plurality of triangles; and determining the target triangle to which the pixel coordinates belong in the terrain grid includes:
[0017] Determine the mapping coordinates of the pixel coordinates in the terrain grid according to the pixel coordinates and the downsampling rate;
[0018] A target triangle is determined from the plurality of triangles according to the mapping coordinates.
[0019] In an optional implementation, determining the center of gravity coordinates according to the pixel coordinates and the target coordinates includes:
[0020] The centroid coordinates are determined according to target coordinates corresponding to one vertex coordinate of the target triangle, target coordinates corresponding to the other two vertex coordinates, and vectors between the pixel coordinates.
[0021] In an optional implementation, determining the pixel error corresponding to the pixel coordinates according to the pixel value corresponding to the pixel coordinates, the barycenter coordinates, and the pixel value corresponding to the target coordinates includes:
[0022] Determine an interpolation value according to the barycenter coordinates and the pixel values corresponding to the target coordinates;
[0023] The absolute value of the difference between the pixel value corresponding to the pixel coordinate and the interpolation value is determined as the pixel error corresponding to the pixel coordinate.
[0024] In an optional implementation, determining a displacement map according to the elevation map and the initial error includes:
[0025] Randomly select any vertex coordinate and generate an offset coordinate of the vertex coordinate within a preset range;
[0026] Using the vertex coordinates as target vertex coordinates, the offset coordinates as target offset coordinates, and determining new errors based on the target vertex coordinates, the target offset coordinates and the elevation map;
[0027] When the new error, the initial error and the current temperature meet the adjustment condition, generating adjustment information corresponding to the target vertex coordinates according to the target vertex coordinates and the target offset coordinates;
[0028] When the current number of iterations does not exceed the iteration threshold, randomly reselect vertex coordinates and generate offset coordinates of the vertex coordinates within a preset range, use the reselected vertex coordinates as the target vertex coordinates, and use the regenerated offset coordinates as the target offset coordinates;
[0029] When the current number of iterations exceeds the iteration threshold, if the new error is less than the error threshold or the current temperature is less than the temperature threshold, generating a displacement map according to the generated adjustment information;
[0030] When the current number of iterations exceeds the iteration threshold and the new error is not less than the error threshold and the current temperature is not less than the temperature threshold, the current temperature is lowered, the current number of iterations is cleared, and the vertex coordinates are randomly selected again and the offset coordinates of the vertex coordinates are generated within a preset range, the re-selected vertex coordinates are used as the target vertex coordinates, and the re-generated offset coordinates are used as the target offset coordinates.
[0031] In an optional implementation, when the new error, the initial error, and the current temperature satisfy an adjustment condition, generating adjustment information corresponding to the target vertex coordinates according to the target vertex coordinates and the target offset coordinates includes:
[0032] If the target vertex coordinates already have adjustment information, the error corresponding to the existing adjustment information is used as the current error; if the target vertex coordinates do not have adjustment information, the initial error is used as the current error;
[0033] When the new error is smaller than the current error, it is determined that the adjustment condition is met;
[0034] When the new error is not less than the current error, determining a transition probability according to the new error, the current error and the current temperature, and when the transition probability is not less than a random probability, determining that an adjustment condition is met;
[0035] When the adjustment condition is met, the adjustment coordinates corresponding to the target vertex coordinates are determined according to the target vertex coordinates and the target offset coordinates, and the pixel values corresponding to the target vertex coordinates, the target offset coordinates and the adjustment coordinates are used as adjustment information corresponding to the target vertex coordinates.
[0036] In a second aspect, the present invention provides a terrain rendering device, the device comprising:
[0037] A processing module, used for downsampling the elevation map of the terrain to be rendered to obtain a terrain grid; the terrain grid includes a plurality of vertex coordinates;
[0038] An adjustment module, configured to determine an initial error according to the terrain grid and the elevation map; the initial error represents an initial difference in pixel values between the elevation map and the terrain grid; determine a displacement map according to the elevation map and the initial error; the displacement map is used to record adjustment information corresponding to at least one of the vertex coordinates, the adjustment information being generated in the process of optimizing the difference in pixel values between the elevation map and the terrain grid;
[0039] A rendering module is used for performing terrain rendering according to the terrain grid and the displacement map.
[0040] In a third aspect, the present invention provides an electronic device, comprising a processor and a memory, wherein the memory stores machine executable instructions that can be executed by the processor, and the processor can execute the machine executable instructions to implement the terrain rendering method described in any of the aforementioned implementations.
[0041] In a fourth aspect, the present invention provides a computer-readable storage medium having a computer program stored thereon, wherein the computer program, when executed by a processor, implements a terrain rendering method as described in any one of the aforementioned embodiments.
[0042] Compared with the prior art, the terrain rendering method, device, electronic device and computer-readable storage medium provided in the embodiments of the present invention downsample the elevation map of the terrain to be rendered to obtain a terrain grid; generate a displacement map in the process of optimizing the difference in pixel values between the elevation map and the terrain grid, and use the displacement map to adjust the vertex coordinates of the terrain grid, and render the terrain at the adjusted vertex positions, thereby improving the geometric accuracy of the terrain grid and enhancing the terrain rendering effect.
[0043] In order to make the above-mentioned objects, features and advantages of the present invention more obvious and easy to understand, preferred embodiments are given below and described in detail with reference to the accompanying drawings. BRIEF DESCRIPTION OF THE DRAWINGS
[0044] In order to more clearly illustrate the technical solutions of the embodiments of the present invention, the drawings required for use in the embodiments are briefly introduced below. It should be understood that the following drawings only show certain embodiments of the present invention and therefore should not be regarded as limiting the scope. For ordinary technicians in this field, other related drawings can be obtained based on these drawings without creative work.
[0045] Figure 1 A schematic flow chart of a terrain rendering method provided by an embodiment of the present invention is shown.
[0046] Figure 2 Shows Figure 1 A flow chart of the sub-steps of step S20.
[0047] Figure 3 Shows Figure 1 A flow chart of the sub-steps of step S30.
[0048] Figure 4 A block diagram of a terrain rendering device provided by an embodiment of the present invention is shown.
[0049] Figure 5 A block diagram of an electronic device provided by an embodiment of the present invention is shown.
[0050] Icons: 100 - electronic device; 110 - memory; 120 - processor; 130 - communication module; 200 - terrain rendering device; 201 - processing module; 202 - adjustment module; 203 - rendering module. DETAILED DESCRIPTION
[0051] The following will be combined with the accompanying drawings in the embodiments of the present invention to clearly and completely describe the technical solutions in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Generally, the components of the embodiments of the present invention described and shown in the drawings here can be arranged and designed in various different configurations.
[0052] Therefore, the following detailed description of the embodiments of the present invention provided in the accompanying drawings is not intended to limit the scope of the invention claimed for protection, but merely represents selected embodiments of the present invention. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without making creative work are within the scope of protection of the present invention.
[0053] It should be noted that relational terms such as "first" and "second" are used only to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Moreover, the terms "include", "comprise" or any other variants thereof are intended to cover non-exclusive inclusion, so that a process, method, article or device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, article or device. In the absence of further restrictions, the elements defined by the sentence "comprise a ..." do not exclude the existence of other identical elements in the process, method, article or device including the elements.
[0054] In the prior art, when rendering three-dimensional terrain, the geometry of the terrain grid is usually a block standard grid, a binary tree tessellation or an irregular grid. Among them, the block standard grid is to divide the complete terrain into multiple regular squares to describe the terrain, the binary tree tessellation is to use a triangular subdivision binary tree to describe the terrain, and the irregular grid is to use a pre-calculated model grid to describe the terrain.
[0055] The inventors have discovered that when using a block standard grid to render terrain, a large number of redundant vertices are required to describe the terrain in areas with small gradient changes. Conversely, in areas with large gradient changes, the vertex density is not sufficient to accurately describe the geometry of the terrain, seriously affecting the rendering effect.
[0056] When using binary tree tessellation to render terrain, it is necessary to recursively determine the tessellation level of triangles based on the observation distance in the tessellation shader. However, the tessellation shader has poor support on mobile terminals and has not been widely used in mobile terminals.
[0057] When using irregular grids to render terrain, geometric calculations are used to ensure that vertices are dense where the gradient changes significantly, and sparse otherwise. The problem with this method is that each piece of terrain needs to store different vertex data and index data, which takes up a large amount of storage space and cannot be reused between plots. The image processor can only bind one irregular grid at a time for terrain rendering, and cannot render terrain concurrently, resulting in low terrain rendering efficiency.
[0058] Based on this, the core idea of the terrain rendering method and device provided by the embodiments of the present invention is to downsample the elevation map of the terrain to be rendered to obtain a terrain grid; generate a displacement map in the process of optimizing the difference in pixel values between the elevation map and the terrain grid, and use the displacement map to adjust the vertex coordinates of the terrain grid, and render the terrain at the adjusted vertex positions, thereby improving the geometric accuracy of the terrain grid and enhancing the terrain rendering effect.
[0059] The embodiments of the present invention are described in detail below with reference to the accompanying drawings.
[0060] Please refer to Figure 1 , Figure 1 A schematic diagram of a flow chart of a terrain rendering method provided by an embodiment of the present invention is shown, and the method comprises the following steps:
[0061] Step S10, downsampling the elevation map of the terrain to be rendered to obtain a terrain grid; the terrain grid includes a plurality of vertex coordinates.
[0062] In an embodiment of the present invention, an elevation map of the terrain to be rendered is obtained, wherein the elevation map may be a high-resolution grayscale image containing elevation information of the terrain to be rendered. The source of the elevation map includes but is not limited to drawing by an artist, satellite remote sensing data, computer generation, etc.
[0063] As a possible implementation, assuming that the size of the elevation map is a square grayscale image of M*M, assuming that the downsampling rate is 2, the elevation map of the terrain to be rendered is downsampled according to the downsampling rate to obtain equidistant terrain grids, and the size of the terrain grid is N*N, where N is half of M. The downsampling rate can be set according to the actual application scenario, and the downsampling rate is generally a power of 2, which is not limited by the present invention.
[0064] Step S20, determining an initial error based on the terrain grid and the elevation map; the initial error represents an initial difference in pixel values between the elevation map and the terrain grid.
[0065] In the embodiment of the present invention, the initial difference of the pixel values between the elevation map and the terrain grid is calculated, and the initial error is obtained according to the initial difference.
[0066] Step S30, determining a displacement map according to the elevation map and the initial error; the displacement map is used to record adjustment information corresponding to at least one vertex coordinate, and the adjustment information is generated in the process of optimizing the difference in pixel values between the elevation map and the terrain grid.
[0067] Step S40, rendering the terrain according to the terrain grid and the displacement map.
[0068] In an embodiment of the present invention, the vertex coordinates in the terrain grid are offset to obtain the adjusted coordinates, and the difference in pixel values between the elevation map and the terrain grid is optimized according to the adjusted coordinates, the corresponding coordinates in the elevation map, and the initial error to obtain the adjustment information corresponding to at least one vertex coordinate, and the displacement map is generated according to the adjustment information. Finally, the terrain grid and the displacement map are transmitted to the graphics processor, and the graphics processor offsets the vertex coordinates in the terrain grid according to the displacement map to obtain the vertex coordinates with smaller geometric errors, and renders the offset vertex coordinates according to the corresponding adjustment information to obtain the final three-dimensional terrain scene.
[0069] In summary, the terrain rendering method provided in the embodiment of the present invention downsamples the elevation map of the terrain to be rendered to obtain a terrain grid; generates a displacement map in the process of optimizing the difference in pixel values between the elevation map and the terrain grid, and uses the displacement map to adjust the vertex coordinates of the terrain grid, and renders the terrain at the adjusted vertex positions, thereby improving the geometric accuracy of the terrain grid and further enhancing the terrain rendering effect.
[0070] In addition, for irregular terrain, the prior art generates corresponding vertex data and index data for each terrain. When processing each terrain, the graphics processor needs to bind the vertex data and index data corresponding to the image. Therefore, the graphics processor can only render each terrain serially, and the rendering efficiency is low. In the embodiment of the present invention, the same terrain grid is used to describe multiple terrains in the same scene, and displacement mapping is used to Figure 1 The adjustment information corresponding to the vertex coordinates of each terrain is described one by one. Therefore, after the graphics processor binds the terrain grid, it can adjust the vertex coordinates to be rendered in parallel according to the displacement map corresponding to each terrain, and render the terrain at the adjusted vertex coordinates, thereby ensuring the reuse of terrain grids in different terrains, improving the efficiency of terrain rendering, and reducing the storage amount of geometric data corresponding to the terrain grids.
[0071] Furthermore, since the solution does not need to use the hardware surface subdivision function, terrain rendering can be performed on fixed terminals or mobile terminals, and has good cross-platform performance.
[0072] Optionally, in practical applications, the elevation map includes multiple pixel coordinates, and the pixel error corresponding to each pixel coordinate is determined one by one according to the elevation map and the terrain grid. Figure 2 , Figure 1 The sub-steps of step S20 may include:
[0073] Step S201 , for each pixel coordinate, determining in the terrain grid the target triangle to which the pixel coordinate belongs; the mapping coordinate of the pixel coordinate in the terrain grid is located on the edge or inside the target triangle.
[0074] In an embodiment of the present invention, each vertex coordinate in the terrain grid is mapped to a pixel coordinate in the elevation map. According to the position of the mapping coordinate corresponding to each pixel coordinate in the elevation map in the terrain grid, the target triangle to which the pixel coordinate belongs is determined. The mapping coordinate is located on any edge of the target triangle or inside the triangular area surrounded by the three edges of the target triangle.
[0075] Step S202: converting the vertex coordinates of the target triangle into corresponding target coordinates in the elevation map according to the downsampling rate.
[0076] In an embodiment of the present invention, the downsampling rate is multiplied by the three vertex coordinates of the target triangle to obtain the corresponding target coordinates in the elevation map. Assuming the downsampling rate is 2 and the pixel coordinate is (1, 0), the three vertex coordinates of the target triangle are (0, 0), (1, 0) and (1, 1). The three vertex coordinates of the target triangle are converted according to the downsampling rate, and the corresponding three target coordinates in the elevation map are (0, 0), (2, 0) and (2, 2).
[0077] Step S203, determining the centroid coordinates according to the pixel coordinates and the target coordinates.
[0078] In the embodiment of the present invention, triangles are needed in the three-dimensional terrain rendering scene, but the triangle itself is a two-dimensional graphic, and it is very troublesome to use two-dimensional triangles in a three-dimensional scene. The problem of using two-dimensional triangles in a three-dimensional scene can be solved by using barycentric coordinates, which are coordinates associated with the triangle surface and unrelated to the three-dimensional coordinate space.
[0079] Step S204, determining the pixel error corresponding to the pixel coordinates according to the pixel value corresponding to the pixel coordinates, the centroid coordinates and the pixel value corresponding to the target coordinates.
[0080] Step S205, determining the initial error according to the pixel errors corresponding to all pixel coordinates in the elevation map.
[0081] In the embodiment of the present invention, each pixel coordinate in the elevation map is used to describe the position of each pixel point, and the pixel value of each pixel point is used to represent the height value of the corresponding point on the ground. The corresponding pixel error is calculated for each pixel coordinate, and the initial error is obtained by summing all the pixel errors in the elevation map, and the initial geometric error of the pixel values corresponding to all the pixel coordinates in the elevation map is maintained using the initial error.
[0082] Optionally, in practical applications, the terrain grid includes a plurality of triangles, and each grid in the terrain grid is composed of two right-angled triangles. Figure 2 The sub-step of determining the target triangle to which the pixel coordinates belong in the terrain grid in step S201 may include:
[0083] The mapping coordinates of the pixel coordinates in the terrain grid are determined according to the pixel coordinates and the down sampling rate; and the target triangle is determined from the plurality of triangles according to the mapping coordinates.
[0084] In the embodiment of the present invention, the mapping coordinates are obtained according to the ratios of the horizontal coordinates and the vertical coordinates of the pixel coordinates to the downsampling rate, and then the target triangle is determined according to the mapping coordinates and the vertex coordinates of multiple adjacent triangles.
[0085] As a possible implementation, assuming that the downsampling rate is 2, the pixel coordinates are (1, 0), and assuming that the rule for dividing the grid into triangles is to connect the coordinates of the upper left and lower right vertices. Then the mapping coordinates of the pixel coordinates in the terrain grid are (0.5, 0), and the coordinates of the two vertices of the target triangle are obtained according to the mapping coordinates, which are (0, 0) and (1, 0), respectively. Combined with the triangle division rule of the terrain grid, the coordinates of the other vertex of the target triangle are obtained as (1, 1).
[0086] As another possible implementation, assume that the downsampling rate is 2, the pixel coordinates are (2, 2), and the rule for dividing the grid into triangles is to connect the coordinates of the upper left and lower right vertices. Then the mapping coordinates of the pixel coordinates in the terrain grid are (1, 1). According to the mapping coordinates, eight adjacent triangles are determined as candidate triangles. The eight candidate triangles share one vertex coordinate, namely the mapping coordinate. Based on the coordinate minimization principle, the triangle with the smallest vertex coordinate is selected from the eight candidate triangles as the target triangle. The three vertex coordinates of the target triangle are (0, 0), (1, 0) and (1, 1) respectively.
[0087] It should be noted that the rules for dividing triangles and determining the target triangles can be formulated according to actual application scenarios, and the present invention is not limited to this.
[0088] Optionally, in practical applications, the centroid coordinates are determined according to the vector between the vertex coordinates and the pixel coordinates of the target triangle. Figure 2 The sub-steps of step S203 may include:
[0089] The centroid coordinates are determined according to the target coordinates corresponding to one of the vertex coordinates of the target triangle and the vectors between the target coordinates corresponding to the other two vertex coordinates and the pixel coordinates.
[0090] As a possible implementation, assuming that the three vertex coordinates of the target triangle are P1, P2, and P3, and the pixel coordinate is P, the calculation formula of the centroid coordinate is as follows:
[0091]
[0092] w 3 =1-w 1 -w 2
[0093] Among them, (w 1 , w 2 , w 3 ) are the centroid coordinates, |.| is the modulus of the vector, × is the cross product, P3P is the vector from P3 to P, P3P2 is the vector from P3 to P2, and P3P1 is the vector from P3 to P1.
[0094] Optionally, in practical applications, the centroid coordinates are used as weights to determine pixel errors corresponding to the pixel coordinates. Figure 2 The sub-steps of step S204 may include:
[0095] An interpolation value is determined according to the pixel values corresponding to the centroid coordinates and the target coordinates; and an absolute value of a difference between the pixel value corresponding to the pixel coordinate and the interpolation value is determined as a pixel error corresponding to the pixel coordinate.
[0096] As a possible implementation, assume that the three vertex coordinates P1, P2 and P3 of the target triangle are mapped to the pixel values corresponding to the target coordinates on the elevation map, z1, z2 and z3 respectively, and the pixel value corresponding to the pixel coordinate P is z'. The calculation formula for the pixel difference is as follows:
[0097] z=w 1 ×z1+w 2 ×z2+w 3 ×z3
[0098] dz=|z′-z|
[0099] Among them, dz is the pixel error corresponding to the pixel coordinate P, and z is the interpolation value.
[0100] Furthermore, the pixel errors corresponding to all pixel coordinates in the elevation map are summed to obtain the initial error. The calculation formula for the initial error is:
[0101]
[0102] Among them, E is the initial error, M is the side length of the elevation map, and M+1 is the elevation. Figure 1 The number of pixel coordinates distributed on the edge, dz i is the pixel error corresponding to the i-th pixel coordinate.
[0103] Optionally, in practical applications, terrain vertices to be rendered with higher geometric accuracy are gradually obtained through iteration. Figure 3 , Figure 1 The sub-steps of step S30 may include:
[0104] Step S301 , randomly selecting any vertex coordinate and generating an offset coordinate of the vertex coordinate within a preset range.
[0105] In an embodiment of the present invention, any vertex coordinate is randomly selected in the terrain grid, and a preset range is determined according to the downsampling rate. Assuming the downsampling rate is M / N, the horizontal and vertical coordinates of the vertex coordinates are randomly determined in the preset range [-N / M, N / M] to obtain the corresponding offset coordinates.
[0106] As a possible implementation, assuming that the downsampling rate is 2, then the preset range is [-0.5, 0.5], and the randomly selected vertex coordinates are (1, 0), then the offset coordinates are determined within the preset range to ensure that the vertex coordinates adjusted according to the offset coordinates have corresponding pixel coordinates in the elevation map. For example, if the offset coordinates are determined to be (-0.5, 0), then the adjusted vertex coordinates are (0.5, 0), and the corresponding pixel coordinates are obtained according to the downsampling rate and the adjusted vertex coordinates, that is, (1, 0). It should be noted that the preset range can be set according to the actual application scenario, and the present invention is not limited to this.
[0107] Step S302: taking the vertex coordinates as target vertex coordinates and the offset coordinates as target offset coordinates.
[0108] Step S303, determining a new error according to the target vertex coordinates, the target offset coordinates and the elevation map.
[0109] In the embodiment of the present invention, the obtained vertex coordinates and offset coordinates are used as the target vertex coordinates and target offset coordinates of this iteration respectively. A temporary grid is constructed according to the target vertex coordinates, target offset coordinates and terrain grid, and a new error is determined according to the temporary grid and the elevation map.
[0110] It is worth mentioning that when calculating the new error, the pixel error can be recalculated for each pixel coordinate in the elevation map, and then the newly obtained pixel errors are accumulated to obtain the new error. It is also possible to recalculate the pixel errors corresponding to the pixel coordinates covered by the affected triangle range according to the triangle range affected by the adjusted coordinates, and then accumulate the pixel errors corresponding to the affected pixel coordinates and the pixel errors corresponding to the unaffected pixel coordinates to obtain the new error. It is worth mentioning that adjusting a vertex coordinate affects up to eight triangles with the adjusted vertex coordinates as vertices.
[0111] Step S304: when the new error, the initial error and the current temperature meet the adjustment conditions, the adjustment information corresponding to the target vertex coordinates is generated according to the target vertex coordinates and the target offset coordinates.
[0112] Step S305, when the current number of iterations does not exceed the iteration threshold, randomly reselect vertex coordinates and generate offset coordinates of the vertex coordinates within a preset range, use the reselected vertex coordinates as target vertex coordinates, and use the regenerated offset coordinates as target offset coordinates.
[0113] In the embodiment of the present invention, during this iteration, when the new error, the initial error and the current temperature do not satisfy the adjustment conditions, there is no need to generate adjustment information, that is, the target vertex coordinates of this iteration do not need to be adjusted.
[0114] Update the number of iterations to obtain the current number of iterations. When the current number of iterations does not exceed the iteration threshold, randomly re-select any vertex coordinates, and generate the offset coordinates of the vertex coordinates within the preset range. The re-selected vertex coordinates are used as the target vertex coordinates, and the re-generated offset coordinates are used as the target offset coordinates. Return to step S303 for the next round of iterations, calculate the new error based on the re-generated target vertex coordinates, target offset coordinates and elevation map, and generate adjustment information corresponding to the target vertex coordinates that meet the adjustment conditions.
[0115] Step S306, when the current number of iterations exceeds the iteration threshold, if the new error is less than the error threshold or the current temperature is less than the temperature threshold, a displacement map is generated according to the generated adjustment information.
[0116] In the embodiment of the present invention, the iteration threshold, error threshold and temperature threshold are all preset in combination with the empirical data of the application scenario. Before terrain rendering, the iteration threshold, error threshold and temperature threshold suitable for the application scenario can be obtained through a large number of tests.
[0117] When the number of iterations exceeds the iteration threshold and the new error is less than the error threshold, or the number of iterations exceeds the iteration threshold and the current temperature is less than the temperature threshold, it means that the iteration termination condition is met. When the iteration termination condition is met, the adjustment information of at least one vertex coordinate is saved as a displacement map, so that the graphics processor adjusts the corresponding vertex coordinates in the terrain grid according to the displacement map, and renders based on the adjusted vertex coordinates.
[0118] Step S307, when the current number of iterations exceeds the iteration threshold and the new error is not less than the error threshold and the current temperature is not less than the temperature threshold, lower the current temperature, clear the current number of iterations, re-randomly select vertex coordinates and generate offset coordinates of the vertex coordinates within a preset range, use the re-selected vertex coordinates as the target vertex coordinates, and use the re-generated offset coordinates as the target offset coordinates.
[0119] In an embodiment of the present invention, when the new error generated in this round of iteration is not less than the error threshold and the current temperature is not less than the temperature threshold, the current iteration number is reset, the current temperature is lowered, the next iteration cycle is entered, and iteration is performed again.
[0120] In a new iteration cycle, any vertex coordinate is randomly selected again and the offset coordinate of the vertex coordinate is generated within a preset range, and the re-selected vertex coordinate is used as the target vertex coordinate, and the re-generated offset coordinate is used as the target offset coordinate, and the process returns to step S303 for the next round of iteration, and the new error is calculated based on the re-generated target vertex coordinate, target offset coordinate and elevation map, and the adjustment information corresponding to the target vertex coordinate that meets the adjustment conditions is generated.
[0121] It should be noted that, in the first iteration, the preset initial temperature is set as the current temperature, and the current temperature is reduced using the preset cooling rate, and the updated current temperature is used as the current temperature of the next iteration cycle. The update formula of the current temperature is:
[0122] T ′ =k×T, k∈(0,1)
[0123] Among them, T ′ is the current temperature after update, T is the current temperature before update, and k is the cooling rate.
[0124] It should be noted that the cooling rate can be adjusted according to the actual application environment, and the present invention is not limited to this.
[0125] Optionally, in practical applications, the geometric accuracy of the terrain grid is continuously optimized by combining the existing adjustment information of the target vertex coordinates, the initial error and the current temperature. Figure 3 The sub-steps of step S303 may include:
[0126] If adjustment information already exists for the target vertex coordinates, the error corresponding to the existing adjustment information is used as the current error; if adjustment information does not exist for the target vertex coordinates, the initial error is used as the current error; when the new error is less than the current error, the adjustment condition is determined to be met; when the new error is not less than the current error, the transfer probability is determined based on the new error, the current error and the current temperature, and when the transfer probability is not lower than the random probability, the adjustment condition is determined to be met; when the adjustment condition is met, the adjustment coordinates corresponding to the target vertex coordinates are determined based on the target vertex coordinates and the target offset coordinates, and the pixel values corresponding to the target vertex coordinates, the target offset coordinates and the adjustment coordinates are used as the adjustment information corresponding to the target vertex coordinates.
[0127] In an embodiment of the present invention, the corresponding adjustment information is obtained according to the target vertex coordinates. If there is no adjustment information, it means that the target vertex coordinates are adjusted for the first time. Then, the adjustment information is compared with the initial error to determine whether the adjustment condition is met, and the adjustment information that meets the adjustment condition is generated. If there is adjustment information, it means that the target vertex coordinates have been adjusted. The error corresponding to the existing adjustment information is compared with the new error. When the adjustment condition is met, the adjustment information corresponding to the target vertex coordinates is updated using the pixel values corresponding to the target vertex coordinates, the target offset coordinates, and the adjustment coordinates. This ensures that the geometric structure of the terrain grid is continuously optimized through the adjustment information, and the geometric error is reduced.
[0128] The calculation formula for calculating the transition probability is as follows:
[0129]
[0130] Among them, P is the transition probability, E ′ is the new error, E is the current error, and T is the current temperature.
[0131] As a possible implementation, assume that vertex coordinates A1, A2, and A1 are selected in sequence as target vertex coordinates. First, the new error corresponding to vertex coordinate A1 is calculated. Since it is the first adjustment, when the new error corresponding to A1 meets the adjustment conditions compared with the initial error, the adjustment information corresponding to A1 is recorded in the displacement map. Then the new error corresponding to vertex coordinate A2 is calculated. When the new error corresponding to A2 does not meet the adjustment conditions, vertex coordinate A2 does not need to be adjusted, and the new error generated when the vertex coordinates are adjusted again is calculated. When the new error corresponding to A1 in this iteration meets the adjustment conditions compared with the error corresponding to the existing adjustment information, the adjustment information generated in this iteration is used to overwrite the existing adjustment information.
[0132] It should be noted that when the adjustment conditions are met, the new errors corresponding to the vertex coordinates can be recorded in the adjustment information, or the correspondence between the vertex coordinates and the new errors can be maintained separately. The present invention does not limit the specific form of obtaining the errors corresponding to the adjustment information.
[0133] Based on the same inventive concept, the embodiment of the present invention further provides a terrain rendering device, the basic principle and technical effects of which are the same as those of the above embodiment. For the sake of brief description, for parts not mentioned in this embodiment, reference may be made to the corresponding contents of the above embodiment.
[0134] Please refer to Figure 4 , Figure 4 A block diagram of a terrain rendering device 200 provided by an embodiment of the present invention is shown. The terrain rendering device 200 includes a processing module 201 , an adjustment module 202 and a rendering module 203 .
[0135] Processing module 201, used for downsampling the elevation map of the terrain to be rendered to obtain a terrain grid; the terrain grid includes a plurality of vertex coordinates;
[0136] The adjustment module 202 is used to determine an initial error based on the terrain grid and the elevation map; the initial error represents the initial difference in pixel values between the elevation map and the terrain grid; determine a displacement map based on the elevation map and the initial error; the displacement map is used to record adjustment information corresponding to at least one vertex coordinate, and the adjustment information is generated in the process of optimizing the difference in pixel values between the elevation map and the terrain grid;
[0137] The rendering module 203 is used to render the terrain according to the terrain grid and the displacement map.
[0138] In summary, the terrain rendering device provided in the embodiment of the present invention downsamples the elevation map of the terrain to be rendered to obtain a terrain grid; generates a displacement map in the process of optimizing the difference in pixel values between the elevation map and the terrain grid, and uses the displacement map to adjust the vertex coordinates of the terrain grid, and performs terrain rendering at the adjusted vertex positions, thereby improving the geometric accuracy of the terrain grid and further enhancing the terrain rendering effect.
[0139] In addition, for irregular terrain, the prior art generates corresponding vertex data and index data for each terrain. When processing each terrain, the graphics processor needs to bind the vertex data and index data corresponding to the image. Therefore, the graphics processor can only render each terrain serially, and the rendering efficiency is low. In the embodiment of the present invention, the same terrain grid is used to describe multiple terrains in the same scene, and displacement mapping is used to Figure 1 The adjustment information corresponding to the vertex coordinates of each terrain is described one by one. Therefore, after the graphics processor binds the terrain grid, it can adjust the vertex coordinates to be rendered in parallel according to the displacement map corresponding to each terrain, and render the terrain at the adjusted vertex coordinates, thereby ensuring the reuse of terrain grids in different terrains, improving the efficiency of terrain rendering, and reducing the storage amount of geometric data corresponding to the terrain grids.
[0140] Furthermore, since the solution does not need to use the hardware surface subdivision function, terrain rendering can be performed on fixed terminals or mobile terminals, and has good cross-platform performance.
[0141] Optionally, the elevation map includes a plurality of pixel coordinates. The adjustment module 202 is specifically used to determine, for each pixel coordinate, in the terrain grid, the target triangle to which the pixel coordinate belongs; the mapping coordinates of the pixel coordinate in the terrain grid are located on the edge or inside the target triangle; the vertex coordinates of the target triangle are converted into corresponding target coordinates in the elevation map according to the downsampling rate; the centroid coordinates are determined according to the pixel coordinates and the target coordinates; the pixel error corresponding to the pixel coordinate is determined according to the pixel value corresponding to the pixel coordinate, the centroid coordinate and the pixel value corresponding to the target coordinate; and the initial error is determined according to the pixel errors corresponding to all pixel coordinates in the elevation map.
[0142] Optionally, the terrain grid includes a plurality of triangles. The adjustment module 202 is specifically configured to determine the mapping coordinates of the pixel coordinates in the terrain grid according to the pixel coordinates and the downsampling rate; and determine the target triangle from the plurality of triangles according to the mapping coordinates.
[0143] Optionally, the adjustment module 202 is specifically configured to determine the centroid coordinates according to the target coordinates corresponding to one of the vertex coordinates of the target triangle and the vectors between the target coordinates corresponding to the other two vertex coordinates and the pixel coordinates.
[0144] Optionally, the adjustment module 202 is specifically configured to determine an interpolation value according to the pixel values corresponding to the centroid coordinates and the target coordinates; and determine an absolute value of a difference between the pixel value corresponding to the pixel coordinate and the interpolation value as a pixel error corresponding to the pixel coordinate.
[0145] Optionally, the adjustment module 202 is specifically used to randomly select any vertex coordinate and generate an offset coordinate of the vertex coordinate within a preset range; use the vertex coordinate as the target vertex coordinate, the offset coordinate as the target offset coordinate, and determine the new error according to the target vertex coordinate, the target offset coordinate and the elevation map; when the new error, the initial error and the current temperature meet the adjustment condition, generate adjustment information corresponding to the target vertex coordinate according to the target vertex coordinate and the target offset coordinate;
[0146] When the current number of iterations does not exceed the iteration threshold, randomly reselect vertex coordinates and generate offset coordinates of the vertex coordinates within a preset range, use the reselected vertex coordinates as the target vertex coordinates, and use the regenerated offset coordinates as the target offset coordinates;
[0147] When the current number of iterations exceeds the iteration threshold, if the new error is less than the error threshold or the current temperature is less than the temperature threshold, a displacement map is generated according to the generated adjustment information;
[0148] When the current number of iterations exceeds the iteration threshold and the new error is not less than the error threshold and the current temperature is not less than the temperature threshold, the current temperature is lowered, the current number of iterations is cleared, and the vertex coordinates are randomly selected again and the offset coordinates of the vertex coordinates are generated within a preset range. The reselected vertex coordinates are used as the target vertex coordinates, and the regenerated offset coordinates are used as the target offset coordinates.
[0149] Optionally, the adjustment module 202 is specifically used to use the error corresponding to the existing adjustment information as the current error if adjustment information already exists for the target vertex coordinates; use the initial error as the current error if adjustment information does not exist for the target vertex coordinates; when the new error is less than the current error, it is determined that the adjustment condition is met; when the new error is not less than the current error, the transition probability is determined based on the new error, the current error and the current temperature, and when the transition probability is not lower than the random probability, it is determined that the adjustment condition is met; when the adjustment condition is met, the adjustment coordinates corresponding to the target vertex coordinates are determined based on the target vertex coordinates and the target offset coordinates, and the pixel values corresponding to the target vertex coordinates, the target offset coordinates and the adjustment coordinates are used as the adjustment information corresponding to the target vertex coordinates.
[0150] Please refer to Figure 5 , Figure 5A block diagram of an electronic device 100 provided in an embodiment of the present invention. The electronic device 100 may be a fixed terminal or a mobile terminal with an image rendering function, such as a personal computer (PC), a personal digital assistant (PDA), a laptop, a tablet computer, a mobile phone, a server, etc., which is not limited in the embodiment of the present invention. The electronic device 100 includes a memory 110, a processor 120, and a communication module 130. The memory 110, the processor 120, and the communication module 130 are electrically connected to each other directly or indirectly to realize data transmission or interaction. For example, these components can be electrically connected to each other through one or more communication buses or signal lines.
[0151] The memory 110 is used to store programs or data. The memory 110 may be, but is not limited to, a random access memory (RAM), a read only memory (ROM), a programmable read-only memory (PROM), an erasable programmable read-only memory (EPROM), an electrically erasable programmable read-only memory (EEPROM), etc.
[0152] The processor 120 is used to read / write data or programs stored in the memory 110 and execute corresponding functions. For example, when the computer program stored in the memory 110 is executed by the processor 120, the terrain rendering method disclosed in the above embodiments can be implemented.
[0153] The communication module 130 is used to establish a communication connection between the electronic device 100 and other communication terminals through a network, and to send and receive data through the network.
[0154] It should be understood that Figure 5 The structure shown is only a schematic diagram of the structure of the electronic device 100. The electronic device 100 may also include Figure 5 More or fewer components as shown, or with Figure 5 Different configurations shown. Figure 5 Each component shown in the figure can be implemented by hardware, software or a combination thereof.
[0155] The embodiment of the present invention further provides a computer-readable storage medium on which a computer program is stored. When the computer program is executed by the processor 120, the terrain rendering method disclosed in the above embodiments is implemented.
[0156] In several embodiments provided by the present invention, it should be understood that the disclosed devices and methods can also be implemented in other ways. The device embodiments described above are merely schematic. For example, the flowcharts and block diagrams in the accompanying drawings show the possible architecture, functions and operations of the devices, methods and computer program products according to multiple embodiments of the present invention. In this regard, each box in the flowchart or block diagram can represent a module, a program segment or a part of a code, and the module, a program segment or a part of a code contains one or more executable instructions for implementing the specified logical functions. It should also be noted that in some alternative implementations, the functions marked in the box can also occur in a different order from the order marked in the accompanying drawings. For example, two consecutive boxes can actually be executed substantially in parallel, and they can sometimes be executed in the opposite order, depending on the functions involved. It should also be noted that each box in the block diagram and / or flowchart, and the combination of boxes in the block diagram and / or flowchart can be implemented with a dedicated hardware-based system that performs a specified function or action, or can be implemented with a combination of dedicated hardware and computer instructions.
[0157] In addition, the functional modules in the various embodiments of the present invention may be integrated together to form an independent part, or each module may exist independently, or two or more modules may be integrated to form an independent part.
[0158] If the functions are implemented in the form of software function modules and sold or used as independent products, they can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present invention, or the part that contributes to the prior art or the part of the technical solution, can be embodied in the form of a software product. The computer software product is stored in a storage medium, including several instructions for enabling a computer device (which can be a personal computer, a server, or a network device, etc.) to perform all or part of the steps of the methods described in each embodiment of the present invention. The aforementioned storage medium includes: various media that can store program codes, such as a USB flash drive, a mobile hard disk, a read-only memory (ROM), a random access memory (RAM), a magnetic disk or an optical disk.
[0159] The above description is only a preferred embodiment of the present invention and is not intended to limit the present invention. For those skilled in the art, the present invention may have various modifications and variations. Any modification, equivalent replacement, improvement, etc. made within the spirit and principle of the present invention shall be included in the protection scope of the present invention.
Claims
1. A terrain rendering method, characterized in that: The method comprises: Downsampling the elevation map of the terrain to be rendered to obtain a terrain grid; the terrain grid includes a plurality of vertex coordinates; determining an initial error based on the terrain grid and the elevation map; the initial error characterizing an initial difference in pixel values between the elevation map and the terrain grid; Determining a displacement map according to the elevation map and the initial error; the displacement map is used to record adjustment information corresponding to at least one of the vertex coordinates, the adjustment information being generated in the process of optimizing the difference in pixel values between the elevation map and the terrain grid; Terrain rendering is performed according to the terrain grid and the displacement map.
2. The terrain rendering method according to claim 1, characterized in that: The elevation map includes a plurality of pixel coordinates; and determining the initial error according to the terrain grid and the elevation map includes: For each pixel coordinate, determining a target triangle to which the pixel coordinate belongs in the terrain grid; the mapping coordinate of the pixel coordinate in the terrain grid is located on the edge or inside the target triangle; Converting the vertex coordinates of the target triangle into corresponding target coordinates in the elevation map according to the downsampling rate; Determining the center of gravity coordinates according to the pixel coordinates and the target coordinates; Determine a pixel error corresponding to the pixel coordinates according to a pixel value corresponding to the pixel coordinates, the barycenter coordinates, and a pixel value corresponding to the target coordinates; The initial error is determined according to the pixel errors corresponding to all pixel coordinates in the elevation map.
3. The terrain rendering method according to claim 2, characterized in that: The terrain grid includes a plurality of triangles; and determining the target triangle to which the pixel coordinates belong in the terrain grid includes: Determine the mapping coordinates of the pixel coordinates in the terrain grid according to the pixel coordinates and the downsampling rate; A target triangle is determined from the plurality of triangles according to the mapping coordinates.
4. The terrain rendering method according to claim 2, characterized in that: The determining of the center of gravity coordinates according to the pixel coordinates and the target coordinates includes: The centroid coordinates are determined according to target coordinates corresponding to one vertex coordinate of the target triangle, target coordinates corresponding to the other two vertex coordinates, and vectors between the pixel coordinates.
5. The terrain rendering method according to claim 2, characterized in that: The determining the pixel error corresponding to the pixel coordinates according to the pixel value corresponding to the pixel coordinates, the barycenter coordinates, and the pixel value corresponding to the target coordinates includes: Determine an interpolation value according to the barycenter coordinates and the pixel values corresponding to the target coordinates; The absolute value of the difference between the pixel value corresponding to the pixel coordinate and the interpolation value is determined as the pixel error corresponding to the pixel coordinate.
6. The terrain rendering method according to claim 1, characterized in that: The step of determining a displacement map according to the elevation map and the initial error comprises: Randomly select any vertex coordinate and generate an offset coordinate of the vertex coordinate within a preset range; Using the vertex coordinates as target vertex coordinates, the offset coordinates as target offset coordinates, and determining new errors based on the target vertex coordinates, the target offset coordinates and the elevation map; When the new error, the initial error and the current temperature meet the adjustment condition, generating adjustment information corresponding to the target vertex coordinates according to the target vertex coordinates and the target offset coordinates; When the current number of iterations does not exceed the iteration threshold, randomly reselect vertex coordinates and generate offset coordinates of the vertex coordinates within a preset range, use the reselected vertex coordinates as the target vertex coordinates, and use the regenerated offset coordinates as the target offset coordinates; When the current number of iterations exceeds the iteration threshold, if the new error is less than the error threshold or the current temperature is less than the temperature threshold, generating a displacement map according to the generated adjustment information; When the current number of iterations exceeds the iteration threshold and the new error is not less than the error threshold and the current temperature is not less than the temperature threshold, the current temperature is lowered, the current number of iterations is cleared, and the vertex coordinates are randomly selected again and the offset coordinates of the vertex coordinates are generated within a preset range, the re-selected vertex coordinates are used as the target vertex coordinates, and the re-generated offset coordinates are used as the target offset coordinates.
7. The terrain rendering method according to claim 6, characterized in that: When the new error, the initial error, and the current temperature meet the adjustment condition, generating adjustment information corresponding to the target vertex coordinates according to the target vertex coordinates and the target offset coordinates, comprises: If the target vertex coordinates already have adjustment information, the error corresponding to the existing adjustment information is used as the current error; if the target vertex coordinates do not have adjustment information, the initial error is used as the current error; When the new error is smaller than the current error, it is determined that the adjustment condition is met; When the new error is not less than the current error, determining a transition probability according to the new error, the current error and the current temperature, and when the transition probability is not less than a random probability, determining that an adjustment condition is met; When the adjustment condition is met, the adjustment coordinates corresponding to the target vertex coordinates are determined according to the target vertex coordinates and the target offset coordinates, and the pixel values corresponding to the target vertex coordinates, the target offset coordinates and the adjustment coordinates are used as adjustment information corresponding to the target vertex coordinates.
8. A terrain rendering device, characterized in that: The device comprises: A processing module, used for downsampling the elevation map of the terrain to be rendered to obtain a terrain grid; the terrain grid includes a plurality of vertex coordinates; An adjustment module, configured to determine an initial error according to the terrain grid and the elevation map; the initial error represents an initial difference in pixel values between the elevation map and the terrain grid; determine a displacement map according to the elevation map and the initial error; the displacement map is used to record adjustment information corresponding to at least one of the vertex coordinates, the adjustment information being generated in the process of optimizing the difference in pixel values between the elevation map and the terrain grid; A rendering module is used for performing terrain rendering according to the terrain grid and the displacement map.
9. An electronic device, characterized in that: It comprises a processor and a memory, wherein the memory stores machine executable instructions that can be executed by the processor, and the processor can execute the machine executable instructions to implement the terrain rendering method described in any one of claims 1-7.
10. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the terrain rendering method according to any one of claims 1 to 7 is implemented.
Citation Information
Cited By
Aircraft positioning method using ToF camera in small celestial body landing process
CN119714306A
