Terrain rendering method, apparatus and electronic device
By sampling the display hierarchy and vertex texture color of model vertices, the number of samplings was reduced, the crack problem in terrain rendering was solved, device performance was improved, and a smooth transition was achieved.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-09-23
- Publication Date
- 2026-04-07
AI Technical Summary
Existing technologies suffer from cracking issues and excessive sampling when rendering large-area terrain, leading to increased device bandwidth overhead, impacting performance, and causing overheating.
By sampling the display level and vertex texture color of model vertices using a vertex-based processing approach, the number of samplings is reduced, and rendering is performed within the interior of model faces to achieve a seamless and smooth transition.
It reduces the bandwidth overhead of the equipment, improves operating performance, avoids equipment overheating, and enables seamless and smooth terrain transitions.
Smart Images

Figure CN115631279B_ABST
Abstract
Description
TECHNICAL FIELD
[0001] The present application relates to the technical field of model rendering, in particular to a terrain rendering method, device and electronic equipment. BACKGROUND
[0002] At present, for rendering a terrain with a large area, a preset texture map is usually sampled for each model vertex to obtain a texture index and a blending weight corresponding to the model vertex, and finally a texture color is obtained by sampling the texture map, and the terrain is rendered according to the texture color and the blending weight. However, since the texture index of adjacent pixels in the preset texture map changes, the rendered terrain usually has a crack problem.
[0003] In the related art, based on the principle of bilinear sampling, the preset texture map is sampled, and the texture colors of four adjacent pixels of the model vertex are sampled to obtain the target texture color corresponding to the model vertex, which can avoid the crack problem of the terrain and realize seamless transition of the terrain. However, in this way, the preset texture map needs to be sampled four times for each model vertex, and the texture map also needs to be sampled four times, so the number of samplings is large, which increases the bandwidth overhead of the device, affects the operation performance of the device, and causes the device to heat up. SUMMARY
[0004] Therefore, the present application aims to provide a terrain rendering method, device and electronic equipment, which samples the display level and the vertex texture color corresponding to the model vertex based on a vertex processing manner, reduces the number of samplings, reduces the bandwidth overhead of the device, improves the operation performance of the device, avoids the device from heating up, and further realizes seamless and smooth transition of the terrain by rendering the internal model position of the model patch.
[0005] In a first aspect, an embodiment of the present application provides a terrain rendering method, which comprises: obtaining a terrain model of a target terrain; wherein the terrain model is composed of a plurality of model patches, the model patch comprises a plurality of model vertices, and the model vertex is preset with a rendering parameter; determining a rendering parameter of an internal model position of the model patch according to the rendering parameter of the model vertex; obtaining a vertex display level corresponding to the model vertex based on a preset level texture map; wherein the pixel points in the level texture map correspond to the model vertices one by one, the pixel points are used to store the display level, and the display level is used to indicate the index of a preset color texture map; determining a position display level corresponding to the internal model position based on the vertex display level and the rendering parameter of the internal model position; sampling the color texture map based on the vertex display level and the position display level to obtain a vertex texture color of the model vertex and a position texture color of the internal model position; and rendering the model patch according to the vertex texture color and the position texture color to obtain a rendering result of the target terrain.
[0006] Secondly, embodiments of the present invention provide a terrain rendering apparatus, comprising: a terrain model acquisition module for acquiring a terrain model of a target terrain; wherein the terrain model is composed of multiple model patches, each model patch including multiple model vertices, and each model vertex having preset rendering parameters; a rendering parameter determination module for determining rendering parameters of the internal model positions of the model patches based on the rendering parameters of the model vertices; a vertex display level acquisition module for acquiring vertex display levels corresponding to model vertices based on preset layer maps; wherein pixels in the layer maps correspond one-to-one with model vertices, pixels are used to store display levels, and display levels are used to indicate the index of preset color maps; a position display level determination module for determining the position display level corresponding to the internal model position based on the vertex display level and the rendering parameters of the internal model position; a texture color sampling module for sampling color maps based on the vertex display level and the position display level to obtain the vertex texture color of the model vertices and the position texture color of the internal model position; and a terrain model rendering module for rendering the model patches based on the vertex texture color and the position texture color to obtain the rendering result of the target terrain.
[0007] Thirdly, embodiments of the present invention provide an electronic device, including a processor and a memory, wherein the memory stores computer-executable instructions that can be executed by the processor, and the processor executes the computer-executable instructions to implement the terrain rendering method of any of the first aspects.
[0008] Fourthly, embodiments of the present invention provide a computer-readable storage medium storing computer-executable instructions, which, when invoked and executed by a processor, cause the processor to implement the terrain rendering method of any of the first aspects.
[0009] The embodiments of the present invention bring the following beneficial effects:
[0010] This invention provides a terrain rendering method, apparatus, and electronic device. The method involves acquiring a terrain model composed of multiple model patches, each containing multiple model vertices. Based on preset rendering parameters for the model vertices, rendering parameters for the internal model positions within each patch are determined. A layered texture map is used to obtain the vertex display layer. Based on the vertex display layer and the rendering parameters for the internal model positions, a positional display layer corresponding to each internal model position is determined. A color map is sampled based on the vertex display layer and the positional display layer to obtain texture colors. The model patches are then rendered according to these texture colors. This method, by sampling the vertex display layer and vertex texture colors, requires fewer sampling operations, reducing bandwidth overhead, improving device performance, and preventing overheating. Furthermore, by rendering the internal model positions within the model patches, a seamless and smooth terrain transition is achieved.
[0011] Other features and advantages of the invention will be set forth in the description which follows, and will be apparent in part from the description, or may be learned by practicing the invention. The objects and other advantages of the invention are realized and obtained in accordance with the structures particularly pointed out in the description, claims and drawings.
[0012] To make the above-mentioned objects, features and advantages of the present invention more apparent and understandable, preferred embodiments are described below in detail with reference to the accompanying drawings. Attached Figure Description
[0013] To more clearly illustrate the specific embodiments of the present invention or the technical solutions in the prior art, the drawings used in the description of the specific embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are some embodiments of the present invention. For those skilled in the art, other drawings can be obtained from these drawings without creative effort.
[0014] Figure 1 A schematic diagram of a rendering result provided in an embodiment of the present invention;
[0015] Figure 2 A flowchart of a terrain rendering method provided in an embodiment of the present invention;
[0016] Figure 3 A schematic diagram of a model patch provided in an embodiment of the present invention;
[0017] Figure 4 A schematic diagram of another model patch provided in an embodiment of the present invention;
[0018] Figure 5 This is a schematic diagram of the structure of a terrain rendering device provided in an embodiment of the present invention;
[0019] Figure 6 This is a schematic diagram of the structure of an electronic device provided in an embodiment of the present invention. Detailed Implementation
[0020] To make the objectives, technical solutions, and advantages of the embodiments of the present invention clearer, the technical solutions of the present invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of the present invention, not all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of the present invention.
[0021] In games with extremely large maps, rich terrain representation is crucial, including elements like beaches, grasslands, and snow-capped mountains. However, conventional terrain rendering methods are computationally expensive on mobile devices. Typically, it's rendered using the following methods:
[0022] First, model generation: Generally, on older mobile platforms, terrain models are generated offline through baking. With the improvement of mobile phone performance, the ability of the GPU (Graphics Processing Unit) to sample textures in the vertex shader is typically utilized. This allows rendering an N×N mesh model. In the vertex shading stage, the height map is read, and the vertex heights of the network model are adjusted based on the height information of each vertex to generate the terrain model. Of course, terrain rendering for very large scenes requires a lot of additional work, such as streaming height data.
[0023] Second, texture blending: If the number of texture maps required for the terrain does not exceed four, a preset map (which can be called a Control Map) can be generated from the blending weight data. The weights of each texture map are stored in the four RGBA channels of the pixels in the preset map. Then, during the fragment shading stage, the preset map is sampled to obtain the weight of each texture map. At the same time, the texture color of each texture map is sampled, and the sum of the products of each texture color and its corresponding weight is calculated to obtain the blending result. The model is then rendered based on the blending result.
[0024] However, if the terrain requires more than four texture maps, at least two preset texture maps need to be generated, which increases the number of samples during the fragment shading stage. Especially for the extremely rich terrain of the open world, it may require 16 texture maps, resulting in 16 samples. Most mobile phone performance cannot support this. Even if the GPU computing power is sufficient, the huge texture reading requires a large bandwidth overhead, which will also cause the phone to overheat.
[0025] In conventional improvement schemes, it's considered that although the total number of textures is large, each region of the terrain generally does not exceed the blending of two texture maps. Therefore, each pixel of the preset texture can store the texture indices of two texture maps and the blending weights of these two texture maps, utilizing exactly four channels. This reduces the number of samplings, avoiding the need to sample every preset texture map and every texture map for every model location.
[0026] However, in the above method, the texture indices of adjacent pixels may change. For example, one pixel might be sampled with texture indices 0 and 1, while another adjacent pixel might be sampled with texture indices 1 and 2. Since the GPU's texture sampler cannot know that other texture maps will be sampled nearby, a color jump will occur between the two pixels with changed texture indices, resulting in cracks in the rendered terrain. For example, as shown... Figure 1 The aforementioned crack.
[0027] In another improvement, bilinear sampling weights can be calculated during the fragment shading stage to address the aforementioned crack problem. The bilinear sampling formula is: p = p1(1-u)(1-v) + p2u(1-v) + p3v(1-u) + p4uv. Specifically, during the fragment shading stage, a UV coordinate is passed in to sample the texture map required for the terrain (e.g., grass, rocks). This UV coordinate can be called mainUV. Another UV coordinate is used to sample the preset texture (i.e., the ControlMap mentioned above) to obtain the texture index (whether the current pixel uses a grass or rock texture). This UV coordinate can be called ctrlUV. Bilinear interpolation is performed on the ControlMap, converting ctrlUV to pixel coordinates. By rounding down and up based on these pixel coordinates, the texture colors of four adjacent pixels (i.e., p1, p2, p3, p4) can be obtained. Then, the decimal part of the converted pixel coordinates (which can be achieved using the frac function) is taken to obtain the uv in the bilinear formula. This involves obtaining the four adjacent pixels to the aforementioned pixel coordinates in the ControlMap, which yields four corresponding texture indices. By sampling the corresponding texture maps based on these four texture indices, four texture colors can be obtained. Each texture color is multiplied by the pre-calculated weight and then summed to achieve a seamless transition.
[0028] However, the above method requires sampling the ControlMap four times and the texture map four times, for a total of eight samplings. This is still a relatively high number of samplings, increasing the device's bandwidth overhead, affecting its performance, and causing it to overheat. Therefore, this invention provides a terrain rendering method, apparatus, and electronic device, which can be applied to mobile phones, tablets, laptops, computers, and other electronic devices.
[0029] To facilitate understanding of this embodiment, a terrain rendering method disclosed in this invention will first be described in detail, such as... Figure 2 As shown, the method includes the following steps:
[0030] Step S202: Obtain the terrain model of the target terrain; wherein, the terrain model is composed of multiple model patches, and each model patch includes multiple model vertices, and the model vertices have preset rendering parameters;
[0031] The aforementioned target terrain typically refers to the terrain of the open world, such as beaches, grasslands, and deserts. The aforementioned terrain model typically refers to a 3D model. Each model vertex not only has preset rendering parameters but also vertex coordinates, which are usually coordinates in the world coordinate system, and also includes vertex height data. The aforementioned model patches are usually composed of model vertices; for example, a model patch formed by three adjacent model vertices is a triangle. The aforementioned model patches include multiple vertices, i.e., the aforementioned model vertices. The aforementioned rendering parameters are usually pixel values, each with three pixel channels. The pixel value is determined based on the value of each channel. For example, if the preset rendering parameters (or pixel values) for a model vertex are red, then the RGB channel of that pixel value is (255, 0, 0), or it could be a normalized value (1, 0, 0). Similarly, if the preset rendering parameters (or pixel values) for a model vertex are green, then the RGB channel of that pixel value is (0, 255, 0), or it could be a normalized value (0, 1, 0).
[0032] In addition, the rendering parameters (i.e. pixel values) of the model vertices in each of the above model patches are different. The target terrain can be specifically generated from the terrain data, which usually includes data such as the height of each vertex.
[0033] Step S204: Determine the rendering parameters of the internal model position of the model facet based on the rendering parameters of the model vertices.
[0034] The rendering parameters for the internal model positions of the aforementioned model facets are typically pixel values, with the same number of channels as the model vertices—three pixel channels. These internal model positions typically comprise multiple locations, each with unique rendering parameters (i.e., pixel values). Specifically, interpolation can be performed on the internal model positions within the model facets, based on the rendering parameters of the model vertices, setting different rendering parameters (i.e., pixel values) for each position. This process can also be called rasterization. Since each vertex and each internal model position includes multiple channels, interpolation of the internal model positions can be performed based on the values of each channel in the model vertices, targeting the corresponding channels of the internal model positions.
[0035] This step is performed on the GPU. Therefore, in actual implementation, the terrain model, which is a 3D model, is usually converted into a 2D model. The rendering parameters for the internal model position of the model facet are determined based on the 2D model. That is, the internal model position of the 2D model usually refers to the internal pixel point.
[0036] Step S206: Based on the preset layer map, obtain the vertex display layer corresponding to the model vertex; wherein, the pixels in the layer map correspond one-to-one with the model vertex, the pixels are used to store the display layer, and the display layer is used to indicate the index of the preset color map.
[0037] The pixels in the aforementioned preset layered texture map store at least one display layer, where different display layers correspond to different color textures. For example, if the display layer of a model vertex is 2, then when sampling color textures later, it is necessary to sample the color texture with display layer 2 or index 2. It should be noted that each color texture has a corresponding preset display layer (or index).
[0038] Each pixel in the aforementioned hierarchical texture map includes four channels (i.e., RGBA channels). In actual implementation, each pixel in the hierarchical texture map can store one display level, which is the display level of the color map with the highest blending weight corresponding to the model vertex. Alternatively, each pixel in the hierarchical texture map can store two display levels, which are the display levels of the two color maps with the highest blending weight corresponding to the model vertices. When a pixel in the hierarchical texture map stores two display levels, it usually also stores the blending weight of the color map corresponding to each display level. Furthermore, the pixels in the aforementioned hierarchical texture map correspond to the vertices of the model points in the terrain model.
[0039] In actual implementation, for each vertex in the model facet, a hierarchical texture is sampled. Specifically, the display level stored in the pixel corresponding to that vertex coordinate is sampled; this is the vertex display level mentioned above. Each model vertex can have one or two display levels, determined by the number of display levels stored in each pixel of the hierarchical texture. Furthermore, model vertices include multiple pixel channels; therefore, the vertex display levels obtained by sampling the hierarchical texture are always the display levels corresponding to a specific channel of the model vertex. For example, if a model vertex is red, with a pixel value of (1,0,0), then the vertex display level corresponding to that model vertex is the display level corresponding to the R channel.
[0040] Step S208: Determine the position display level corresponding to the internal model position based on the rendering parameters of the vertex display level and the internal model position;
[0041] To improve the transition effect of terrain rendering results, it is necessary to render the internal model positions within the model patches. This requires determining the display level corresponding to the internal model positions. Since terrain data typically only records the model vertex data and not the internal model position data, after obtaining the rendering parameters for the internal model positions, the corresponding position display level can be determined based on the vertex display level and the internal model position rendering parameters. The aforementioned position display levels corresponding to the internal model positions usually include multiple levels. If each channel of the internal model position has a value, typically each channel will determine a corresponding position display level.
[0042] Specifically, for each vertex in the model patch, the steps of determining the display level corresponding to the internal model position are performed sequentially. For example, for the vertex display level of the first model vertex in the model patch, the display level corresponding to the first channel of the internal model position can be determined; for the vertex display level of the second model vertex in the model patch, the display level corresponding to the second channel of the internal model position can be determined, and so on. The display level corresponding to the internal model position can be calculated using a linear interpolation formula.
[0043] For example, for the simplest linear interpolation, p = p0(1-t) + p1t; where p is the interpolation value, if p0 is 0, then... If p1 is 0, then In other words, if either p0 or p1 is 0, then p0 or p1 can be obtained through interpolation. In this embodiment, this feature can be used to reconstruct the display level corresponding to the internal model position based on the vertex display level and the rendering parameters of the internal model position. Assuming we are rendering a model facet, the preset rendering parameters for each model vertex in the facet are red (pixel value 1, 0, 0), green (pixel value 0, 1, 0), and blue (pixel value 0, 0, 1), meaning each channel of the three model vertices has a 0. Therefore, each channel of the internal model position will be interpolated from 0 to 1, or from 1 to 0. This perfectly satisfies the above conclusion. Through the interpolation result, i.e., the rendering parameters of the internal model position, the display level corresponding to that position can be deduced. If the rendering is done on the red model vertex, after sampling the vertex display level of the red model point, it can be multiplied by the rendering parameters of the internal model position (i.e., the value of the R channel) and then divided by the rendering parameters to obtain the position display level of the R channel of the internal model position. The position display levels of other colored model vertices in the rendering model patch can also be obtained in the same way as above, and then the position display levels corresponding to the internal model positions can be obtained.
[0044] Step S210: Based on the vertex display level and position display level, sample the color map to obtain the vertex texture color of the model vertex and the position texture color of the internal model position;
[0045] Specifically, the first color map corresponding to the model vertex can be determined based on the vertex display level corresponding to the model vertex, and the second color map corresponding to the internal model position can be determined based on the position display level corresponding to the internal model position. Then, the texture color of the pixel corresponding to the model vertex in the first color map is sampled, which is the vertex texture color mentioned above. The texture color of the pixel corresponding to the internal model position in the second color map is sampled, which is the position texture color mentioned above.
[0046] Since the vertex display levels corresponding to the vertices in the above model may be one or two, the vertex texture colors of the above model vertices may also be one or two. Similarly, the position display levels corresponding to the internal model positions are also multiple, therefore the position texture colors of the above internal model positions may also be multiple.
[0047] Step S212: Render the model facets based on vertex texture color and position texture color to obtain the rendering result of the target terrain.
[0048] In practice, rendering is typically performed on a per-model-plane basis. After obtaining the vertex texture color of each model vertex in the plane, if each model vertex has only one vertex texture color, that color is rendered to the corresponding model vertex. If each model vertex has two vertex texture colors, the two colors are added together, or multiplied by their respective blending weights and then added together. The result is then rendered to the corresponding model vertex. After obtaining the position texture colors of the internal model locations within the plane, since each internal model location has multiple position texture colors, these multiple position texture colors can be added together, or each position texture color can be multiplied by its corresponding weight and then added together. The result is then rendered to the corresponding internal model location, resulting in the rendered model plane. Rendering each model plane in the same way yields the rendering result of the target terrain.
[0049] This invention provides a terrain rendering method that obtains a terrain model composed of multiple model patches, each containing multiple model vertices. Based on preset rendering parameters for the model vertices, rendering parameters for the internal model positions within the model patches are determined. A vertex display level is obtained based on a layered texture map. The positional display level corresponding to the internal model position is determined based on the vertex display level and the rendering parameters for the internal model positions. A color map is sampled based on the vertex display level and the positional display level to obtain texture colors. The model patches are then rendered based on these texture colors. This method, by sampling vertex display levels and vertex texture colors for model vertices, requires fewer sampling operations, reducing device bandwidth overhead, improving device performance, and preventing overheating. Furthermore, by rendering the internal model positions within the model patches, a seamless and smooth terrain transition is achieved.
[0050] The above rendering parameters include pixel values; in step S204 above, the step of determining the rendering parameters of the internal model position of the model facet based on the rendering parameters of the model vertices is implemented as follows: based on the pixel values of the model vertices in the model facet, the internal model position of the model facet is linearly interpolated to obtain the interpolated pixel values of the internal model position of the model facet.
[0051] Specifically, rasterization converts the vertex data of the model in the model patch into fragments, which is the process of converting a 3D model into a 2D image. The internal model positions are called internal pixels. Then, based on the preset pixel values of the model vertices, interpolation is performed on each internal pixel. Specifically, linear interpolation can be used, based on the values of each channel between every two model vertices, to linearly interpolate the internal pixels, thus obtaining the pixel value of each channel within the internal pixel, i.e., the interpolated pixel value mentioned above.
[0052] The above model facet is a triangle, and the model vertices in the triangle include the first model vertex, the second model vertex, and the third model vertex; the rendering parameter of the first model vertex is the first pixel value, the rendering parameter of the second model vertex is the second pixel value, and the rendering parameter of the third model vertex is the third pixel value.
[0053] One possible implementation: Based on the first pixel value of the first model vertex, the second pixel value of the second model vertex, and the third pixel value of the third model vertex in the model patch, perform linear interpolation on the internal model position of the model patch to obtain the interpolated pixel value of the internal model position of the model patch.
[0054] For example, such as Figure 3As shown, taking the model facet of this right-angled triangle as an example, a1, a2, and a3 are model vertices. a1 is red with a pixel value of (1,0,0), a2 is green with a pixel value of (0,1,0), and a3 is blue with a pixel value of (0,0,1). For each channel, starting from a1 to a2, interpolation calculations are performed for each row, continuing until a3, to obtain the interpolated pixel values of the internal model positions of the model facet.
[0055] The aforementioned model facet is a triangle, and the model vertices in this triangle include a first model vertex, a second model vertex, and a third model vertex; the rendering parameter of the first model vertex is the first pixel value, the rendering parameter of the second model vertex is the second pixel value, and the rendering parameter of the third model vertex is the third pixel value; the first channel of the first pixel value is the first value, and the second and third channels of the first pixel value are the second values; the second channel of the second pixel value is the first value, and the first and third channels of the second pixel value are the second values; the third channel of the third pixel value is the first value, and the first and second channels of the third pixel value are the second values; the first value and the second value are different.
[0056] In this embodiment, the aforementioned triangle refers to a right-angled triangle. The first pixel value can be red, the second pixel value can be green, and the third pixel value can be blue; that is, the first channel is the R channel, the second channel is the G channel, and the third channel is the B channel. The first value is 1, and the second value is 0. In other words, the pixel value of the first model vertex is (1, 0, 0), the pixel value of the second model vertex is (0, 1, 0), and the pixel value of the third model vertex is (0, 0, 1). This method utilizes the characteristics of linear interpolation, allowing two channels of each model vertex to be set to 0, facilitating the subsequent reconstruction of the internal model's position display hierarchy.
[0057] In the above terrain model, the model vertices in each model patch are the first pixel value, the second quality value, and the third pixel value, which are unique to each other.
[0058] Based on the first pixel value, the second pixel value, and the third pixel value mentioned above, the interpolated pixel value is obtained by interpolating the internal model position of the model patch. The values of the first channel, the second channel, and the third channel of the interpolated pixel value are all greater than the second value and less than the first value.
[0059] Since interpolation is performed between 0 and 1, the values of the first, second, and third channels of the interpolated pixel values are all greater than 0 and less than 1. In this method, by interpolating between 0 and 1, the channel values of the internal model position can represent the UV coordinates of that position.
[0060] The following describes a possible implementation of step S206, which involves obtaining the vertex display level corresponding to the model vertices based on a preset layered texture map:
[0061] (1) Obtain the vertex coordinates of the model vertices in the model patch, and convert the vertex coordinates of the model vertices in the model patch into the first UV coordinates;
[0062] (2) Based on the first UV coordinates, the display level stored by the pixel corresponding to the model vertex in the sampling layer map is obtained to obtain the vertex display level corresponding to the model vertex; wherein, the pixel in the layer map stores at least one display level, and the pixel in the layer map corresponds to the model vertex of the terrain model.
[0063] The vertex coordinates of the aforementioned model vertices are based on the world coordinate system. Specifically, during the vertex shading stage, based on the correspondence between the UV controls of the terrain model and the hierarchical map, the vertex coordinates are converted into first UV coordinates. These first UV coordinates are used to collect the pixels corresponding to the model vertices in the hierarchical map and obtain the display level stored in that pixel. The display level stored in the pixels of the hierarchical map is pre-set through the terrain data; a pixel can store one or two display levels, along with their corresponding blending weights. Furthermore, the terrain data includes texture data, i.e., which texture maps the terrain requires.
[0064] (such as grass textures, stone textures, etc.), and blending data, which is the blending weight of each texture map used at each location in the terrain.
[0065] The rendering parameters for the internal model position of the aforementioned model patch include interpolated pixel values; the following describes step S208, which involves determining the position display level corresponding to the internal model position based on the vertex display level and the rendering parameters of the internal model position, with one possible implementation:
[0066] Step A: In the vertex shader, calculate the product of the vertex display level and the interpolated pixel value of the internal model position of the model face;
[0067] In actual implementation, calculations need to be performed for each channel. This involves calculating the value of each model vertex in the model patch, or multiplying the display level of the vertex corresponding to each channel by the value of the corresponding channel at the internal model position of the model patch.
[0068] The model vertices in the above model patch include the first model vertex, the second model vertex, and the third model vertex; the vertex display levels corresponding to the model vertices include: the first vertex display level corresponding to the first model vertex, the second vertex display level corresponding to the second model vertex, and the third vertex display level corresponding to the third model vertex.
[0069] One possible implementation: Calculate the first product of the display level of the first vertex and the value of the first channel of the interpolated pixel value; calculate the second product of the display level of the second vertex and the value of the second channel of the interpolated pixel value; calculate the third product of the display level of the third vertex and the value of the third channel of the interpolated pixel value.
[0070] For example, if the first vertex corresponding to the first model vertex has a display level of "2" and the value of the first channel of the interpolated pixel value is 0.3, then the first product value is 0.6; if the second vertex corresponding to the second model vertex has a display level of "3" and the value of the second channel of the interpolated pixel value is 0.5, then the second product value is 1.5; if the third vertex corresponding to the third model vertex has a display level of "4" and the value of the third channel of the interpolated pixel value is 0.2, then the third product value is 0.8.
[0071] Step B: Pass the product value into the fragment shader. In the fragment shader, calculate the ratio of the product value to the interpolated pixel value of the internal model position. Determine the display level of the position corresponding to the internal model position of the model facet.
[0072] One possible implementation: Calculate a first ratio of the first product value to the value of the first channel of the interpolated pixel value; calculate a second ratio of the second product value to the value of the second channel of the interpolated pixel value; calculate a third ratio of the third product value to the value of the third channel of the interpolated pixel value; determine the first ratio as the first position display level corresponding to the first channel of the internal model position, determine the second ratio as the second position display level corresponding to the second channel of the model position, and determine the third ratio as the third position display level corresponding to the third channel of the model position.
[0073] For example, if the first product value is 0.6 and the value of the first channel of the interpolated pixel value is 0.3, then the first ratio is 2. If the second product value is 1.5 and the value of the second channel of the interpolated pixel value is 0.5, then the second ratio is 3. If the third product value is 0.8 and the value of the third channel of the interpolated pixel value is 0.2, then the third ratio is 4. The first ratio of 2 is determined as the first display level corresponding to the first channel of the internal model position, the second ratio of 3 is determined as the second display level corresponding to the second channel of the model position, and the third ratio of 4 is determined as the third display level corresponding to the third channel of the model position. Finally, the display level corresponding to the internal model position is (2, 3, 4).
[0074] In the above method, only one layer map sampling is performed during the vertex shading stage, and it is a vertex-based sampling method, which greatly reduces the number of samplings compared to pixel-based sampling methods. In addition, by making full use of the characteristics of linear interpolation, different color values and interpolated pixel values can be set for the model vertices of the model facets to restore the display layer corresponding to the internal model position, thereby improving the rendering effect of the model.
[0075] The following describes a possible implementation of step S208, which involves sampling color maps based on vertex display level and position display level to obtain the vertex texture color of the model vertices and the position texture color of the internal model positions:
[0076] (1) Obtain the vertex coordinates of the model vertices in the model patch, convert the vertex coordinates of the model vertices in the model patch into second UV coordinates, and convert the position coordinates of the internal model positions in the model patch into third UV coordinates;
[0077] Specifically, because the correspondence between hierarchical textures and terrain models differs from that between color textures and terrain models, it is necessary to convert the vertex coordinates of the model vertices in the model patches into second UV coordinates. These second UV coordinates differ from the aforementioned first UV coordinates; they indicate the pixels in the color texture corresponding to the model vertices. Similarly, the third UV coordinates indicate the pixels in the color texture corresponding to the positions of the internal model elements.
[0078] (2) Based on the second UV coordinates, sample the color map corresponding to the vertex display layer to obtain the vertex texture color of the model vertex in the model facet;
[0079] Specifically, first obtain the target color map corresponding to the vertex display layer of the model vertex, then sample the texture color of the pixel corresponding to the second UV coordinate in the target color map to obtain the vertex texture color of the model vertex.
[0080] The model vertices in the aforementioned model patch include a first model vertex, a second model vertex, and a third model vertex; the aforementioned vertex display hierarchy includes: the first vertex display hierarchy corresponding to the first model vertex, the second vertex display hierarchy corresponding to the second model vertex, and the third vertex display hierarchy corresponding to the third model vertex. More precisely, it should be the first vertex display hierarchy corresponding to the first channel of the first model vertex, the second vertex display hierarchy corresponding to the second channel of the second model vertex, and the third vertex display hierarchy corresponding to the third channel of the third model vertex.
[0081] One possible implementation: Sample the texture color of the pixel corresponding to the second UV coordinate of the first model vertex in the color map corresponding to the first vertex display layer to obtain the first vertex texture color of the first model vertex; sample the texture color of the pixel corresponding to the second UV coordinate of the second model vertex in the color map corresponding to the second vertex display layer to obtain the second vertex texture color of the second model vertex; sample the texture color of the pixel corresponding to the second UV coordinate of the third model vertex in the color map corresponding to the third vertex display layer to obtain the third vertex texture color of the third model vertex.
[0082] (3) Based on the third UV coordinates, the color map corresponding to the sampling position display layer is obtained to obtain the position texture color of the internal model position in the model patch; wherein, the color map stores the texture color of the rendered terrain model.
[0083] Similarly, by first obtaining the target color map corresponding to the display layer of the internal model position, and then sampling the texture color of the pixel corresponding to the third UV coordinate in the target color map, the vertex texture color of the internal model position can be obtained.
[0084] The position display levels corresponding to the aforementioned internal model positions include: the first position display level corresponding to the first channel of the internal model position, the second position display level corresponding to the second channel of the internal model position, and the third position display level corresponding to the third channel of the internal model position.
[0085] One possible implementation: Sample the texture color of the pixel corresponding to the third UV coordinate in the color map corresponding to the first position display layer to obtain the first position texture color of the first channel of the internal pixel position in the model patch; sample the texture color of the pixel corresponding to the third UV coordinate in the color map corresponding to the second position display layer to obtain the second position texture color of the second channel of the internal model position in the model patch; sample the texture color of the pixel corresponding to the third UV coordinate in the color map corresponding to the third position display layer to obtain the third position texture color of the third channel of the internal model position in the model patch.
[0086] The above method can be represented in code as follows:
[0087] One for each of the three RGB channels. The pseudocode is as follows:
[0088]
[0089]
[0090] In the above method, only one layer map sampling is required for each model vertex, and only one color map sampling is required for each model vertex. For each internal model position, only three color map samplings are required. This not only reduces the number of samplings and improves the device's operating performance, but also improves the rendering effect.
[0091] The vertex texture colors of the above model vertices include: the first vertex texture color of the first model vertex, the second vertex texture color of the second model vertex, and the third vertex texture color of the third model vertex;
[0092] The positional texture color of the aforementioned internal model location includes: the first positional texture color of the first channel of the internal model location, the second positional texture color of the second channel of the internal model location, and the third positional texture color of the third channel of the internal model location.
[0093] Step S210 above, which involves rendering model patches based on vertex texture colors and position texture colors to obtain the rendering result of the target terrain, can be implemented in one possible way:
[0094] Step C: Render the first model vertex, the second model vertex, and the third model vertex in the model facet according to the texture colors of the first vertex, the second vertex, and the third vertex, respectively.
[0095] Specifically, if the first vertex texture color is one, the second vertex texture color is one, and the third vertex texture color is one, the first vertex texture color can be rendered to the first model vertex in the model facet, the second vertex texture color can be rendered to the second model vertex in the model facet, and the third vertex texture color can be rendered to the third model vertex in the model facet.
[0096] If there are multiple first vertex texture colors, the final first vertex texture color can be determined according to the corresponding weights, and the final first vertex texture color can be rendered to the first model vertex in the model facet. For the second and third vertex texture colors, the corresponding second and third model vertices can also be rendered in the same way.
[0097] Step D: Based on the texture color of the first position, the texture color of the second position, and the texture color of the third position, render the internal model position in the model patch to obtain the rendering result of the target terrain.
[0098] Specifically, the texture colors at the first, second, and third positions can be added together to obtain the target position texture color. This target position texture color is then rendered onto the internal model position within the model patch, resulting in the rendered model patch and consequently, the rendered target terrain. Alternatively, a weighted calculation can be performed based on the weight of each texture color to obtain the target position texture color, which is then rendered onto the internal model position within the model patch.
[0099] The above method not only renders the model vertices but also the internal model positions, avoiding the problem of cracks in the rendering results and thus improving the rendering effect.
[0100] In step D above, the step of rendering the internal model position in the model facet based on the first position texture color, the second position texture color, and the third position texture color can be implemented in one possible way: Calculate the sum of the first position texture color, the second position texture color, and the third position texture color to obtain the target position texture color; then render the internal model position in the model facet based on the target position texture color. In this method, the weight of each position texture color is not considered; the first position texture color, the second position texture color, and the third position texture color are directly added together to render the internal model position in the model facet, avoiding the problem of cracks in the rendering result and thus improving the rendering effect.
[0101] Since the above method uses interpolation within a triangle and lacks diagonal weights for bilinear sampling, a triangular transition shape will appear. To further improve the rendering effect and perfectly restore the original terrain effect, complete bilinear interpolation needs to be implemented.
[0102] Reviewing the principle of bilinear interpolation sampling, in a texture, let p1, p2, p3, and p4 be the colors of four adjacent pixels on the texture, with p1 at the bottom left, p2 at the bottom right, p3 at the top left, and p4 at the top right. There is a texture coordinate uv∈[0,1] located between these four pixels. The bilinear sampling process is as follows:
[0103] P′=p1(1-u)+p2*u
[0104] P″=p3(1-u)+p4*u
[0105] P = P′(1-v) + P″v
[0106] Substituting P′ and P″, we get: P=p1(1-u)(1-v)+p2u(1-v)+p3(1-u)v+p4*uv; According to this formula, bilinear sampling generates 4 weights, which serve as a transition.
[0107] Based on this, the rendering parameters of the model vertices are pixel values; after obtaining the vertex display level corresponding to the model vertex by sampling the display level of the pixels corresponding to the model vertex in the sampling layer map according to the first UV coordinates, the above method further includes:
[0108] Step E: Based on the pixel values of the model vertices and the first UV coordinates, sample the display layer stored in the pixel corresponding to the fourth model vertex in the layer texture map to obtain the fourth vertex display layer corresponding to the fourth model vertex; wherein, the fourth model vertex is adjacent to the model vertices in the model patch, and the fourth model vertex and the model vertices in the model patch can form a rectangle;
[0109] In the aforementioned embodiments, only the RGB channels were used for each model vertex and its internal model position; one alpha channel was left unused. This alpha channel could be used to supplement the information of the fourth model vertex. For example, as shown... Figure 4 As shown, a4 is the fourth model vertex mentioned above. Specifically, in the vertex shader, the pixel value of the currently executing model vertex can be determined. If it is the first model vertex a1, it will be shifted to the upper right. If it is the second model vertex a2, it will be shifted upward. If it is the third model vertex a3, it will be shifted to the right. This allows the display level of the pixel corresponding to the fourth model vertex to be sampled, which is the fourth vertex display level mentioned above.
[0110] Step F: Display the fourth vertex in the fourth channel of the model vertices stored in the model facet.
[0111] The fourth vertex display level can be stored in the fourth channel of the currently executing model vertex in the model facet, namely the Alpha channel.
[0112] Step G: Convert the fourth model vertex into the fourth UV coordinate; sample the texture color of the pixel corresponding to the fourth UV coordinate in the color map corresponding to the fourth vertex display layer to obtain the fourth position texture color of the fourth channel of the internal model position in the model patch.
[0113] Specifically, the fourth vertex display layer can be stored in the fourth channel of the internal model position. Then, based on the third UV coordinates transformed from the internal model position, the color map corresponding to the fourth vertex display layer can be sampled to obtain the fourth position texture color of the fourth channel of the internal model position in the model patch. Alternatively, after sampling the texture color of the pixel corresponding to the fourth UV coordinate, it can be stored in the fourth channel of the internal model position in the model patch to obtain the fourth position texture color of the fourth channel of the internal model position. In this method, although one more vertex sampling is added, that is, four pixel samplings are performed, but the rendering effect is improved. It is usually used on high-end devices. The aforementioned method that only performs three pixel samplings is usually used on low-end devices.
[0114] In the above method, by sampling the display level corresponding to the fourth model vertex, the internal model position can obtain the texture color corresponding to the diagonal vertex, avoiding the appearance of a triangular shape transition in the rendering result and further improving the rendering effect.
[0115] Based on steps E-F above, and in step D above, the step of rendering the internal model positions in the model patch according to the first position texture color, the second position texture color, and the third position texture color to obtain the rendering result of the target terrain, another possible implementation is as follows:
[0116] Based on the interpolated pixel values of the internal model position, determine the UV coordinates of the internal model position; calculate the target position texture color of the internal model position according to the following formula: p=p1(1-u)(1-v)+p2u(1-v)+p3v(1-u)+p4uv where p is the target position texture color, p1 is the first position texture color, p2 is the second position texture color, p3 is the third position texture color, p4 is the fourth position texture color, and (u,v) is the UV coordinates of the internal model position; render the internal model position in the model patch according to the target position texture color to obtain the rendering result of the target terrain.
[0117] Since the interpolated pixel values are all between 0 and 1, and during linear interpolation, each channel changes from 0 to 1 or 1 to 0, the UV coordinates of the internal model position can be determined based on the interpolated pixel values. For example, depending on the interpolation method, the value of the second channel in the interpolated pixel values of the internal model position can be determined as 'u', and the value of the third channel can be determined as 'v'. Alternatively, the difference between 1 and the value of the first channel in the interpolated pixel values of the internal model position can be used to determine 'u', and the value of the second channel can be determined as 'v'. The specific determination method depends on the specific interpolation method used.
[0118] After determining u and v, we can substitute u, v, and the texture colors at the first, second, third, and fourth positions p1, p2, p3, and p4 into p = p1(1-u)(1-v) + p2u(1-v) + p3v(1-u) + p4uv to obtain the texture color at the target position. Then, we can render the target position color to the corresponding internal model position.
[0119] In the above method, the weights of bilinear interpolation are determined by interpolating pixel values. By utilizing the characteristics of bilinear sampling, the weighted values of the texture colors corresponding to each vertex around the internal model position can be calculated, avoiding the appearance of triangular transition shapes in the rendering results and further improving the rendering effect.
[0120] One possible implementation of the above step of determining the UV coordinates of the internal model position based on the interpolated pixel values of the internal model position is as follows: the difference between the value of the first channel and the interpolated pixel value is determined as the u of the UV coordinate; the value of the second channel of the interpolated pixel value is determined as the v of the UV coordinate.
[0121] For example, observe Figure 3 As shown, the vertex colors of a1, a2, and a3 are red, green, and blue, respectively. Observing the R channel, from a1 to a2, the interpolated pixel value p1 (the value of the first channel) changes from 1 to 0; observing the G channel, from a1 to a2, the interpolated pixel value p2 (the value of the second channel) changes from 0 to 1. Therefore, u = 1 - Color.r, v = Color.g, where Color.r is the value of the interpolated pixel value in the first channel, and Color.g is the value of the interpolated pixel value in the second channel.
[0122] The steps described above, which render the first model vertex, second model vertex, and third model vertex in the model facet based on the first vertex texture color, the second vertex texture color, and the third vertex texture color, respectively, include: if there are multiple first vertex texture colors, calculating the sum of the products of each first vertex texture color and its blending weight to obtain the first target vertex texture color; if there are multiple second vertex texture colors, calculating the sum of the products of each second vertex texture color and its blending weight to obtain the second target vertex texture color; if there are multiple third vertex texture colors, calculating the sum of the products of each third vertex texture color and its blending weight to obtain the third target vertex texture color; wherein, the blending weight is obtained by sampling a hierarchical texture map, and the hierarchical texture map stores multiple display hierarchies and their blending weights; and rendering the first model vertex, second model vertex, and third model vertex in the triangle based on the first target vertex texture color, the second target vertex texture color, and the third target vertex texture color, respectively.
[0123] If the first vertex texture color includes multiple elements, meaning the vertex display level corresponding to the first model vertex includes multiple elements, then the hierarchical map stores multiple display levels, along with the blending weights corresponding to each display level. The statement that the vertex display level corresponding to the first model vertex includes multiple elements typically means that the vertex display level corresponding to the first model vertex includes two elements. In the above method, by storing multiple display levels in the hierarchical map, and also storing the blending weights corresponding to each display level, the rendering effect can be further improved.
[0124] In the aforementioned method, pixel-level sampling in related technologies is replaced by vertex-level sampling. Vertices are relatively sparse, while pixels fill the entire screen, so the number of sampling operations is greatly reduced.
[0125] Corresponding to the above method embodiments, this invention provides a terrain rendering device, such as... Figure 5 As shown. The device includes:
[0126] The terrain model acquisition module 51 is used to acquire the terrain model of the target terrain; wherein, the terrain model is composed of multiple model patches, and each model patch includes multiple model vertices, and the model vertices have preset rendering parameters;
[0127] The rendering parameter determination module 52 is used to determine the rendering parameters of the internal model position of the model facet based on the rendering parameters of the model vertices.
[0128] The vertex display layer acquisition module 53 is used to acquire the vertex display layer corresponding to the model vertex based on the preset layer map; wherein, the pixels in the layer map correspond one-to-one with the model vertex, the pixels are used to store the display layer, and the display layer is used to indicate the index of the preset color map.
[0129] The position display level determination module 54 is used to determine the position display level corresponding to the internal model position based on the rendering parameters of the vertex display level and the internal model position.
[0130] The texture color sampling module 55 is used to sample color maps based on vertex display level and position display level to obtain the vertex texture color of the model vertex and the position texture color of the internal model position;
[0131] The terrain model rendering module 56 is used to render model patches based on vertex texture color and position texture color to obtain the rendering result of the target terrain.
[0132] This invention provides a terrain rendering apparatus that acquires a terrain model composed of multiple model patches, each containing multiple model vertices. Based on preset rendering parameters for the model vertices, rendering parameters for the internal model positions within the model patches are determined. A vertex display level is acquired based on a layered texture map. The positional display level corresponding to the internal model position is determined based on the vertex display level and the rendering parameters for the internal model positions. A color map is sampled based on the vertex display level and the positional display level to obtain texture colors. The model patches are then rendered based on these texture colors. This method, by sampling vertex display levels and vertex texture colors for the model vertices, reduces the number of samplings, lowers the device's bandwidth overhead, improves device performance, and avoids overheating. Furthermore, by rendering the internal model positions of the model patches, a seamless and smooth terrain transition is achieved.
[0133] The above rendering parameters include pixel values; the model facet is a triangle, and the model vertices in the triangle include a first model vertex, a second model vertex, and a third model vertex; the rendering parameter of the first model vertex is the first pixel value, the rendering parameter of the second model vertex is the second pixel value, and the rendering parameter of the third model vertex is the third pixel value; the above rendering parameter determination module is also used to: perform linear interpolation on the internal model position of the model facet based on the first pixel value of the first model vertex, the second pixel value of the second model vertex, and the third pixel value of the third model vertex in the model facet, to obtain the interpolated pixel value of the internal model position of the model facet.
[0134] The first channel of the first pixel value is the first value, and the second and third channels of the first pixel value are the second values; the second channel of the second pixel value is the first value, and the first and third channels of the second pixel value are the second values; the third channel of the third pixel value is the first value, and the first and second channels of the third pixel value are the second values; the first value and the second value are different.
[0135] The values of the first, second, and third channels of the interpolated pixel values are all greater than the second value and less than the first value.
[0136] The aforementioned vertex display layer acquisition module is further configured to: acquire the vertex coordinates of the model vertices in the model patch, convert the vertex coordinates of the model vertices in the model patch into first UV coordinates; based on the first UV coordinates, sample the display layer stored in the pixel corresponding to the model vertex in the layer map to obtain the vertex display layer corresponding to the model vertex; wherein, the pixel in the layer map stores at least one display layer, and the pixel in the layer map corresponds to the model vertex of the terrain model.
[0137] The rendering parameters for the internal model position of the aforementioned model facet include interpolated pixel values; the aforementioned position display level determination module is also used to: calculate the product of the vertex display level and the interpolated pixel value of the internal model position of the model facet in the vertex shader; pass the product value to the fragment shader, calculate the ratio of the product value to the interpolated pixel value of the internal model position in the fragment shader, and determine the ratio as the position display level corresponding to the internal model position of the model facet.
[0138] The model vertices in the aforementioned model patch include a first model vertex, a second model vertex, and a third model vertex; the vertex display levels corresponding to the model vertices include: the first vertex display level corresponding to the first model vertex, the second vertex display level corresponding to the second model vertex, and the third vertex display level corresponding to the third model vertex; the aforementioned position display level determination module is further used to: calculate the first product value of the first vertex display level and the value of the first channel of the interpolated pixel value; calculate the second product value of the second vertex display level and the value of the second channel of the interpolated pixel value; and calculate the third product value of the third vertex display level and the value of the third channel of the interpolated pixel value.
[0139] The aforementioned product values include a first product value, a second product value, and a third product value; the aforementioned position display level determination module is further configured to: calculate a first ratio of the first product value to the value of the first channel of the interpolated pixel value; calculate a second ratio of the second product value to the value of the second channel of the interpolated pixel value; calculate a third ratio of the third product value to the value of the third channel of the interpolated pixel value; determine the first ratio as the first position display level corresponding to the first channel of the internal model position, determine the second ratio as the second position display level corresponding to the second channel of the model position, and determine the third ratio as the third position display level corresponding to the third channel of the model position.
[0140] The aforementioned texture color sampling module is also used to: obtain the vertex coordinates of the model vertices in the model patch, convert the vertex coordinates of the model vertices in the model patch into second UV coordinates, and convert the position coordinates of the internal model positions in the model patch into third UV coordinates; based on the second UV coordinates, sample the color map corresponding to the vertex display layer to obtain the vertex texture color of the model vertices in the model patch; based on the third UV coordinates, sample the color map corresponding to the position display layer to obtain the position texture color of the internal model positions in the model patch; wherein, the color map stores the texture color of the rendered terrain model.
[0141] The model vertices in the aforementioned model patch include a first model vertex, a second model vertex, and a third model vertex; the vertex display hierarchy includes: the first vertex display hierarchy corresponding to the first model vertex, the second vertex display hierarchy corresponding to the second model vertex, and the third vertex display hierarchy corresponding to the third model vertex; the aforementioned texture color sampling module is further used to: sample the texture color of the pixel corresponding to the second UV coordinate of the first model vertex in the color texture map corresponding to the first vertex display hierarchy to obtain the first vertex texture color of the first model vertex; sample the texture color of the pixel corresponding to the second UV coordinate of the second model vertex in the color texture map corresponding to the second vertex display hierarchy to obtain the second vertex texture color of the second model vertex; sample the texture color of the pixel corresponding to the second UV coordinate of the third model vertex in the color texture map corresponding to the third vertex display hierarchy to obtain the third vertex texture color of the third model vertex.
[0142] The aforementioned display hierarchy corresponding to the internal model position includes: a first display hierarchy corresponding to the first channel of the internal model position, a second display hierarchy corresponding to the second channel of the internal model position, and a third display hierarchy corresponding to the third channel of the internal model position. The texture color sampling module is further used to: sample the texture color of the pixel corresponding to the third UV coordinate in the color map corresponding to the first display hierarchy to obtain the first position texture color of the first channel of the internal pixel position in the model patch; sample the texture color of the pixel corresponding to the third UV coordinate in the color map corresponding to the second display hierarchy to obtain the second position texture color of the second channel of the internal model position in the model patch; and sample the texture color of the pixel corresponding to the third UV coordinate in the color map corresponding to the third display hierarchy to obtain the third position texture color of the third channel of the internal model position in the model patch.
[0143] The vertex texture colors of the aforementioned model vertices include: the first vertex texture color of the first model vertex, the second vertex texture color of the second model vertex, and the third vertex texture color of the third model vertex; the position texture colors of the internal model positions include: the first position texture color of the first channel of the internal model position, the second position texture color of the second channel of the internal model position, and the third position texture color of the third channel of the internal model position; the aforementioned terrain model rendering module is also used to: render the first model vertex, the second model vertex, and the third model vertex in the model facet according to the first vertex texture color, the second vertex texture color, and the third vertex texture color respectively; and render the internal model positions in the model facet according to the first position texture color, the second position texture color, and the third position texture color to obtain the rendering result of the target terrain.
[0144] The aforementioned terrain model rendering module is also used to: calculate the sum of the texture colors at the first, second, and third positions to obtain the texture color at the target position; and render the internal model position in the model patch based on the texture color at the target position.
[0145] The rendering parameters of the above-mentioned model vertices are pixel values; the above-mentioned device also includes a fourth vertex display layer sampling module, used to: sample the display layer stored in the pixel point corresponding to the fourth model vertex in the layer texture according to the pixel value of the model vertex and the first UV coordinate, and obtain the fourth vertex display layer corresponding to the fourth model vertex; wherein, the fourth model vertex is adjacent to the model vertex in the model patch, and the fourth model vertex and the model vertex in the model patch can form a rectangle; and store the fourth vertex display layer in the fourth channel of the model vertex in the model patch.
[0146] The aforementioned device further includes: a fourth position texture color sampling module, used to: convert the fourth model vertex into the fourth UV coordinate; sample the texture color of the pixel corresponding to the fourth UV coordinate in the color map corresponding to the fourth vertex display layer, and obtain the fourth position texture color of the fourth channel of the internal model position in the model patch.
[0147] The aforementioned internal model location texture color also includes: the fourth location texture color of the fourth channel of the internal model location; the aforementioned terrain model rendering module is also used to: determine the UV coordinates of the internal model location based on the interpolated pixel values of the internal model location; calculate the target location texture color of the internal model location according to the following formula: p=p1(1-u)(1-v)+p2u(1-v)+p3v(1-u)+p4uv where p is the target location texture color, p1 is the first location texture color, p2 is the second location texture color, p3 is the third location texture color, p4 is the fourth location texture color, and (u,v) is the UV coordinates of the internal model location; render the internal model location in the model patch according to the target location texture color to obtain the rendering result of the target terrain.
[0148] The aforementioned terrain model rendering module is also used to: determine the difference between the values of the first channel and the interpolated pixel values as u in UV coordinates; and determine the values of the second channel of the interpolated pixel values as v in UV coordinates.
[0149] The aforementioned terrain model rendering module is further configured to: if the first vertex texture color includes multiple values, calculate the sum of the products of each first vertex texture color and its blending weight to obtain the first target vertex texture color; if the second vertex texture color includes multiple values, calculate the sum of the products of each second vertex texture color and its blending weight to obtain the second target vertex texture color; if the third vertex texture color includes multiple values, calculate the sum of the products of each third vertex texture color and its blending weight to obtain the third target vertex texture color; wherein, the blending weight is obtained by sampling a hierarchical texture map, the hierarchical texture map stores multiple display hierarchies and their blending weights; and render the first model vertex, the second model vertex, and the third model vertex in the triangle according to the first target vertex texture color, the second target vertex texture color, and the third target vertex texture color, respectively.
[0150] The terrain rendering apparatus provided in this embodiment of the invention has the same technical features as the terrain rendering method provided in the above embodiments, so it can also solve the same technical problems and achieve the same technical effects.
[0151] This embodiment also provides an electronic device, including a processor and a memory. The memory stores machine-executable instructions that can be executed by the processor, and the processor executes the machine-executable instructions to implement the above-described terrain rendering method. This electronic device can be a server or a terminal device.
[0152] See Figure 4 As shown, the electronic device includes a processor 100 and a memory 101. The memory 101 stores machine-executable instructions that can be executed by the processor 100. The processor 100 executes the machine-executable instructions to implement the above-described terrain rendering method.
[0153] Furthermore, Figure 4 The electronic device shown also includes a bus 102 and a communication interface 103, with the processor 100, the communication interface 103 and the memory 101 connected via the bus 102.
[0154] The memory 101 may include high-speed random access memory (RAM) or non-volatile memory, such as at least one disk storage device. Communication between this system network element and at least one other network element is achieved through at least one communication interface 103 (which can be wired or wireless), such as the Internet, wide area network, local area network, or metropolitan area network. The bus 102 may be an ISA bus, PCI bus, or EISA bus, etc. The bus can be divided into address bus, data bus, control bus, etc. For ease of representation, Figure 4 The symbol is represented by a single double-headed arrow, but this does not mean that there is only one bus or one type of bus.
[0155] Processor 100 may be an integrated circuit chip with signal processing capabilities. In implementation, each step of the above method can be completed by the integrated logic circuitry in the hardware of processor 100 or by instructions in software form. Processor 100 may be a general-purpose processor, including a Central Processing Unit (CPU), a Network Processor (NP), etc.; it may also be a Digital Signal Processor (DSP), an Application Specific Integrated Circuit (ASIC), a Field-Programmable Gate Array (FPGA), or other programmable logic devices, discrete gate or transistor logic devices, or discrete hardware components. It can implement or execute the methods, steps, and logic block diagrams disclosed in the embodiments of this invention. The general-purpose processor may be a microprocessor or any conventional processor. The steps of the methods disclosed in the embodiments of this invention can be directly manifested as execution by a hardware decoding processor, or execution by a combination of hardware and software modules in the decoding processor. The software module can reside in a mature storage medium in the art, such as random access memory, flash memory, read-only memory, programmable read-only memory, electrically erasable programmable memory, or registers. This storage medium is located in memory 101. The processor 100 reads information from memory 101 and, in conjunction with its hardware, completes the steps of the method described in the foregoing embodiment, specifically including:
[0156] The method involves obtaining a terrain model of the target terrain. This model consists of multiple model patches, each containing multiple model vertices with preset rendering parameters. Based on these vertex rendering parameters, the rendering parameters for the internal model positions within the model patches are determined. Using a preset layered texture map, the vertex display layer corresponding to each model vertex is obtained. Each pixel in the layered texture map corresponds one-to-one with a model vertex, storing the display layer and indicating the index of a preset color map. Based on the vertex display layer and the rendering parameters for the internal model positions, the positional display layer corresponding to each internal model position is determined. Based on the vertex display layer and positional display layer, color maps are sampled to obtain the vertex texture color of the model vertices and the positional texture color of the internal model positions. The model patches are then rendered using these vertex texture colors to obtain the rendered target terrain. This method, by sampling vertex display layers and vertex texture colors for model vertices, reduces the number of samples, lowers device bandwidth overhead, improves device performance, and avoids overheating. Furthermore, by rendering the internal model positions within the model patches, a seamless and smooth terrain transition is achieved.
[0157] The above rendering parameters include pixel values; the model facet is a triangle, and the model vertices in the triangle include a first model vertex, a second model vertex, and a third model vertex; the rendering parameter of the first model vertex is the first pixel value, the rendering parameter of the second model vertex is the second pixel value, and the rendering parameter of the third model vertex is the third pixel value; the step of determining the rendering parameters of the internal model position of the model facet based on the rendering parameters of the model vertices includes: performing linear interpolation on the internal model position of the model facet based on the first pixel value of the first model vertex, the second pixel value of the second model vertex, and the third pixel value of the third model vertex in the model facet, to obtain the interpolated pixel value of the internal model position of the model facet.
[0158] In the above-mentioned method, the first channel of the first pixel value is the first value, and the second and third channels of the first pixel value are the second values; the second channel of the second pixel value is the first value, and the first and third channels of the second pixel value are the second values; the third channel of the third pixel value is the first value, and the first and second channels of the third pixel value are the second values; the first value and the second value are different. In this method, by utilizing the characteristics of linear interpolation, two channels of each model vertex can be set to 0 to facilitate the subsequent reconstruction of the position display hierarchy of the internal model.
[0159] The values of the first, second, and third channels of the interpolated pixel values are all greater than the second value and less than the first value. In this method, by interpolating between 0 and 1, the channel values of the internal model position can represent the UV coordinates of that position.
[0160] The steps for obtaining the vertex display level corresponding to the model vertex based on the preset layer map include: obtaining the vertex coordinates of the model vertex in the model patch, converting the vertex coordinates of the model vertex in the model patch into first UV coordinates; sampling the display level stored in the pixel corresponding to the model vertex in the layer map according to the first UV coordinates, and obtaining the vertex display level corresponding to the model vertex; wherein, the pixel in the layer map stores at least one display level, and the pixel in the layer map corresponds to the model vertex of the terrain model.
[0161] The rendering parameters for the internal model position of the aforementioned model facet include interpolated pixel values. The step of determining the position display level corresponding to the internal model position based on the vertex display level and the rendering parameters of the internal model position includes: in the vertex shader, calculating the product of the vertex display level and the interpolated pixel value of the internal model position of the model facet; passing the product value to the fragment shader, in the fragment shader, calculating the ratio of the product value to the interpolated pixel value of the internal model position, and determining the ratio as the position display level corresponding to the internal model position of the model facet.
[0162] The model vertices in the aforementioned model patch include a first model vertex, a second model vertex, and a third model vertex; the vertex display levels corresponding to the model vertices include: the first vertex display level corresponding to the first model vertex, the second vertex display level corresponding to the second model vertex, and the third vertex display level corresponding to the third model vertex; the step of calculating the product of the vertex display level corresponding to the model vertex and the interpolated pixel value of the internal model position of the model patch includes: calculating the first product of the first vertex display level and the value of the first channel of the interpolated pixel value; calculating the second product of the second vertex display level and the value of the second channel of the interpolated pixel value; and calculating the third product of the third vertex display level and the value of the third channel of the interpolated pixel value.
[0163] The aforementioned product values include a first product value, a second product value, and a third product value. The step of calculating the ratio of the product value to the interpolated pixel value of the internal model position, and determining this ratio as the display level corresponding to the internal model position of the model patch, includes: calculating a first ratio of the first product value to the value of the first channel of the interpolated pixel value; calculating a second ratio of the second product value to the value of the second channel of the interpolated pixel value; calculating a third ratio of the third product value to the value of the third channel of the interpolated pixel value; determining the first ratio as the first display level corresponding to the first channel of the internal model position, determining the second ratio as the second display level corresponding to the second channel of the model position, and determining the third ratio as the third display level corresponding to the third channel of the model position. In this method, only one layer map sampling is performed during the vertex shading stage, and it is a vertex-based sampling method, which significantly reduces the number of samplings compared to pixel-based sampling methods. In addition, by making full use of the characteristics of linear interpolation, different color values and interpolated pixel values can be set at the model vertices of the model facets to restore the display level corresponding to the internal model position, thereby improving the rendering effect of the model.
[0164] The steps described above, based on vertex display level and position display level, to sample color maps and obtain the vertex texture color of the model vertices and the position texture color of the internal model positions, include: obtaining the vertex coordinates of the model vertices in the model patch; converting the vertex coordinates of the model vertices in the model patch into second UV coordinates; converting the position coordinates of the internal model positions in the model patch into third UV coordinates; sampling the color map corresponding to the vertex display level according to the second UV coordinates to obtain the vertex texture color of the model vertices in the model patch; sampling the color map corresponding to the position display level according to the third UV coordinates to obtain the position texture color of the internal model positions in the model patch; wherein, the color map stores the texture color of the rendered terrain model.
[0165] The model vertices in the aforementioned model patch include a first model vertex, a second model vertex, and a third model vertex; the vertex display hierarchy includes: a first vertex display hierarchy corresponding to the first model vertex, a second vertex display hierarchy corresponding to the second model vertex, and a third vertex display hierarchy corresponding to the third model vertex; the step of sampling the color map corresponding to the vertex display hierarchy to obtain the vertex texture color of the model vertices in the model patch includes: sampling the texture color of the pixel corresponding to the second UV coordinate of the first model vertex in the color map corresponding to the first vertex display hierarchy to obtain the first vertex texture color of the first model vertex; sampling the texture color of the pixel corresponding to the second UV coordinate of the second model vertex in the color map corresponding to the second vertex display hierarchy to obtain the second vertex texture color of the second model vertex; sampling the texture color of the pixel corresponding to the second UV coordinate of the third model vertex in the color map corresponding to the third vertex display hierarchy to obtain the third vertex texture color of the third model vertex.
[0166] The aforementioned display hierarchy corresponding to the internal model position includes: the first display hierarchy corresponding to the first channel of the internal model position, the second display hierarchy corresponding to the second channel of the internal model position, and the third display hierarchy corresponding to the third channel of the internal model position. The step of sampling the color map corresponding to the display hierarchy to obtain the position texture color of the internal model position in the model facet includes: sampling the texture color of the pixel corresponding to the third UV coordinate in the color map corresponding to the first display hierarchy to obtain the first position texture color of the first channel of the internal pixel position in the model facet; sampling the texture color of the pixel corresponding to the third UV coordinate in the color map corresponding to the second display hierarchy to obtain the second position texture color of the second channel of the internal model position in the model facet; and sampling the texture color of the pixel corresponding to the third UV coordinate in the color map corresponding to the third display hierarchy to obtain the third position texture color of the third channel of the internal model position in the model facet. In this method, only one layer texture sampling is required for each model vertex, and only one color map sampling is required for each model vertex. For each internal model position, only three color map samplings are required, which not only reduces the number of samplings and improves device performance but also enhances the rendering effect.
[0167] The vertex texture colors of the aforementioned model vertices include: the first vertex texture color of the first model vertex, the second vertex texture color of the second model vertex, and the third vertex texture color of the third model vertex; the position texture colors of the internal model positions include: the first position texture color of the first channel of the internal model position, the second position texture color of the second channel of the internal model position, and the third position texture color of the third channel of the internal model position; the step of rendering model patches based on vertex texture colors and position texture colors to obtain the rendering result of the target terrain includes: rendering the first model vertex, the second model vertex, and the third model vertex in the model patch according to the first vertex texture color, the second vertex texture color, and the third vertex texture color, respectively; and rendering the internal model positions in the model patch according to the first position texture color, the second position texture color, and the third position texture color to obtain the rendering result of the target terrain. This method not only renders model vertices but also renders internal model positions, avoiding the problem of cracks in the rendering result and thus improving the rendering effect.
[0168] The steps described above for rendering the internal model position within a model facet based on the texture colors of the first, second, and third positions include: calculating the sum of the texture colors of the first, second, and third positions to obtain the target position texture color; and rendering the internal model position within the model facet based on the target position texture color. This method does not consider the weight of each texture color position; it directly adds the texture colors of the first, second, and third positions to render the internal model position within the model facet, avoiding the problem of rendering cracks and thus improving the rendering effect.
[0169] The rendering parameters for the model vertices mentioned above are pixel values. Following the step of obtaining the vertex display layer corresponding to the model vertex by sampling the display layer stored in the layer texture map based on the first UV coordinates, the method further includes: obtaining the fourth vertex display layer corresponding to the fourth model vertex by sampling the display layer stored in the layer texture map based on the pixel values of the model vertices and the first UV coordinates; wherein the fourth model vertex is adjacent to the model vertices in the model patch, and the fourth model vertex and the model vertices in the model patch can form a rectangle; the fourth vertex display layer is stored in the fourth channel of the model vertex in the model patch. In this method, by sampling the display layer corresponding to the fourth model vertex, the internal model position can obtain the texture color corresponding to the diagonal vertex, avoiding the appearance of triangular transition shapes in the rendering result, and further improving the rendering effect.
[0170] The above method also includes: converting the fourth model vertex into the fourth UV coordinate; sampling the texture color of the pixel corresponding to the fourth UV coordinate in the color map corresponding to the fourth vertex display layer, and obtaining the fourth position texture color of the fourth channel of the internal model position in the model patch.
[0171] The aforementioned internal model position texture color also includes: the fourth position texture color of the fourth channel of the internal model position; the step of rendering the internal model position in the model patch based on the first position texture color, the second position texture color, and the third position texture color to obtain the rendering result of the target terrain includes: determining the UV coordinates of the internal model position based on the interpolated pixel values of the internal model position; calculating the target position texture color of the internal model position according to the following formula: p = p1(1-u)(1-v) + p2u(1-v) + p3v(1-u) + p4uv where p is the target position texture color, p1 is the first position texture color, p2 is the second position texture color, p3 is the third position texture color, p4 is the fourth position texture color, and (u,v) are the UV coordinates of the internal model position; rendering the internal model position in the model patch based on the target position texture color to obtain the rendering result of the target terrain. In this method, the weights of bilinear interpolation are determined by interpolating pixel values. By utilizing the characteristics of bilinear sampling, the weighted values between the texture colors corresponding to each vertex around the internal model position can be calculated, avoiding the appearance of triangular transition shapes in the rendering results and further improving the rendering effect.
[0172] The steps described above for determining the UV coordinates of the internal model position based on the interpolated pixel values of the internal model position include: determining the difference between the value of the first channel and the interpolated pixel value as the u of the UV coordinate; and determining the value of the second channel of the interpolated pixel value as the v of the UV coordinate.
[0173] The steps described above, which render the first model vertex, second model vertex, and third model vertex in the model facet based on the first vertex texture color, the second vertex texture color, and the third vertex texture color, respectively, include: if there are multiple first vertex texture colors, calculating the sum of the products of each first vertex texture color and its blending weight to obtain the first target vertex texture color; if there are multiple second vertex texture colors, calculating the sum of the products of each second vertex texture color and its blending weight to obtain the second target vertex texture color; if there are multiple third vertex texture colors, calculating the sum of the products of each third vertex texture color and its blending weight to obtain the third target vertex texture color; wherein, the blending weight is obtained by sampling a hierarchical texture map, and the hierarchical texture map stores multiple display hierarchies and their blending weights; and rendering the first model vertex, second model vertex, and third model vertex in the triangle based on the first target vertex texture color, the second target vertex texture color, and the third target vertex texture color, respectively. In this method, by storing multiple display layers in the layered texture map, and also storing the blending weights corresponding to each display layer, the rendering effect can be further improved.
[0174] This embodiment also provides a machine-readable storage medium storing machine-executable instructions. When these machine-executable instructions are invoked and executed by a processor, they cause the processor to implement the aforementioned terrain rendering method, specifically including:
[0175] The method involves obtaining a terrain model of the target terrain. This model consists of multiple model patches, each containing multiple model vertices with preset rendering parameters. Based on these vertex rendering parameters, the rendering parameters for the internal model positions within the model patches are determined. Using a preset layered texture map, the vertex display layer corresponding to each model vertex is obtained. Each pixel in the layered texture map corresponds one-to-one with a model vertex, storing the display layer and indicating the index of a preset color map. Based on the vertex display layer and the rendering parameters for the internal model positions, the positional display layer corresponding to each internal model position is determined. Based on the vertex display layer and positional display layer, color maps are sampled to obtain the vertex texture color of the model vertices and the positional texture color of the internal model positions. The model patches are then rendered using these vertex texture colors to obtain the rendered target terrain. This method, by sampling vertex display layers and vertex texture colors for model vertices, reduces the number of samples, lowers device bandwidth overhead, improves device performance, and avoids overheating. Furthermore, by rendering the internal model positions within the model patches, a seamless and smooth terrain transition is achieved.
[0176] The above rendering parameters include pixel values; the model facet is a triangle, and the model vertices in the triangle include a first model vertex, a second model vertex, and a third model vertex; the rendering parameter of the first model vertex is the first pixel value, the rendering parameter of the second model vertex is the second pixel value, and the rendering parameter of the third model vertex is the third pixel value; the step of determining the rendering parameters of the internal model position of the model facet based on the rendering parameters of the model vertices includes: performing linear interpolation on the internal model position of the model facet based on the first pixel value of the first model vertex, the second pixel value of the second model vertex, and the third pixel value of the third model vertex in the model facet, to obtain the interpolated pixel value of the internal model position of the model facet.
[0177] In the above-mentioned method, the first channel of the first pixel value is the first value, and the second and third channels of the first pixel value are the second values; the second channel of the second pixel value is the first value, and the first and third channels of the second pixel value are the second values; the third channel of the third pixel value is the first value, and the first and second channels of the third pixel value are the second values; the first value and the second value are different. In this method, by utilizing the characteristics of linear interpolation, two channels of each model vertex can be set to 0 to facilitate the subsequent reconstruction of the position display hierarchy of the internal model.
[0178] The values of the first, second, and third channels of the interpolated pixel values are all greater than the second value and less than the first value. In this method, by interpolating between 0 and 1, the channel values of the internal model position can represent the UV coordinates of that position.
[0179] The steps for obtaining the vertex display level corresponding to the model vertex based on the preset layer map include: obtaining the vertex coordinates of the model vertex in the model patch, converting the vertex coordinates of the model vertex in the model patch into first UV coordinates; sampling the display level stored in the pixel corresponding to the model vertex in the layer map according to the first UV coordinates, and obtaining the vertex display level corresponding to the model vertex; wherein, the pixel in the layer map stores at least one display level, and the pixel in the layer map corresponds to the model vertex of the terrain model.
[0180] The rendering parameters for the internal model position of the aforementioned model facet include interpolated pixel values. The step of determining the position display level corresponding to the internal model position based on the vertex display level and the rendering parameters of the internal model position includes: in the vertex shader, calculating the product of the vertex display level and the interpolated pixel value of the internal model position of the model facet; passing the product value to the fragment shader, in the fragment shader, calculating the ratio of the product value to the interpolated pixel value of the internal model position, and determining the ratio as the position display level corresponding to the internal model position of the model facet.
[0181] The model vertices in the aforementioned model patch include a first model vertex, a second model vertex, and a third model vertex; the vertex display levels corresponding to the model vertices include: the first vertex display level corresponding to the first model vertex, the second vertex display level corresponding to the second model vertex, and the third vertex display level corresponding to the third model vertex; the step of calculating the product of the vertex display level corresponding to the model vertex and the interpolated pixel value of the internal model position of the model patch includes: calculating the first product of the first vertex display level and the value of the first channel of the interpolated pixel value; calculating the second product of the second vertex display level and the value of the second channel of the interpolated pixel value; and calculating the third product of the third vertex display level and the value of the third channel of the interpolated pixel value.
[0182] The aforementioned product values include a first product value, a second product value, and a third product value. The step of calculating the ratio of the product value to the interpolated pixel value of the internal model position, and determining this ratio as the display level corresponding to the internal model position of the model patch, includes: calculating a first ratio of the first product value to the value of the first channel of the interpolated pixel value; calculating a second ratio of the second product value to the value of the second channel of the interpolated pixel value; calculating a third ratio of the third product value to the value of the third channel of the interpolated pixel value; determining the first ratio as the first display level corresponding to the first channel of the internal model position, determining the second ratio as the second display level corresponding to the second channel of the model position, and determining the third ratio as the third display level corresponding to the third channel of the model position. In this method, only one layer map sampling is performed during the vertex shading stage, and it is a vertex-based sampling method, which significantly reduces the number of samplings compared to pixel-based sampling methods. In addition, by making full use of the characteristics of linear interpolation, different color values and interpolated pixel values can be set at the model vertices of the model facets to restore the display level corresponding to the internal model position, thereby improving the rendering effect of the model.
[0183] The steps described above, based on vertex display level and position display level, to sample color maps and obtain the vertex texture color of the model vertices and the position texture color of the internal model positions, include: obtaining the vertex coordinates of the model vertices in the model patch; converting the vertex coordinates of the model vertices in the model patch into second UV coordinates; converting the position coordinates of the internal model positions in the model patch into third UV coordinates; sampling the color map corresponding to the vertex display level according to the second UV coordinates to obtain the vertex texture color of the model vertices in the model patch; sampling the color map corresponding to the position display level according to the third UV coordinates to obtain the position texture color of the internal model positions in the model patch; wherein, the color map stores the texture color of the rendered terrain model.
[0184] The model vertices in the aforementioned model patch include a first model vertex, a second model vertex, and a third model vertex; the vertex display hierarchy includes: a first vertex display hierarchy corresponding to the first model vertex, a second vertex display hierarchy corresponding to the second model vertex, and a third vertex display hierarchy corresponding to the third model vertex; the step of sampling the color map corresponding to the vertex display hierarchy to obtain the vertex texture color of the model vertices in the model patch includes: sampling the texture color of the pixel corresponding to the second UV coordinate of the first model vertex in the color map corresponding to the first vertex display hierarchy to obtain the first vertex texture color of the first model vertex; sampling the texture color of the pixel corresponding to the second UV coordinate of the second model vertex in the color map corresponding to the second vertex display hierarchy to obtain the second vertex texture color of the second model vertex; sampling the texture color of the pixel corresponding to the second UV coordinate of the third model vertex in the color map corresponding to the third vertex display hierarchy to obtain the third vertex texture color of the third model vertex.
[0185] The aforementioned display hierarchy corresponding to the internal model position includes: the first display hierarchy corresponding to the first channel of the internal model position, the second display hierarchy corresponding to the second channel of the internal model position, and the third display hierarchy corresponding to the third channel of the internal model position. The step of sampling the color map corresponding to the display hierarchy to obtain the position texture color of the internal model position in the model facet includes: sampling the texture color of the pixel corresponding to the third UV coordinate in the color map corresponding to the first display hierarchy to obtain the first position texture color of the first channel of the internal pixel position in the model facet; sampling the texture color of the pixel corresponding to the third UV coordinate in the color map corresponding to the second display hierarchy to obtain the second position texture color of the second channel of the internal model position in the model facet; and sampling the texture color of the pixel corresponding to the third UV coordinate in the color map corresponding to the third display hierarchy to obtain the third position texture color of the third channel of the internal model position in the model facet. In this method, only one layer texture sampling is required for each model vertex, and only one color map sampling is required for each model vertex. For each internal model position, only three color map samplings are required, which not only reduces the number of samplings and improves device performance but also enhances the rendering effect.
[0186] The vertex texture colors of the aforementioned model vertices include: the first vertex texture color of the first model vertex, the second vertex texture color of the second model vertex, and the third vertex texture color of the third model vertex; the position texture colors of the internal model positions include: the first position texture color of the first channel of the internal model position, the second position texture color of the second channel of the internal model position, and the third position texture color of the third channel of the internal model position; the step of rendering model patches based on vertex texture colors and position texture colors to obtain the rendering result of the target terrain includes: rendering the first model vertex, the second model vertex, and the third model vertex in the model patch according to the first vertex texture color, the second vertex texture color, and the third vertex texture color respectively; and rendering the internal model positions in the model patch according to the first position texture color, the second position texture color, and the third position texture color to obtain the rendering result of the target terrain. This method not only renders model vertices but also renders internal model positions, avoiding the problem of cracks in the rendering result and thus improving the rendering effect.
[0187] The steps described above for rendering the internal model position within a model facet based on the texture colors of the first, second, and third positions include: calculating the sum of the texture colors of the first, second, and third positions to obtain the target position texture color; and rendering the internal model position within the model facet based on the target position texture color. This method does not consider the weight of each texture color position; it directly adds the texture colors of the first, second, and third positions to render the internal model position within the model facet, avoiding the problem of rendering cracks and thus improving the rendering effect.
[0188] The rendering parameters for the model vertices mentioned above are pixel values. Following the step of obtaining the vertex display layer corresponding to the model vertex by sampling the display layer stored in the layer texture map based on the first UV coordinates, the method further includes: obtaining the fourth vertex display layer corresponding to the fourth model vertex by sampling the display layer stored in the layer texture map based on the pixel values of the model vertices and the first UV coordinates; wherein the fourth model vertex is adjacent to the model vertices in the model patch, and the fourth model vertex and the model vertices in the model patch can form a rectangle; the fourth vertex display layer is stored in the fourth channel of the model vertex in the model patch. In this method, by sampling the display layer corresponding to the fourth model vertex, the internal model position can obtain the texture color corresponding to the diagonal vertex, avoiding the appearance of triangular transition shapes in the rendering result, and further improving the rendering effect.
[0189] The above method also includes: converting the fourth model vertex into the fourth UV coordinate; sampling the texture color of the pixel corresponding to the fourth UV coordinate in the color map corresponding to the fourth vertex display layer, and obtaining the fourth position texture color of the fourth channel of the internal model position in the model patch.
[0190] The aforementioned internal model position texture color also includes: the fourth position texture color of the fourth channel of the internal model position; the step of rendering the internal model position in the model patch based on the first position texture color, the second position texture color, and the third position texture color to obtain the rendering result of the target terrain includes: determining the UV coordinates of the internal model position based on the interpolated pixel values of the internal model position; calculating the target position texture color of the internal model position according to the following formula: p = p1(1-u)(1-v) + p2u(1-v) + p3v(1-u) + p4uv where p is the target position texture color, p1 is the first position texture color, p2 is the second position texture color, p3 is the third position texture color, p4 is the fourth position texture color, and (u,v) are the UV coordinates of the internal model position; rendering the internal model position in the model patch based on the target position texture color to obtain the rendering result of the target terrain. In this method, the weights of bilinear interpolation are determined by interpolating pixel values. By utilizing the characteristics of bilinear sampling, the weighted values between the texture colors corresponding to each vertex around the internal model position can be calculated, avoiding the appearance of triangular transition shapes in the rendering results and further improving the rendering effect.
[0191] The steps described above for determining the UV coordinates of the internal model position based on the interpolated pixel values of the internal model position include: determining the difference between the value of the first channel and the interpolated pixel value as the u of the UV coordinate; and determining the value of the second channel of the interpolated pixel value as the v of the UV coordinate.
[0192] The steps described above, which render the first model vertex, second model vertex, and third model vertex in the model facet based on the first vertex texture color, the second vertex texture color, and the third vertex texture color, respectively, include: if there are multiple first vertex texture colors, calculating the sum of the products of each first vertex texture color and its blending weight to obtain the first target vertex texture color; if there are multiple second vertex texture colors, calculating the sum of the products of each second vertex texture color and its blending weight to obtain the second target vertex texture color; if there are multiple third vertex texture colors, calculating the sum of the products of each third vertex texture color and its blending weight to obtain the third target vertex texture color; wherein, the blending weight is obtained by sampling a hierarchical texture map, and the hierarchical texture map stores multiple display hierarchies and their blending weights; and rendering the first model vertex, second model vertex, and third model vertex in the triangle based on the first target vertex texture color, the second target vertex texture color, and the third target vertex texture color, respectively. In this method, by storing multiple display layers in the layered texture map, and also storing the blending weights corresponding to each display layer, the rendering effect can be further improved.
[0193] The computer program products of the terrain rendering method, apparatus, electronic device and system provided in the embodiments of the present invention include a computer-readable storage medium storing program code. The instructions included in the program code can be used to execute the methods described in the preceding method embodiments. For specific implementation, please refer to the method embodiments, which will not be repeated here.
[0194] Those skilled in the art will clearly understand that, for the sake of convenience and brevity, the specific working process of the system and apparatus described above can be referred to the corresponding process in the foregoing method embodiments, and will not be repeated here.
[0195] Furthermore, in the description of the embodiments of the present invention, unless otherwise explicitly specified and limited, the terms "installation," "connection," and "linking" should be interpreted broadly. For example, they can refer to a fixed connection, a detachable connection, or an integral connection; they can refer to a mechanical connection or an electrical connection; they can refer to a direct connection or an indirect connection through an intermediate medium; and they can refer to the internal connection of two components. Those skilled in the art can understand the specific meaning of the above terms in the present invention based on the specific circumstances.
[0196] If the aforementioned functions are implemented as software functional units 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 this invention, essentially, or the part that contributes to the prior art, or a portion of the technical solution, can be embodied in the form of a software product. This computer software product is stored in a storage medium and includes several instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) to execute all or part of the steps of the methods described in the various embodiments of this invention. The aforementioned storage medium includes various media capable of storing program code, such as USB flash drives, portable hard drives, read-only memory (ROM), random access memory (RAM), magnetic disks, or optical disks.
[0197] In the description of this invention, it should be noted that the terms "center," "upper," "lower," "left," "right," "vertical," "horizontal," "inner," and "outer," etc., indicate the orientation or positional relationship based on the orientation or positional relationship shown in the accompanying drawings. They are used only for the convenience of describing the invention and for simplifying the description, and do not indicate or imply that the device or element referred to must have a specific orientation, or be constructed and operated in a specific orientation. Therefore, they should not be construed as limitations on the invention. Furthermore, the terms "first," "second," and "third" are used for descriptive purposes only and should not be construed as indicating or implying relative importance.
[0198] Finally, it should be noted that the above embodiments are merely specific implementations of the present invention, used to illustrate the technical solutions of the present invention, and not to limit it. The scope of protection of the present invention is not limited thereto. Although the present invention has been described in detail with reference to the foregoing embodiments, those skilled in the art should understand that any person skilled in the art can still modify or easily conceive of changes to the technical solutions described in the foregoing embodiments within the technical scope disclosed in the present invention, or make equivalent substitutions for some of the technical features; and these modifications, changes, or substitutions do not cause the essence of the corresponding technical solutions to deviate from the spirit and scope of the technical solutions of the embodiments of the present invention, and should all be covered within the scope of protection of the present invention. Therefore, the scope of protection of the present invention should be determined by the scope of the claims.
Claims
1. A terrain rendering method, characterized in that, The method includes: Obtain a terrain model of the target terrain; wherein the terrain model is composed of multiple model patches, each model patch including multiple model vertices, and each model vertex having preset rendering parameters; Based on the rendering parameters of the model vertices, determine the rendering parameters of the internal model positions of the model facets; Based on a preset layer map, the vertex display layer corresponding to the model vertex is obtained; wherein, the pixels in the layer map correspond one-to-one with the model vertex, the pixels are used to store the display layer, and the display layer is used to indicate the index of the preset color map; Based on the rendering parameters of the vertex display level and the internal model position, determine the position display level corresponding to the internal model position; Based on the vertex display level and the position display level, the color map is sampled to obtain the vertex texture color of the model vertex and the position texture color of the internal model position; The model facets are rendered based on the vertex texture color and the position texture color to obtain the rendering result of the target terrain.
2. The method according to claim 1, characterized in that, The rendering parameters include pixel values; the model facet is a triangle, and the model vertices in the triangle include a first model vertex, a second model vertex, and a third model vertex; the rendering parameter of the first model vertex is a first pixel value, the rendering parameter of the second model vertex is a second pixel value, and the rendering parameter of the third model vertex is a third pixel value. The step of determining the rendering parameters of the internal model position of the model facet based on the rendering parameters of the model vertices includes: Based on the first pixel value of the first model vertex, the second pixel value of the second model vertex, and the third pixel value of the third model vertex in the model facet, linear interpolation is performed on the internal model position of the model facet to obtain the interpolated pixel value of the internal model position of the model facet.
3. The method according to claim 2, characterized in that, The first channel of the first pixel value is a first value, and the second and third channels of the first pixel value are second values; the second channel of the second pixel value is a first value, and the first and third channels of the second pixel value are second values; the third channel of the third pixel value is a first value, and the first and second channels of the third pixel value are second values; the first value and the second value are different.
4. The method according to claim 2, characterized in that, The values of the first channel, the second channel, and the third channel of the interpolated pixel value are all greater than the second value and less than the first value.
5. The method according to claim 1, characterized in that, The step of obtaining the vertex display level corresponding to the model vertex based on a preset layer map includes: Obtain the vertex coordinates of the model vertices in the model patch, and convert the vertex coordinates of the model vertices in the model patch into first UV coordinates; Based on the first UV coordinates, the display levels stored in the pixels corresponding to the model vertices in the hierarchical texture map are sampled to obtain the vertex display levels corresponding to the model vertices; wherein, the pixels in the hierarchical texture map store at least one display level, and the pixels in the hierarchical texture map correspond to the model vertices of the terrain model.
6. The method according to claim 1, characterized in that, The rendering parameters for the internal model position of the model patch include interpolated pixel values; The step of determining the position display level corresponding to the internal model position based on the rendering parameters of the vertex display level and the internal model position includes: In the vertex shader, the product of the vertex display level and the interpolated pixel value of the internal model position of the model face is calculated; The product value is passed to the fragment shader, where the ratio of the product value to the interpolated pixel value of the internal model position is calculated, and the ratio is determined as the position display level corresponding to the internal model position of the model facet.
7. The method according to claim 6, characterized in that, The model vertices in the model patch include a first model vertex, a second model vertex, and a third model vertex; the vertex display levels corresponding to the model vertices include: the first vertex display level corresponding to the first model vertex, the second vertex display level corresponding to the second model vertex, and the third vertex display level corresponding to the third model vertex. The step of calculating the product of the vertex display level corresponding to the model vertex and the interpolated pixel value of the internal model position of the model facet includes: Calculate the first product of the first vertex display level and the value of the first channel of the interpolated pixel value; calculate the second product of the second vertex display level and the value of the second channel of the interpolated pixel value; calculate the third product of the third vertex display level and the value of the third channel of the interpolated pixel value.
8. The method according to claim 6, characterized in that, The product value includes a first product value, a second product value, and a third product value; The step of calculating the ratio of the product value to the interpolated pixel value of the internal model position, and determining the ratio as the display level corresponding to the internal model position of the model patch, includes: Calculate a first ratio of the first product value to the value of the first channel of the interpolated pixel value; calculate a second ratio of the second product value to the value of the second channel of the interpolated pixel value; calculate a third ratio of the third product value to the value of the third channel of the interpolated pixel value. The first ratio is determined as the first position display level corresponding to the first channel of the internal model position, the second ratio is determined as the second position display level corresponding to the second channel of the model position, and the third ratio is determined as the third position display level corresponding to the third channel of the model position.
9. The method according to claim 1, characterized in that, Based on the vertex display level and the position display level, the step of sampling the color map to obtain the vertex texture color of the model vertex and the position texture color of the internal model position includes: Obtain the vertex coordinates of the model vertices in the model patch, convert the vertex coordinates of the model vertices in the model patch into second UV coordinates, and convert the position coordinates of the internal model positions in the model patch into third UV coordinates; Based on the second UV coordinates, sample the color map corresponding to the vertex display layer to obtain the vertex texture color of the model vertex in the model facet; Based on the third UV coordinates, the color map corresponding to the position display layer is sampled to obtain the position texture color of the internal model position in the model patch; wherein, the color map stores the texture color for rendering the terrain model.
10. The method according to claim 9, characterized in that, The model vertices in the model patch include a first model vertex, a second model vertex, and a third model vertex; The vertex display hierarchy includes: a first vertex display hierarchy corresponding to the first model vertex, a second vertex display hierarchy corresponding to the second model vertex, and a third vertex display hierarchy corresponding to the third model vertex; The step of sampling the color map corresponding to the vertex display level to obtain the vertex texture color of the model vertices in the model patch includes: The texture color of the pixel corresponding to the second UV coordinate of the first model vertex is obtained by sampling the color map corresponding to the first vertex display layer; Sample the texture color of the pixel corresponding to the second UV coordinate of the second model vertex in the color map corresponding to the second vertex display layer to obtain the second vertex texture color of the second model vertex; The texture color of the third vertex is obtained by sampling the texture color of the pixel corresponding to the second UV coordinate of the third model vertex in the color map corresponding to the third vertex display layer.
11. The method according to claim 9, characterized in that, The position display hierarchy corresponding to the internal model position includes: a first position display hierarchy corresponding to the first channel of the internal model position, a second position display hierarchy corresponding to the second channel of the internal model position, and a third position display hierarchy corresponding to the third channel of the internal model position. The step of sampling the color map corresponding to the display layer at the location to obtain the position texture color of the internal model position in the model patch includes: Sampling the texture color of the pixel corresponding to the third UV coordinate in the color map corresponding to the first position display layer, the first position texture color of the first channel of the internal pixel position in the model patch is obtained; By sampling the texture color of the pixel corresponding to the third UV coordinate in the color map corresponding to the second position display layer, the second position texture color of the second channel of the internal model position in the model patch is obtained; The texture color of the pixel corresponding to the third UV coordinate in the color map corresponding to the third position display layer is sampled to obtain the third position texture color of the third channel of the internal model position in the model patch.
12. The method according to claim 2, characterized in that, The vertex texture colors of the model vertices include: the first vertex texture color of the first model vertex, the second vertex texture color of the second model vertex, and the third vertex texture color of the third model vertex. The positional texture color of the internal model location includes: the first positional texture color of the first channel of the internal model location, the second positional texture color of the second channel of the internal model location, and the third positional texture color of the third channel of the internal model location. The step of rendering the model patch based on the vertex texture color and the position texture color to obtain the rendering result of the target terrain includes: Based on the first vertex texture color, the second vertex texture color, and the third vertex texture color, render the first model vertex, the second model vertex, and the third model vertex in the model patch, respectively; Based on the texture color of the first position, the texture color of the second position, and the texture color of the third position, the internal model position in the model patch is rendered to obtain the rendering result of the target terrain.
13. The method according to claim 12, characterized in that, The step of rendering the internal model position in the model patch based on the texture color of the first position, the texture color of the second position, and the texture color of the third position includes: The target position texture color is obtained by summing the texture color at the first position, the texture color at the second position, and the texture color at the third position. Render the internal model position in the model patch based on the texture color of the target position.
14. The method according to claim 5, characterized in that, The rendering parameters for the model vertices are pixel values; After the step of sampling the display layer of the pixel corresponding to the model vertex in the layer map according to the first UV coordinates to obtain the vertex display layer of the model vertex, the method further includes: Based on the pixel values of the model vertices and the first UV coordinates, the display layer stored in the pixel corresponding to the fourth model vertex in the layer map is sampled to obtain the fourth vertex display layer corresponding to the fourth model vertex; wherein, the fourth model vertex is adjacent to the model vertices in the model patch, and the fourth model vertex and the model vertices in the model patch can form a rectangle; The fourth vertex display hierarchy is stored in the fourth channel of the model vertex in the model patch.
15. The method according to claim 14, characterized in that, The method further includes: Convert the fourth model vertex into fourth UV coordinates; The texture color of the pixel corresponding to the fourth UV coordinate in the color map corresponding to the fourth vertex display layer is sampled to obtain the fourth position texture color of the fourth channel of the internal model position in the model patch.
16. The method according to claim 12, characterized in that, The position texture color of the internal model location also includes: the fourth position texture color of the fourth channel of the internal model location; The step of rendering the internal model positions in the model patch based on the first position texture color, the second position texture color, and the third position texture color to obtain the rendering result of the target terrain includes: The UV coordinates of the internal model position are determined based on the interpolated pixel values of the internal model position. The target location texture color of the internal model position is calculated according to the following formula: in, The texture color at the target location. The texture color at the first position. The texture color at the second position. The texture color at the third position. The texture color at the fourth position. The UV coordinates of the internal model position; The internal model position in the model patch is rendered according to the texture color of the target position to obtain the rendering result of the target terrain.
17. The method according to claim 16, characterized in that, The step of determining the UV coordinates of the internal model position based on the interpolated pixel values of the internal model position includes: The difference between the value of the first channel and the interpolated pixel value is determined as the UV coordinate. The value of the second channel of the interpolated pixel value is determined as the UV coordinate. .
18. The method according to claim 12, characterized in that, The step of rendering the first model vertex, the second model vertex, and the third model vertex in the model patch according to the first vertex texture color, the second vertex texture color, and the third vertex texture color respectively includes: If the first vertex texture color includes multiple values, calculate the sum of the products of each first vertex texture color and the mixing weight of the first vertex texture color to obtain the first target vertex texture color; If the second vertex texture color includes multiple values, calculate the sum of the products of each second vertex texture color and the blending weight of the second vertex texture color to obtain the second target vertex texture color; If the third vertex texture color includes multiple colors, the sum of the products of each third vertex texture color and the blending weight of the third vertex texture color is calculated to obtain the third target vertex texture color; wherein, the blending weight is obtained by sampling the layer map, and the layer map stores multiple display layers and the blending weight of the display layers; Based on the texture colors of the first target vertex, the second target vertex, and the third target vertex, render the first model vertex, the second model vertex, and the third model vertex in the triangle, respectively.
19. A terrain rendering device, characterized in that, The device includes: The terrain model acquisition module is used to acquire the terrain model of the target terrain; wherein, the terrain model is composed of multiple model patches, each model patch includes multiple model vertices, and each model vertex has preset rendering parameters; The rendering parameter determination module is used to determine the rendering parameters of the internal model position of the model facet based on the rendering parameters of the model vertices. The vertex display layer acquisition module is used to acquire the vertex display layer corresponding to the model vertex based on a preset layer map; wherein, the pixels in the layer map correspond one-to-one with the model vertex, the pixels are used to store the display layer, and the display layer is used to indicate the index of the preset color map; The position display level determination module is used to determine the position display level corresponding to the internal model position based on the vertex display level and the rendering parameters of the internal model position; The texture color sampling module is used to sample the color map based on the vertex display level and the position display level to obtain the vertex texture color of the model vertex and the position texture color of the internal model position; The terrain model rendering module is used to render the model facets based on the vertex texture color and the position texture color to obtain the rendering result of the target terrain.
20. An electronic device, characterized in that, It includes a processor and a memory, the memory storing computer-executable instructions that can be executed by the processor, the processor executing the computer-executable instructions to implement the terrain rendering method according to any one of claims 1-18.
21. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores computer-executable instructions, which, when invoked and executed by a processor, cause the processor to implement the terrain rendering method according to any one of claims 1-18.
Citation Information
Patent Citations
Virtual terrain rendering method and device, equipment and medium
CN112245926A
Terrain rendering method and device, electronic equipment, medium and product
CN114842127A