Method and device for generating index map and method and device for generating virtual terrain
By merging weight maps to generate index maps, the problems of excessive game size and performance overhead in virtual terrain generation are solved, achieving high-quality terrain performance while reducing game size and performance overhead.
Patent Information
- Application Number
- CN202410263307.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-03-07
- Publication Date
- 2025-09-09
AI Technical Summary
When generating complex and rich virtual terrain, existing technologies require a large number of weight maps, which leads to excessively large game packages and increased performance overhead. It is difficult to control the size of the game package while providing high-quality terrain performance.
The weight maps corresponding to each surface level are merged into an index map, which is generated through color adjustment and overlay. The index map is used to index the maps corresponding to each surface level from the texture array, reducing the number of samples and lowering the game package size and performance overhead.
Multiple surface layer textures can be indexed through a single index map, reducing game package size and performance overhead while maintaining high-quality terrain performance.
Smart Images

Figure CN120612412A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of computer technology, and in particular to a method for generating an index map, a method for generating a virtual terrain, a device, an electronic device, and a computer-readable storage medium. Background Art
[0002] Virtual game scenes often include a large amount of virtual terrain. Virtual terrain simulates real-world terrain, such as mountains, plains, forests, and rivers. High-quality virtual terrain can provide users with a realistic gaming experience, and therefore, virtual terrain generation has become a critical component of virtual games.
[0003] Currently, a common approach is to use four channels of a weight map to store the weights of the four surface layers, thereby achieving blending of the four surface layers. However, when generating complex and rich virtual terrain, virtual games require an order of magnitude higher number of surface layers, which results in an excessive number of weight maps and increases the size of the game package. Therefore, how to provide high-quality terrain representation while avoiding excessive game size has become a pressing issue. Summary of the Invention
[0004] This application provides a method for generating an index map, a method for generating virtual terrain, an apparatus, an electronic device, and a computer-readable storage medium. These methods combine weight maps corresponding to various surface levels into a single index map. This allows for indexing to the maps corresponding to various surface levels for generating virtual terrain, even when the game package size is small, thereby providing high-quality terrain representation. The specific solution is as follows:
[0005] In a first aspect, an embodiment of the present application provides a method for generating an index map, the method comprising:
[0006] Obtaining weight maps corresponding to each surface level, wherein the weight map includes a white area with a weight of a first preset value and a black area with a weight of a second preset value, the white area being a covered area of the corresponding surface level, the black area being an uncovered area of the corresponding surface level, and the white areas corresponding to every two weight maps do not overlap;
[0007] Performing color adjustment on the white areas in the weight maps to obtain adjusted weight maps, so that the white areas in the adjusted weight maps respectively present different colors;
[0008] For each surface level, determining a correspondence between the adjusted color data and an index value of the surface level in a preset texture array, wherein the texture array stores a corresponding map for each surface level, wherein the adjusted color data is color data of the white area in the adjusted weight map corresponding to the surface level;
[0009] The adjusted weight maps are superimposed to obtain an index map, and the index map is used to index the map corresponding to each surface level from the texture array according to the corresponding relationship.
[0010] In a second aspect, an embodiment of the present application provides a method for generating a virtual terrain, the method comprising:
[0011] Obtain an index map, where the index map is generated by the index map generation method described in the first aspect;
[0012] Indexing the maps corresponding to each surface level from a preset texture array according to the index map;
[0013] The maps are mixed to generate a virtual terrain.
[0014] In a third aspect, an embodiment of the present application further provides a device for generating an index map, the device comprising:
[0015] A first acquisition unit is configured to acquire weight maps corresponding to each surface level, wherein the weight map includes a white area having a weight of a first preset value and a black area having a weight of a second preset value, the white area being a covered area of the corresponding surface level, the black area being an uncovered area of the corresponding surface level, and the white areas corresponding to every two weight maps do not overlap with each other;
[0016] an adjusting unit, configured to perform color adjustment on the white area in each of the weight maps to obtain each of the weight maps after adjustment, so that the white area in each of the weight maps after adjustment presents a different color;
[0017] a determining unit configured to determine, for each surface level, a correspondence between the adjusted color data and an index value of the surface level in a preset texture array, wherein the texture array stores a corresponding map for each surface level, wherein the adjusted color data is color data of the white area in the adjusted weight map corresponding to the surface level;
[0018] A superposition unit is used to superimpose the adjusted weight maps to obtain an index map, and the index map is used to index the map corresponding to each surface level from the texture array according to the corresponding relationship.
[0019] In a fourth aspect, an embodiment of the present application further provides a device for generating a virtual terrain, the device comprising:
[0020] A second acquisition unit, configured to acquire an index map, wherein the index map is generated by the index map generation method described in the first aspect;
[0021] An indexing unit, configured to index a map corresponding to each surface level from a preset texture array according to the index map;
[0022] The mixing unit is used to mix the maps to generate a virtual terrain.
[0023] In a fifth aspect, an embodiment of the present application further provides an electronic device, including:
[0024] processor; and
[0025] The memory is used to store a data processing program. After the electronic device is powered on and the program is run by the processor, the method described in any one of the first aspect or the second aspect is executed.
[0026] In a sixth aspect, an embodiment of the present application further provides a computer-readable storage medium storing a data processing program, which is run by a processor to execute the method as described in any one of the first aspect or the second aspect.
[0027] Compared with the prior art, this application has the following advantages:
[0028] The method for generating an index map provided by the present application obtains weight maps corresponding to each surface level, wherein the weight map includes a white area with a weight of a first preset value and a black area with a weight of a second preset value, the white area is the covered area of the corresponding surface level, the black area is the uncovered area of the corresponding surface level, and the white areas corresponding to each two weight maps do not overlap with each other; the white areas in each weight map are color-adjusted to obtain the adjusted weight maps, so that the white areas of each adjusted weight map appear in different colors respectively, so that the white areas in each adjusted weight map are different in color. The color data of each area are different data; for each surface level, the corresponding relationship between the adjusted color data and the index value of the surface level in the preset texture array is determined, and a corresponding map is stored in the texture array for each surface level, wherein the adjusted color data is the color data of the white area in the adjusted weight map corresponding to the surface level; the adjusted weight maps are superimposed to obtain an index map, and the index map is used to index the map corresponding to each surface level from the texture array according to the corresponding relationship. Since the white areas corresponding to each two weight maps do not overlap, for example, pixel a in the weight map does not overlap. Figure 1, pixel a is black in other weight maps. Furthermore, since the brightness value of black is 0, any superimposed color will present the superimposed color when superimposed with black with a brightness value of 0. In this way, when the adjusted weight maps are superimposed to obtain an index map, the superimposed area superimposed with the black area will present the color of the superimposed area. Therefore, in the index map generated by superimposing the adjusted weight maps and the corresponding area of the white area in each weight map, only the color data corresponding to the white area in the adjusted weight map is retained, that is, the adjusted color data. Since the correspondence between the adjusted color data and the index value of the surface level in the preset texture array is determined for each surface level, the corresponding map can be indexed based on the color data in the index map and the corresponding correspondence to generate a virtual terrain.
[0029] It can be seen that the index map generation method provided by the present application superimposes the weight maps corresponding to each surface level to generate an index map. The generated index map can satisfy the indexing of the map corresponding to each surface level. Compared with the current use of multiple weight maps to achieve the mixing of surface levels with a higher magnitude, the present application only uses one index map to index the map corresponding to the surface level with a higher magnitude. It can be seen that the index map generation method provided by the present application merges the weight maps corresponding to each surface level into an index map, which reduces the game package and performance overhead while satisfying the indexing of the map corresponding to each surface level, thereby providing high-quality terrain performance. BRIEF DESCRIPTION OF THE DRAWINGS
[0030] Figure 1 is a flow chart of a method for generating an index map provided in an embodiment of the present application;
[0031] Figure 2 is a schematic diagram of a weight map according to an embodiment of the present application;
[0032] Figure 3 This is a schematic diagram of setting color data for a weight map provided by an embodiment of the present application;
[0033] Figure 4 This is a schematic diagram of an embodiment of the present application providing an index map obtained by superimposing a weight map after setting color data;
[0034] Figure 5 This is a schematic diagram of discretizing the grayscale between 0 and 1 into six grayscale values provided by an embodiment of the present application;
[0035] Figure 6 is a flow chart of a method for generating a virtual terrain provided in an embodiment of the present application;
[0036] Figure 7This is the effect diagram of the virtual terrain generated by highly mixing the stone layer and the soil layer provided in the embodiment of the present application
[0037] Figure 8 This is a structural block diagram of an example of an index map generation device provided in an embodiment of the present application;
[0038] Figure 9 This is a structural block diagram of an example of a device for generating a virtual terrain provided in an embodiment of the present application;
[0039] Figure 10 This is a structural block diagram of an example of an electronic device provided in an embodiment of the present application. DETAILED DESCRIPTION
[0040] The following description sets forth many specific details to facilitate a thorough understanding of the present application. However, the present application can be implemented in many other ways than those described herein, and those skilled in the art can make similar generalizations without violating the scope of the present application. Therefore, the present application is not limited to the specific implementations disclosed below.
[0041] It should be noted that the terms "first", "second", "third", etc. in the claims, description and drawings of the present application are used to distinguish similar objects and are not used to describe a specific order or sequence. The data used in this way are interchangeable where appropriate, so that the embodiments of the present application described herein can be implemented in a sequence other than that illustrated or described herein. In addition, the terms "including", "having" and their variations are intended to cover non-exclusive inclusions. For example, a process, method, system, product or device that includes a series of steps or units is not necessarily limited to those steps or units clearly listed, but may include other steps or units that are not clearly listed or inherent to these processes, methods, products or devices.
[0042] Before describing the embodiments of the present application in detail, the prior art will be further described.
[0043] Further description of the prior art
[0044] High-quality terrain representation in virtual games can enhance the user experience. Consequently, more and more virtual games are pursuing complex and rich terrain representation. Complex and rich terrain often includes many layers of terrain, such as river layers, stone layers, soil layers, grass layers, and desert layers. Each surface layer corresponds to multiple texture maps, such as normal maps and metalness maps. Generating complex and rich virtual terrain often requires a large number of textures to support the complex terrain effects.
[0045] In related technologies, terrain is often generated through weight maps. Specifically, the four channels of a Weight Map are used to store the weights of four surface layers. By sampling the Weight Map to obtain the corresponding textures for each surface layer, multiple surface layers can be blended.
[0046] However, when the order of magnitude of the surface layers used in virtual games is high, multiple weight maps are required to support it. On the one hand, the game package in the virtual game is increased. On the other hand, multiple weight maps need to be sampled to obtain the maps corresponding to each surface layer. The number of sampling times increases significantly, resulting in additional overhead in the virtual game and reduced game performance.
[0047] Based on the above problems, in order to provide high-quality terrain representation while avoiding the game package being too large and reducing the number of sampling times, the first embodiment of the present application provides a method for generating an index map, which is applied to electronic devices. The electronic devices can be desktop computers, laptops, mobile phones, tablets, servers, terminal devices, etc., or other electronic devices that can generate index maps. The embodiments of the present application do not specifically limit this.
[0048] The following, combined Figures 1 to 5 The present invention introduces a method for generating an index map provided in an embodiment of the present application.
[0049] like Figure 1 As shown, the method for generating an index map provided by the present application includes the following steps S101 to S104.
[0050] Step S101: Obtain each weight map corresponding to each surface level, the weight map including a first white area whose weight of the first color is a first preset value and a second black area whose weight is a second preset value, the first color represents that the white area of the first area is the covered area of the corresponding surface level, and the black represents that the second black area is the uncovered area of the corresponding surface level, and the white areas of the first area corresponding to each two weight maps do not overlap with each other.
[0051] It should be noted that in the prior art, the traditional weight map is a map in the RGBA format, with four color channels, namely the red channel (abbreviated as R), the green channel (abbreviated as G), the blue channel (abbreviated as B) and the alpha channel (abbreviated as A). Each channel can represent a specific surface layer or material type. For example, the R channel represents the weight of the grass layer, the G channel represents the weight of the stone layer, the B channel represents the weight of the river layer, and the A channel represents the weight of the glacier layer. That is, the traditional weight map is a map in which the display weights of multiple surface layers are superimposed.
[0052] In the embodiment of the present application, each surface level corresponds to its own weight map. It can be understood that when making a virtual terrain, each surface level corresponds to a display weight at each position, so that a rich and complex terrain representation can be produced.
[0053] In an embodiment of the present application, first, a weight map (weightmap) corresponding to each surface level can be obtained, wherein the weight map is used to characterize the distribution and weight of the corresponding surface level on the virtual terrain to be generated. The weight map can specifically characterize the display weight of the corresponding surface level at each pixel through the color data of each pixel. The weight map can be a binary image. The weight of the white area can be a first preset value, for example, the weight of the white area is 1, and the white area is the covered area of the corresponding surface level. The weight of the black area can be a second preset value, for example, the weight of the black area is 1, and the black area is the uncovered area of the corresponding surface level. It should be noted that the first preset value and the second preset value can be other possible specific values, not limited to 1 and 0 in the above example. In order to facilitate the explanation of the method for generating an index map provided in the embodiment of the present application, in the subsequent embodiments of the present application, the first preset value is 1 and the second preset value is 0 as an example for introduction, which is not a limitation to the present application.
[0054] Surface layers are the concept of layering and categorizing different materials, textures, or landforms within a virtual terrain. Each surface layer represents a specific surface material or texture. For example, in a virtual game, surface layers might include the following common categories: stone layer, soil layer, grass layer, sediment layer, road layer, river layer, glacier layer, and so on.
[0055] Among them, the stone layer represents an area composed of stone or rock, such as a mountain or a rocky ground; the soil layer represents a layer of mixture composed of minerals, organic matter, water and air covering the surface. The soil layer simulates the characteristics of soil in the real world, including color, texture, humidity, etc.; the grassland layer represents an area covered with grassland; the sedimentary layer simulates the strata formed by the gradual accumulation of weathered materials, biological remains and other particulate matter through physical, chemical and biological actions in the real world. The sediments contained in the sedimentary layer may include different types of rocks such as sand, mud, limestone, shale, etc.; the road layer may include various types of roads, such as highways, city streets, country roads, etc. The road layer usually contains information such as the geometry, width, material, traffic signs, etc. of the road; the river layer represents water bodies such as rivers, lakes and oceans; the glacier layer represents areas covered by snow or ice.
[0056] In virtual terrain, surface layers can be overlaid and blended on top of each other to create richer and more complex terrain surfaces, generating realistic visual effects.
[0057] It should be noted that for each surface level used to generate a virtual terrain, the white parts of the corresponding weight maps are mutually exclusive. That is, if the pixel at a position on a weight map is white, then the pixel at that position on other weight maps will be black. This mutual exclusivity ensures that the surface features of the terrain will not overlap or mix at the same position, thereby maintaining the clarity and realism of the terrain.
[0058] In practical applications, artists or planners can edit and adjust the weights of each surface level according to actual needs, thereby generating weight maps for each surface level to obtain the desired terrain performance.
[0059] like Figure 2 The figure shows a schematic diagram of a weight map according to an embodiment of the present application, including weight map 201, weight map 202, weight map 203, and weight map 204, wherein weight map 201 may be a weight map corresponding to a stone layer, weight map 202 may be a weight map corresponding to a grass layer, weight map 203 may be a weight map corresponding to a glacier layer, and weight map 204 may be a weight map corresponding to a river layer. The white area in weight map 201 indicates that the area is completely covered by the stone layer, and the black area indicates that the area is not covered by the stone layer; the white area in weight map 202 indicates that the area is completely covered by the grass layer, and the black area indicates that the area is not covered by the grass layer; the white area in weight map 203 indicates that the area is completely covered by the glacier layer, and the black area indicates that the area is not covered by the glacier layer; the white area in weight map 204 indicates that the area is completely covered by the river layer, and the black area indicates that the area is not covered by the river layer.
[0060] Step S102: performing color adjustment on the white area of the first region in each of the weight maps to obtain each of the adjusted weight maps, so that the white area of the first region in each of the adjusted weight maps presents different colors.
[0061] In this application, in order to reduce the size of the game package, after obtaining the weight maps of each surface level, the weight maps can be superimposed to obtain an index map, and the maps corresponding to multiple surface levels can be obtained through an index map.
[0062] In the specific implementation, in order to be able to index the maps corresponding to multiple surface levels through one index map, the color of the white area in each weight map corresponding to each surface level can be adjusted to obtain the adjusted weight map, so that the color of the white area in each two adjusted weight maps is different.
[0063] It should be noted that the white area in each adjusted weight map should be understood as the area corresponding to the position of the white area in each adjusted weight map, and the color in the area has currently been changed from white to other colors.
[0064] Step S103: For each surface level, determine the correspondence between the adjusted color data and the index value of the surface level in a preset texture array, wherein the texture array stores a corresponding map for each surface level, wherein the adjusted color data is the color data of the white area of the first area in the adjusted weight map corresponding to the surface level.
[0065] It should be noted that in this application, an index value can be assigned to each surface layer, and the index value can be between 1 and 256, or between 0 and 255. Each index value corresponds to a surface layer texture and is used to index the corresponding surface layer texture from a preset texture array. For example, index value 1 corresponds to the texture of the stone layer, index value 2 corresponds to the texture of the river layer, index value 3 corresponds to the texture of the grass layer, and index value 4 corresponds to the texture of the glacier layer. Then, the texture of the stone layer can be indexed from the texture array through index value 1, the texture of the river layer can be indexed from the texture array through index value 2, the texture of the grass layer can be indexed from the texture array through index value 3, and the texture of the glacier layer can be indexed from the texture array through index value 4.
[0066] For a surface layer, the index value has a one-to-one correspondence with the color data corresponding to the white area in each adjusted weight map, and a unique index value can be determined based on one color data.
[0067] Step S104: superimposing the adjusted weight maps to obtain an index map, wherein the index map is used to index the maps corresponding to the surface levels from the texture array according to the corresponding relationship.
[0068] It should be noted that since the white areas in each two weight maps are mutually exclusive, the white areas in each two adjusted weight maps are also mutually exclusive. This mutual exclusion relationship can ensure that the white areas will not overlap in the index map generated by superimposing the adjusted weight maps.
[0069] In addition, since the white area in one weight map is a black area in another weight map, the pixel value of the black area is 0 and does not contribute any brightness when superimposed. Therefore, the color data corresponding to the white areas will not be changed when the adjusted weight maps are superimposed. In this way, the index value of the corresponding surface level can be determined by a color data in the index map generated by superimposing the adjusted weight maps. Furthermore, the corresponding surface level map can be indexed from the preset texture array according to the index value, thereby generating a virtual terrain based on the map indexed to the corresponding surface level.
[0070] An index map can contain at least one channel, and each channel can use an 8-bit binary data to represent color data.
[0071] The method for generating an index map provided by the present application obtains weight maps corresponding to each surface level, wherein the weight map includes a white area with a weight of a first preset value and a black area with a weight of a second preset value, the white area is the covered area of the corresponding surface level, the black area is the uncovered area of the corresponding surface level, and the white areas corresponding to each two weight maps do not overlap with each other; the white areas in each weight map are color-adjusted to obtain the adjusted weight maps, so that the white areas of each adjusted weight map appear in different colors respectively, so that the white areas in each adjusted weight map are different in color. The color data of each area are different data; for each surface level, the corresponding relationship between the adjusted color data and the index value of the surface level in the preset texture array is determined, and a corresponding map is stored in the texture array for each surface level, wherein the adjusted color data is the color data of the white area in the adjusted weight map corresponding to the surface level; the adjusted weight maps are superimposed to obtain an index map, and the index map is used to index the map corresponding to each surface level from the texture array according to the corresponding relationship. Since the white areas corresponding to each two weight maps do not overlap, for example, pixel a in the weight map does not overlap. Figure 1 , pixel a is black in other weight maps. Furthermore, since the brightness value of black is 0, any superimposed color will present the superimposed color when superimposed with black with a brightness value of 0. In this way, when the adjusted weight maps are superimposed to obtain an index map, the superimposed area superimposed with the black area will present the color of the superimposed area. Therefore, in the index map generated by superimposing the adjusted weight maps and the corresponding area of the white area in each weight map, only the color data corresponding to the white area in the adjusted weight map is retained, that is, the adjusted color data. Since the correspondence between the adjusted color data and the index value of the surface level in the preset texture array is determined for each surface level, the corresponding map can be indexed based on the color data in the index map and the corresponding correspondence to generate a virtual terrain.
[0072] It can be seen that the index map generation method provided by the present application superimposes the weight maps corresponding to each surface level to generate an index map. The generated index map can satisfy the indexing of the map corresponding to each surface level. Compared with the current use of multiple weight maps to achieve the mixing of surface levels with a higher magnitude, the present application only uses one index map to index the map corresponding to the surface level with a higher magnitude. It can be seen that the index map generation method provided by the present application merges the weight maps corresponding to each surface level into an index map, which reduces the game package and performance overhead while satisfying the indexing of the map corresponding to each surface level, thereby providing high-quality terrain performance.
[0073] In an optional embodiment, the index map can be an image containing four channels, namely R channel, G channel, B channel and A channel, where each channel can use an 8-bit binary to represent color data. In this way, each channel can contain up to 256 colors. Therefore, the index map containing four channels can contain up to 1024 (4*256) types of color data, and the index map containing four channels can index up to 1024 maps corresponding to surface levels.
[0074] In another optional embodiment, the index map may be an image containing three channels, where the three channels may be an R channel, a G channel, and a B channel, or the three channels may be an R channel, a G channel, and an A channel, or the three channels may be a G channel, a B channel, and an A channel. Each channel may use 8-bit binary data to represent color data, so that each channel may contain a maximum of 256 colors. Therefore, the index map containing three channels may contain a maximum of 768 (3*256) types of color data, and the index map containing three channels may index a maximum of 768 maps corresponding to surface levels.
[0075] In another optional embodiment, the index map can be an image containing two channels, the two channels can be the R channel and the G channel, or the two channels can be images of the R channel and the B channel, or the two channels can be images of the R channel and the A channel, or the two channels can be images of the G channel and the B channel, or the two channels can be images of the G channel and the A channel, or the two channels can be images of the B channel and the A channel. Each channel can use an 8-bit binary data to represent color data, so that each channel can contain up to 256 colors. Therefore, an index map containing two channels can contain up to 512 (2*256) types of color data, and an index map containing three channels can index up to 512 maps corresponding to surface levels.
[0076] In another optional embodiment, the index map can be a single-channel image, which can be any one of the R channel, B channel, G channel and A channel. An 8-bit binary representation of color data can be used in the channel, that is, the pixel value corresponding to each pixel can be represented by an 8-bit value. In this way, a single channel can contain up to 256 colors. Therefore, the index map of the single-channel image can index up to 256 maps corresponding to the surface levels.
[0077] It should be noted that since the number of surface levels in a virtual game is typically less than 256, a single-channel image that can index the textures corresponding to all 256 surface levels can meet the requirements for generating rich and complex virtual terrain in the virtual game. In the subsequent embodiments of this application, the indexed texture is a single-channel image as an example.
[0078] Optionally, step S102 may be implemented by the following steps: adjusting the colors of the white areas in the weight maps to different grayscales to obtain the adjusted weight maps.
[0079] Grayscale refers to the range of continuous tonal levels in a black and white or grayscale image, from darkest (black) to brightest (white). In this application, by adjusting the color of the white areas in each weight map to different grayscales, the adjusted white areas in each weight map can have different colors. In this way, the generated index map is a single-channel grayscale image.
[0080] As shown in Table 1, it is an example table of pixel values before and after color adjustment of the white areas of each weight map in the index map generation method provided in an embodiment of the present application.
[0081] Table 1.
[0082] White area pixel value before color adjustment Pixel value of white area after color adjustment Weighted stickers Figure 1 1 0.2 Weighted stickers Figure 2 1 0.4 Weighted stickers Figure 3 1 0.6 Weighted stickers Figure 4 1 0.8
[0083] In the above Table 1, the weights are Figure 1 ~Weighted Post Figure 4 Before color adjustment, the pixel values of the white area are all 1, that is, before color adjustment, the white area is displayed as white. After color adjustment, the weighted area is 1. Figure 1 ~Weighted Post Figure 4 The corresponding white areas are changed to different grayscales, and the weights are Figure 1 The pixel value of the white area is changed to 0.2, and the weight is Figure 2 The pixel value of the white area is changed to 0.4, and the weight is Figure 3 The pixel value of the white area is changed to 0.6, and the weight is Figure 4 The pixel value of the white area is changed to 0.8.
[0084] The following combination Figure 3 and Figure 4 Instructions for generating index maps by overlaying weight maps:
[0085] like Figure 3 , which is a schematic diagram of setting color data for a weight map according to an embodiment of the present application, Figure 3 It includes weight map 301, weight map 302, weight map 303 and weight map 304. Figure 2 The white area of the weight map 201 is set to a grayscale value of 0.2, and we can get Figure 3 The weight map 301 in Figure 2 The white area of the weight map 202 is set to a gray value of 0.4, and then Figure 3 The weight map 302 in Figure 2 The white area of the weight map 203 is set to a gray value of 0.6, and we can get Figure 3 The weight map 303 in Figure 2 The white area of the weight map 204 is set to 0.8, and we can get Figure 3 The weight map 304 in .
[0086] like Figure 4 As shown, it is a schematic diagram of the embodiment of the present application to superimpose the weight map after setting the color data to obtain the index map. Figure 3 After the weight map 301, weight map 302, weight map 303 and weight map 304 in the image are superimposed, we can get Figure 4 The index map, in addition to black, can include the following colors: the first is the color of the area indicated by 401, the second is the color of the area indicated by 402, the third is the color of the area indicated by 403, and the fourth is the color of the area indicated by 405. Figure 3 The color corresponding to the gray value set in the white area of the weight map 302, and the color of the area indicated by 402 is Figure 3 The color corresponding to the gray value set in the white area of the weight map 301, the color of the area indicated by 403 is Figure 3 The color corresponding to the gray value set in the white area of the weight map 304, the color of the area indicated by 404 is Figure 3 The color corresponding to the grayscale value set in the white area of the weight map 303.
[0087] because Figure 3 The weight map 301, weight map 302, weight map 303 and weight map 304 are respectively Figure 2The weight map obtained by setting the color of the white area of the weight map 201, the white area of the weight map 202, the white area of the weight map 203 and the white area of the weight map 204 can be determined. Figure 4 The area indicated by the color 401 in the index map shown is the area Figure 2 The area covered by the surface layer corresponding to the weight map 202 is the area indicated by the color 402. Figure 2 The area covered by the surface layer corresponding to the weight map 201 is the area indicated by the color 403. Figure 2 The area covered by the surface layer corresponding to the weight map 204 is the area indicated by the color 404. Figure 2 The area covered by the surface layer corresponding to the weight map 203.
[0088] It should be noted that, since the weight map is a binary image, the pixel value of the black area is 0, and the pixel value of the white area is 1. Therefore, the step of "adjusting the white areas in each of the weight maps to different grayscales to obtain the adjusted weight maps" in this application can be specifically implemented by the following steps:
[0089] Determine a first grayscale value corresponding to each of the weight maps, each of the weight maps corresponds to a different first grayscale value;
[0090] For each of the weight maps, the pixel value of each pixel in the weight map is multiplied by the first grayscale value to obtain the adjusted weight map.
[0091] Correspondingly, the step of "determining the correspondence between the adjusted color data and the index value of the surface level in the preset texture array" can specifically be: determining the correspondence between the first grayscale value corresponding to the adjusted weight map and the index value of the surface level corresponding to the weight map in the preset texture array.
[0092] In the present application, by multiplying each weight map by the corresponding first grayscale value, the white area in each weight map can be quickly and accurately changed to the corresponding grayscale. Since the pixel value of the black area is 0 and the pixel value of the white area is 1, after multiplying by the corresponding first grayscale value, the pixel value of the black area is still 0, and the pixel value of the white area is changed to the first grayscale value.
[0093] Moreover, for each weight map, its corresponding first grayscale value is the adjusted color data corresponding to the weight map. Therefore, the corresponding relationship determined in this application is the corresponding relationship between the first grayscale value and the corresponding index value.
[0094] As shown in Table 2, it is an example table of an example of multiplying each weight map by the corresponding first grayscale value in the method for generating an index map provided in an embodiment of the present application.
[0095] Table 2.
[0096] First gray value Changes in pixel values in black areas Changes in pixel values in white areas Weighted stickers Figure 1 0.2 0→0 1→0.2 Weighted stickers Figure 2 0.4 0→0 1→0.4 Weighted stickers Figure 3 0.6 0→0 1→0.6 Weighted stickers Figure 4 0.8 0→0 1→0.8
[0097] In the above Table 2, the weights are Figure 1 ~Weighted Post Figure 4 Before color adjustment, the pixel values of the white area are all 1, and the pixel values of the black area are all 0. That is, before color adjustment, the white area is displayed as white, and the black area is displayed as black. After color adjustment by multiplying the pixel values of each weight map by the corresponding first grayscale value, the weight map is Figure 1 ~Weighted Post Figure 4 The corresponding white areas are changed to different grayscales, and the weights are Figure 1 The pixel value of the white area is changed to 0.2, and the weight is Figure 2 The pixel value of the white area is changed to 0.4, and the weight is Figure 3 The pixel value of the white area is changed to 0.6, and the weight is Figure 4 The pixel value of the white area is changed to 0.8, and the weight is Figures 1 to 4 The pixel value of the corresponding black area is still 0 and still appears black.
[0098] For a surface layer, the grayscale value of the corresponding weight map can be determined according to the assigned index value, thereby realizing the setting of the grayscale value of the white area in the weight map.
[0099] Optionally, in the embodiment of the present application, the value range of the index value is referred to as the first range, and the value range of the grayscale value is referred to as the second range. The interval lengths of the first range and the second range are different. The step of "determining the first grayscale value corresponding to each of the weight maps" can be implemented according to the following steps:
[0100] discretize the grayscale value according to the first range and the second range to obtain a discretized grayscale value;
[0101] The first grayscale values corresponding to the weight maps are determined respectively from the discretized grayscale values.
[0102] Through the above steps, the grayscale values in the second range can be discretized into grayscale values whose number is the length of the intervals in the first range.
[0103] If the first range is 1 to 256 and the second range is 0 to 1, in order to be able to index the maps corresponding to 256 surface levels according to the index map, 0 to 1 can be discretized into 256 floating-point numbers. In this way, 256 grayscales can be divided between black and white. Then the step of "determining the first grayscale value corresponding to each of the weight maps" can be specifically implemented as follows:
[0104] Discretize the grayscale value from 0 to 1 into 256 grayscale values;
[0105] The first grayscale values corresponding to the weight maps are determined respectively from the 256 grayscale values.
[0106] The following is an introduction to discretizing 0 to 1 into 256 grayscale values:
[0107] In actual implementation, the range 0 to 1 can be divided into 256 equally spaced intervals, each of which represents a discrete value. This operation is usually called quantization or discretization. The specific steps are as follows:
[0108] Step 1: Calculate the width of each interval. Since a total of 256 intervals are required, the width of each interval is (1-0) / 256=1 / 256.
[0109] Step 2: Determine each interval based on the interval width. Based on the interval widths calculated in the first step, we know that the first interval is [0, 1 / 256], the second interval is (1 / 256, 2 / 256], and so on, until the last interval is (255 / 256 and 1].
[0110] Step 3: Select a floating-point number from each interval. Specifically, the end data of each interval can be used as the floating-point number corresponding to the interval. For example, for the interval [0, 1 / 256], the floating-point number can be 1 / 256, for the interval (1 / 256, 2 / 256], the floating-point number can be 2 / 256, and for the interval (255 / 256 and 1], the floating-point number can be 1. Alternatively, the middle value of each interval can be used as the floating-point number corresponding to the interval. For example, for the interval [0, 1 / 256], the floating-point number can be 0.5 / 256, for the interval (1 / 256, 2 / 256], the floating-point number can be 1.5 / 256, and for the interval (255 / 256 and 1], the floating-point number can be 255.5 / 256.
[0111] In this way, the continuous values originally between 0 and 1 are discretized into 256 floating-point numbers, providing a basis for supporting indexing to the maps corresponding to 256 surface levels.
[0112] It should be noted that the above-mentioned first range and second range can be specifically set according to the actual scenario, and this application does not specifically limit this.
[0113] In another optional embodiment, the grayscale values in the second range may be discretized according to the number of surface levels. The step of "determining the first grayscale values corresponding to each of the weight maps" may be implemented as follows:
[0114] Determine the number of surface levels;
[0115] discretize the grayscale values in the second range into the number of grayscale values;
[0116] The first grayscale values corresponding to the weight maps are determined respectively from the number of grayscale values.
[0117] In this implementation, the grayscale values in the second range can be adaptively discretized into the number of gray levels according to the number of surface levels. For example, if the number of surface levels is 100 and the second range is 0-1, the grayscale values of 0-1 can be discretized into 100 grayscale values, and the 100 grayscale values can be used as the grayscale values corresponding to each surface level. The specific discretization method can refer to the discretization method provided above for discretizing 0-1 into 256 grayscale values, which will not be repeated here.
[0118] like Figure 5 As shown, it is a schematic diagram of discretizing the grayscale between 0 and 1 into six grayscale values provided by an embodiment of the present application, wherein 501 is the grayscale between 0 and 1, and the color gradient from white to black in 501 is a continuous gradient. By discretizing the grayscale between white and black into six grayscale values, the grayscale values corresponding to 503, 504, 505, 506, 507 and 508 can be obtained, and the other grayscale values between 0 and 1 are discarded.
[0119] Furthermore, an index value may be mapped to one of 256 discrete floating-point numbers from 0 to 1, so that an index value can be determined according to a floating-point number, so that 256 floating-point numbers support indexing to maps corresponding to 256 surface levels.
[0120] After the index value is mapped to a floating-point number, in this application, the white areas of each weight map can be set to grayscales of different colors according to the floating-point number, so that after the weight maps are superimposed to generate an index map, the grayscale in the index map can be used to distinguish which weight map it belongs to.
[0121] In an optional implementation, the step of "determining the first grayscale value corresponding to each of the weight maps" can also be implemented by the following steps:
[0122] Determining a first ratio of an index value of each of the surface levels corresponding to each of the weight maps to an interval length of the first range;
[0123] The product of the first ratio and the interval length of the second range is determined as the first grayscale value corresponding to each of the weight maps.
[0124] Accordingly, the step of “determining the correspondence between the adjusted weight maps and the index values of the surface levels in the preset texture array” may include the following steps:
[0125] Determining a second ratio of the adjusted first grayscale value corresponding to each of the weight maps to the second range;
[0126] The ratio of the index value of each surface level to the corresponding second ratio is set as the interval length of the first range, and the correspondence between the adjusted color data and the index value of each surface level in the preset texture array is determined.
[0127] It should be noted that in the embodiment of the present application, the first grayscale value of the corresponding weight map can be determined based on the index value of each surface level in the preset texture array, the interval length of the first range corresponding to the index value, and the interval length of the second range corresponding to the grayscale value, so that the color of the corresponding weight map can be adjusted according to the first grayscale value.
[0128] It can be understood that generating the first grayscale value can be understood as an encoding process, determining the index value through the first grayscale value can be understood as a decoding process, and the corresponding relationship can be used for decoding. Through the generation step of the first grayscale value, it can be known that the corresponding relationship can be the relationship between the adjusted first grayscale value of each weight map, the interval length of the second range, the interval length of the first range, and the index value of each surface level. In this way, when generating a virtual terrain through an index map, after obtaining the pixel value of each pixel in the index map, the corresponding index value can be obtained quickly and accurately according to the pixel value, the interval length of the first range, and the interval length of the second range, thereby indexing the corresponding map.
[0129] When the index value is 1 to 256, the step of "determining the first grayscale value corresponding to each of the weight maps" can be implemented as follows:
[0130] The ratio of the index value of each surface level corresponding to each weight map to 256 is determined as the first grayscale value corresponding to each weight map.
[0131] Accordingly, the step of “determining the correspondence between the adjusted weight maps and the index values of the surface levels in the preset texture array” may include the following steps:
[0132] The ratio between the index value of each surface level and the first grayscale value corresponding to each adjusted weight map is 256, which is determined as the correspondence between the adjusted weight map and the index value of each surface level in the preset texture array.
[0133] As shown in Table 3, this is an example table of index values and first grayscale values of each weight map in the method for generating an index map provided in an embodiment of the present application.
[0134] Table 3.
[0135] Index value corresponding to the surface level First gray value Weighted stickers Figure 1 1 1 / 256 Weighted stickers Figure 2 2 2 / 256 Weighted stickers Figure 3 3 3 / 256 Weighted stickers Figure 4 4 4 / 256
[0136] In the above Table 3, the weighted Figure 1 The index value of the corresponding surface layer is 1, and the first grayscale value of the weight map is 1 / 256. Figure 2 The corresponding surface level index value is 2, then the first grayscale value of the weight map is 2 / 256, and the weight map is Figure 3 The corresponding surface level index value is 3, then the first grayscale value of the weight map is 3 / 256, and the weight map is Figure 4 The corresponding surface level index value is 4, and the first grayscale value corresponding to the weight map is 4 / 256.
[0137] In this way, the first grayscale value of the corresponding weight map can be determined according to the index value of each surface level in the preset texture array, so that the color of the corresponding weight map can be adjusted according to the first grayscale value. It should be noted that in this case, the corresponding relationship is that the ratio between the index value of each surface level and the adjusted first grayscale value corresponding to each weight map is 256. In this way, when generating a virtual terrain through the index map, after obtaining the pixel value of each pixel in the index map, the corresponding pixel value can be multiplied by 256 to quickly and accurately obtain the corresponding index value, thereby indexing the corresponding map.
[0138] Specifically, in step S104, "superimposing the adjusted weight maps to obtain an index map" can be implemented by following the steps below:
[0139] The pixel values of the pixels at the same position in the adjusted weight maps are summed to obtain the pixel value of each pixel in the index map.
[0140] It can be understood that the pixels of each adjusted weight map and the index map are in one-to-one correspondence, and the pixel value of each pixel in the index map is the sum of the pixel values of the corresponding pixels in each adjusted weight map.
[0141] It should be noted that when the pixel value of a pixel point in one adjusted weight map is not 0, the pixel value of the pixel point at the same position in other adjusted weight maps is 0. For example, pixel 1 in the weight map is Figure 1 The pixel value in the weight map is 0.6, and the pixel value in the other weight maps is 0, then the pixel value of pixel 1 after summing is 0.6. In this way, the pixel of one color in the index map obtained after superposition only represents one surface level. In this way, each surface level can be accurately indexed by the pixels of each color in the index map.
[0142] As shown in Table 4, this is an example table of an example of obtaining the pixel value of a pixel point in an index map by summing the pixel values of the pixel points at the same position in each weight map after adjustment in the index map generation method provided in an embodiment of the present application.
[0143] Table 4.
[0144]
[0145] In the above Table 4, the pixel a has the following weights after adjustment: Figure 1 The pixel value in is 0.2, and the pixel a has a Figure 2 The pixel value in is 0, and the pixel a has a Figure 3 The pixel value in is 0, and the pixel a has a Figure 4 The pixel value in the index map is 0, then the pixel value of pixel a in the index map is 0.2; the pixel value of pixel b in the adjusted weight map is Figure 1 The pixel value in is 0, and the pixel b has a value of 0 after the adjustment of the weight Figure 2 The pixel value in is 0.4, and the pixel b has a Figure 3 The pixel value in is 0, and the pixel b has a value of 0 after the adjustment of the weight Figure 4 The pixel value in the index map is 0, then the pixel value of pixel b in the index map is 0.4; the pixel value of pixel c in the adjusted weight map is Figure 1 The pixel value in is 0, and the pixel c is in the adjusted weight Figure 2 The pixel value in is 0, and the pixel c is in the adjusted weight Figure 3 The pixel value in is 0.6, and the pixel c is in the adjusted weight Figure 4 The pixel value in the index map is 0, then the pixel value of pixel c in the index map is 0.6; the pixel value of pixel d in the adjusted weight map is Figure 1 The pixel value in is 0, and the pixel d is in the adjusted weight Figure 2 The pixel value in is 0, and the pixel d is in the adjusted weight Figure 3 The pixel value in is 0, and the pixel d is in the adjusted weight Figure 4 If the pixel value in is 0.8, then the pixel value of pixel d in the index map is 0.8.
[0146] Specifically, in this application, index maps can be generated in Houdini (3D software) or a game engine. Houdini is an advanced 3D computer graphics software, mainly used for the creation of film special effects, visual effects, animation, game development and simulation. Game engine refers to a game development environment, which is a software framework used to design, develop, test and run electronic games. The game development environment can be used to implement the core functions of the game, such as animation splicing, animation playback, graphics rendering, physical simulation, audio processing, scripting language, artificial intelligence, etc. The game development environment provides game developers with a fast, efficient and reliable development environment. Commonly used game development environments include, but are not limited to, UnrealEngine, Unity, and CryEngine.
[0147] When generating an index map in software, the developer can configure the surface level and index value in the corresponding software based on the index value corresponding to each surface level in the preset texture array. Therefore, in the present application, in response to a configuration operation for the surface level and index value, the corresponding relationship between the adjusted color data and the index value of the surface level in the preset texture array can be determined based on the index value configured by the configuration operation and the adjusted color data of the adjusted weight map corresponding to the surface level.
[0148] The above generates the index map provided by the embodiment of the present application for indexing the maps corresponding to each surface level.
[0149] The following combination Figure 6 and Figure 7 , a method for generating virtual terrain provided in the second embodiment of the present application is introduced. The method is applied to electronic devices, which can be desktop computers, laptops, mobile phones, tablet computers, servers, terminal devices, etc., or other electronic devices that can generate index maps. The embodiments of the present application are not specifically limited.
[0150] like Figure 6 , which is a flow chart of a method for generating a virtual terrain provided in the second embodiment of the present application, including steps S601 to S603.
[0151] Step S601: obtaining an index map, wherein the index map is generated by the index map generation method provided in the first embodiment of the present application;
[0152] Step S602: indexing the texture corresponding to each surface level from a preset texture array according to the index texture;
[0153] Step S603: Blending the maps to generate a virtual terrain.
[0154] It is understood that the number of color data for each pixel in the index map in this application has a certain relationship with the number of surface levels. Specifically, the number of colors other than black in the index map can be consistent with the number of surface levels. For example, if the index map has 120 color data other than black, then these 120 color data are the color data of the white areas in each adjusted weight map corresponding to each surface level. In this case, the number of surface level weight maps is 120, and accordingly, the number of surface levels is also 120.
[0155] The virtual terrain generation method provided in an embodiment of the present application includes: obtaining an index map generated using the index map generation method provided in the first embodiment of the present application; indexing maps corresponding to various surface levels from a preset texture array based on the index map; and blending the maps to generate the virtual terrain. Loading a single index map successfully indexes maps corresponding to a surface level that is orders of magnitude higher. Furthermore, when generating the virtual terrain, there is no need to sample multiple maps, reducing the performance overhead of generating the virtual terrain.
[0156] Optionally, step S602 may be implemented by the following steps:
[0157] Determining color data for each pixel in the index map;
[0158] Determining the index values corresponding to the respective surface levels according to the color data and a preset correspondence relationship corresponding to the index map, wherein the correspondence relationship is obtained during the process of generating the index map;
[0159] The texture array is indexed based on the index value to obtain maps corresponding to each of the surface levels.
[0160] When the index map is a grayscale value, the virtual terrain can be generated by the following steps:
[0161] Step S10: Determine the grayscale value contained in the index map.
[0162] Step S11: For each grayscale value, determine the corresponding index value.
[0163] Step S12: indexing a corresponding map from a preset texture array according to each index value, wherein one index value is used to index a surface-level map from the texture array.
[0164] Step S13: According to the coverage position of each surface level indicated in the index map, the indexed maps are mixed to generate a virtual terrain.
[0165] In specific implementation, the index map can be imported into the game engine, and the game engine can parse the grayscale values in the index map and determine the corresponding index values according to the grayscale values. Then, the corresponding map can be indexed from the texture array according to the index values.
[0166] In the case where the grayscale value is a ratio of the index value to 256, the corresponding index value can be determined according to each grayscale value, and the index value can be determined in reverse by multiplying the grayscale value by 256.
[0167] In the embodiment of the present application, the texture array is an array for storing textures. The texture array may include multiple material units, and each material unit may store a map corresponding to a surface level.
[0168] In a specific embodiment, a ground surface may correspond to multiple ground surface layers. For example, a grassland layer may correspond to a dry grassland layer, a moist grassland layer, a flowered grassland layer, and a bare soil grassland layer. The dry grassland layer represents areas with relatively dry soil, yellowish grass, and low vegetation density; the moist grassland layer represents areas with relatively moist soil, greener grass, and high vegetation density; the flowered grassland layer includes some flowers or other plants, resulting in a variety of colors and textures within the grassland; and the bare soil grassland layer represents areas where the grass has been worn away, exposing the soil underneath.
[0169] In the case where one surface corresponds to multiple surface levels, the multiple surface levels can be respectively stored in different material units in a preset texture array, and the index values corresponding to the multiple surface levels of one surface are different.
[0170] For a surface layer, the corresponding map is the terrain PBR map (Physically Based Rendering Terrain Texture). Terrain PBR map is a texture map used to simulate the physical properties of terrain materials in the real world. It is based on the principle of Physically Based Rendering (PBR) and aims to more accurately simulate the interaction between light and matter to achieve more realistic and consistent visual effects. Terrain PBR maps can generally include but are not limited to the following types of maps: Diffuse / Albedo Map (Diffuse / Base Color Map), Normal Map (Normal Map), Roughness / Metalness Map (Roughness / Metalness Map), Ambient Occlusion Map (Ambient Occlusion Map), Height / Displacement Map (Height / Displacement Map), Specular Map (Specular Map).
[0171] Among them, the diffuse map is used to describe the color of the object surface and the diffuse reflection characteristics of the light. The normal map stores the surface normal information at each pixel and is used to simulate the microscopic details and bumps of the terrain surface. The roughness / metallicity map is used to describe the smoothness and material properties of the terrain surface. The roughness controls the blurriness of the specular highlight, and the metalness determines whether the material is metal or non-metal. The ambient occlusion map is used to simulate the influence of the surrounding environment on the shadows of the terrain surface, especially in areas that are difficult to be directly illuminated. The height / displacement map is used to represent the altitude or vertical displacement information of the terrain and can be used to generate a three-dimensional terrain model. The specular map is used to control the intensity and color of the specular reflection.
[0172] For a surface layer, based on the various maps contained in the terrain PBR map, the game engine or 3D software can calculate the lighting and shadow effects according to physical rules, making the presentation of the surface layer more realistic and natural.
[0173] It is understandable that after the maps corresponding to each surface level are indexed, the virtual terrain can be generated according to the maps corresponding to each surface level. Step S603 can be implemented by following the steps below:
[0174] Height-blending the textures to generate a virtual terrain; or
[0175] The maps are weighted mixed to generate a virtual terrain.
[0176] In an optional embodiment, the maps corresponding to each surface level can be highly blended to generate a virtual terrain. Specifically, the height information corresponding to each surface level can be obtained; and the maps are highly blended based on the height information to generate a virtual terrain.
[0177] It is understandable that in terrain production, there are two common ways to record height information: height field and height information on materials. In the embodiment of the present application, the height information corresponding to each surface level in the height blending is the height information on the material.
[0178] A height field is a grayscale image that records the elevation information of the entire terrain surface. The grayscale value of each pixel represents the altitude at that location. By sampling the height field, the height value of each point can be obtained. Typically, the height field serves as the basis for terrain generation and can be directly passed into a game engine or terrain editor for rendering and manipulation.
[0179] Height information on the material refers to encoding height information into the texture channel of the terrain material. This means using additional maps or texture channels to store height values. Unlike height fields, this approach is more flexible because it allows more data to be stored on each pixel, such as normals, lighting, roughness, etc. By decoding this information in the shader, the terrain height at each point can be obtained.
[0180] In general, height fields provide a simple but relatively low-detail way to record height information, allowing you to quickly generate the basic shape of the entire terrain. Height information recorded in materials is more flexible and can be combined with other data and textures to achieve more complex terrain effects, providing finer control and rendering options.
[0181] Height blending refers to the fusion of maps of different surface levels according to their height information to generate the final terrain surface. Specifically, each surface level can have its own height information, and this height information can be recorded on its own material. By superimposing and blending different maps on different height areas, a virtual scene with a realistic terrain appearance can be created. In the method of forming a virtual terrain by height blending, the height information corresponding to each surface level is the determining factor of the terrain performance of the final generated virtual terrain. Generally, the surface level with a lower height indicated by the height information appears to be at a lower terrain in the final generated virtual terrain, while the surface level with a higher height indicated by the height information appears to be at a higher terrain in the final generated virtual terrain.
[0182] Typically, height information can be stored in a separate height map, or it can be encoded in a normal map. That is, for a surface level, the height information can be obtained from the corresponding terrain PBR map.
[0183] As you can understand, the Shader program has the ability to process surface texture blending based on height information. Shader refers to a small program running in the graphics rendering pipeline, which is responsible for calculating pixel color, lighting effects, texture mapping and other visual performances. Shader can be executed on a graphics processing unit (GPU) to achieve efficient parallel computing and high-quality graphics rendering.
[0184] In an embodiment of the present application, by using a shader, the maps of each surface level can be mixed in a certain proportion according to the height information, and the texture details and mixing degree of each surface level can be controlled to obtain more accurate terrain generation and rendering effects, thereby achieving a smooth and realistic transition effect.
[0185] For example, in a mountainous terrain scene, using a highly blended terrain generation method, low-altitude areas can be associated with a grass texture map, mid-altitude areas with a rock texture map, and higher areas with a snow or ice texture map. By blending these maps, realistic terrain details are presented at different height levels, making the terrain look more natural.
[0186] like Figure 7 , which is a rendering of a virtual terrain generated by highly mixing a stone layer and a soil layer provided by an embodiment of the present application. It can be seen that after highly mixing, the height of the stone layer is higher than the height of the soil layer, presenting a visual effect of stones emerging from the soil surface.
[0187] In another optional implementation, the maps corresponding to each surface level may be weighted and mixed to generate a virtual terrain.
[0188] The weighted blending method allows each surface layer to be assigned a weight value, which represents the degree of influence each layer has on the final virtual terrain. Each surface layer can have an independent weight to adjust its visibility and range of influence. By blending the corresponding maps of each surface layer according to the independent weight of each surface layer, complex terrain effects containing multiple surface layers can be generated.
[0189] For example, in a forest terrain scene, using a weighted blending approach, low-altitude areas can be assigned higher weights to the grass texture map, mid-altitude areas can be assigned intermediate weights to the soil and tree texture maps, and higher altitude areas can be assigned lower weights to the rock and mountain texture maps. Based on the weight distribution, each texture map occupies a different proportion in the final terrain, creating a rich and varied forest terrain.
[0190] It should be noted that when mixing various surface levels to generate a virtual terrain, the coverage area corresponding to each surface level may be determined first; and then the maps may be mixed according to the coverage area to generate the virtual terrain.
[0191] The coverage area of each surface level can be determined based on the index map. The area corresponding to each grayscale value in the index map is the final coverage area corresponding to the surface level indexed by the index value corresponding to the grayscale value. In this way, according to the coverage area of each surface level indicated in the index map, the indexed maps are mixed to generate the required rich and complex virtual terrain.
[0192] The coverage area of each surface level can also be determined based on each weight map. The white area in the weight map is the coverage area of the corresponding surface level. In this way, the indexed maps are mixed according to the coverage area of each surface level indicated in each weight map to generate the required rich and complex virtual terrain.
[0193] Corresponding to the method for generating an index map provided in the first embodiment of the present application, the third embodiment of the present application further provides a device for generating an index map, such as Figure 8 As shown, the index map generation device 800 includes:
[0194] A first acquisition unit 801 is configured to acquire weight maps corresponding to respective surface levels, wherein the weight maps include white areas having a weight of a first preset value and black areas having a weight of a second preset value, wherein the white areas are covered areas of the corresponding surface level, and the black areas are uncovered areas of the corresponding surface level, and wherein the white areas corresponding to any two weight maps do not overlap with each other;
[0195] an adjusting unit 802 for performing color adjustment on the white area in each of the weight maps to obtain each of the weight maps after adjustment, so that the white area in each of the weight maps after adjustment presents a different color;
[0196] a determining unit 803 configured to determine, for each surface level, a correspondence between the adjusted color data and an index value of the surface level in a preset texture array, wherein the texture array stores a corresponding map for each surface level, wherein the adjusted color data is color data of the white area in the adjusted weight map corresponding to the surface level;
[0197] The superposition unit 804 is used to superimpose the adjusted weight maps to obtain an index map, and the index map is used to index the map corresponding to each surface level from the texture array according to the corresponding relationship.
[0198] Optionally, the adjusting unit 802 is specifically configured to:
[0199] The colors of the white areas in the weight maps are adjusted to different grayscales to obtain the adjusted weight maps.
[0200] Optionally, the adjusting unit 802 is specifically configured to:
[0201] Determine a first grayscale value corresponding to each of the weight maps, each of the weight maps corresponds to a different first grayscale value;
[0202] For each of the weight maps, multiplying the pixel value of each pixel in the weight map by the first grayscale value to obtain the adjusted weight map;
[0203] The determining unit 803 is specifically configured to:
[0204] Determine a correspondence between the adjusted first grayscale value corresponding to the weight map and the index value of the surface level corresponding to the weight map in a preset texture array.
[0205] Optionally, the index value has a value range of a first range, and the grayscale value has a value range of a second range;
[0206] The adjustment unit 802 is specifically configured to:
[0207] discretize the grayscale value according to the first range and the second range to obtain a discretized grayscale value;
[0208] The first grayscale values corresponding to the weight maps are determined respectively from the discretized grayscale values.
[0209] Optionally, the grayscale value range is a second range, and the adjusting unit 802 is specifically configured to:
[0210] Determine the number of surface levels;
[0211] discretizing the second range into the number of grayscale values;
[0212] The first grayscale values corresponding to the weight maps are determined respectively from the number of grayscale values.
[0213] Optionally, the index value has a value range of a first range, and the grayscale value has a value range of a second range;
[0214] The adjustment unit 802 is specifically configured to:
[0215] Determining a first ratio of an index value of each of the surface levels corresponding to each of the weight maps to an interval length of the first range;
[0216] The product of the first ratio and the interval length of the second range is determined as the first grayscale value corresponding to each of the weight maps.
[0217] Optionally, the determining unit 803 is specifically configured to:
[0218] Determining a second ratio of the adjusted first grayscale value corresponding to each of the weight maps to the interval length of the second range;
[0219] The ratio of the index value of each surface level to the corresponding second ratio is set as the interval length of the first range, and the correspondence between the adjusted color data and the index value of each surface level in the preset texture array is determined.
[0220] Optionally, the superimposing unit 804 is specifically configured to:
[0221] The pixel values of the pixels at the same position in the adjusted weight maps are summed to obtain the pixel value of each pixel in the index map.
[0222] Corresponding to the method for generating virtual terrain provided in the second embodiment of the present application, the fourth embodiment of the present application further provides a device for generating virtual terrain, such as Figure 9 As shown, the virtual terrain generating device 900 includes:
[0223] A second acquiring unit 901 is configured to acquire an index map, where the index map is generated by the index map generating method provided in the first embodiment of the present application;
[0224] An indexing unit 902, configured to index a map corresponding to each surface level from a preset texture array according to the index map;
[0225] The mixing unit 903 is used to mix the maps to generate a virtual terrain.
[0226] Optionally, the index unit 902 is specifically configured to:
[0227] Determining color data for each pixel in the index map;
[0228] Determining the index values corresponding to the respective surface levels according to the color data and a preset correspondence relationship corresponding to the index map, wherein the correspondence relationship is obtained during the process of generating the index map;
[0229] The texture array is indexed based on the index value to obtain maps corresponding to each of the surface levels.
[0230] Optionally, the mixing unit 903 is specifically configured to:
[0231] determining the coverage area corresponding to each of the surface levels;
[0232] The maps are mixed according to the coverage area to generate a virtual terrain.
[0233] Optionally, the mixing unit 903 is specifically configured to:
[0234] Height-blending the textures to generate a virtual terrain; or
[0235] The maps are weighted mixed to generate a virtual terrain.
[0236] Optionally, the mixing unit 903 is specifically configured to:
[0237] Obtaining height information corresponding to each of the surface layers;
[0238] The texture is height-blended based on the height information to generate a virtual terrain.
[0239] Corresponding to the method for generating an index map provided in the first embodiment of the present application, the fifth embodiment of the present application further provides an electronic device for generating an index map. Figure 10 As shown, the electronic device 1000 includes: a processor 1001; and a memory 1002, which is used to store a program for the method of generating an index map. After the device is powered on and the program for the method of generating an index map is run by the processor, the following steps are performed:
[0240] Obtaining weight maps corresponding to each surface level, wherein the weight map includes a white area with a weight of a first preset value and a black area with a weight of a second preset value, the white area being a covered area of the corresponding surface level, the black area being an uncovered area of the corresponding surface level, and the white areas corresponding to every two weight maps do not overlap;
[0241] Performing color adjustment on the white areas in the weight maps to obtain adjusted weight maps, so that the white areas in the adjusted weight maps respectively present different colors;
[0242] For each surface level, determining a correspondence between the adjusted color data and an index value of the surface level in a preset texture array, wherein the texture array stores a corresponding map for each surface level, wherein the adjusted color data is color data of the white area in the adjusted weight map corresponding to the surface level;
[0243] The adjusted weight maps are superimposed to obtain an index map, and the index map is used to index the map corresponding to each surface level from the texture array according to the corresponding relationship.
[0244] Corresponding to the virtual terrain generation method provided in the second embodiment of the present application, the sixth embodiment of the present application further provides an electronic device for generating virtual terrain. The electronic device includes: a processor; and a memory for storing a program for the index map generation method. After the device is powered on and the program for the index map generation method is executed by the processor, the device performs the following steps:
[0245] Obtain an index map, where the index map is generated by the index map generation method provided in the first embodiment of the present application;
[0246] Indexing the maps corresponding to each surface level from a preset texture array according to the index map;
[0247] The maps are mixed to generate a virtual terrain.
[0248] Corresponding to the index map generation method provided in the first embodiment of the present application or the virtual terrain generation method provided in the second embodiment of the present application, the seventh embodiment of the present application provides a computer-readable storage medium storing a program for the index map generation method or the virtual terrain generation method, which is executed by a processor to perform the following steps:
[0249] Obtaining weight maps corresponding to each surface level, wherein the weight map includes a white area with a weight of a first preset value and a black area with a weight of a second preset value, the white area being a covered area of the corresponding surface level, the black area being an uncovered area of the corresponding surface level, and the white areas corresponding to every two weight maps do not overlap;
[0250] Performing color adjustment on the white areas in the weight maps to obtain adjusted weight maps, so that the white areas in the adjusted weight maps respectively present different colors;
[0251] For each surface level, determining a correspondence between the adjusted color data and an index value of the surface level in a preset texture array, wherein the texture array stores a corresponding map for each surface level, wherein the adjusted color data is color data of the white area in the adjusted weight map corresponding to the surface level;
[0252] Superimposing the adjusted weight maps to obtain an index map, wherein the index map is used to index the map corresponding to each surface level from the texture array according to the corresponding relationship;
[0253] Alternatively, an index map is obtained, where the index map is generated by the index map generation method provided in the first embodiment of the present application;
[0254] Indexing the maps corresponding to each surface level from a preset texture array according to the index map;
[0255] The maps are mixed to generate a virtual terrain.
[0256] It should be noted that for the detailed description of the devices, electronic devices and computer-readable storage media provided in the third, fourth, fifth, sixth and seventh embodiments of the present application, reference can be made to the relevant descriptions of the first and second embodiments of the present application, and no further details will be given here.
[0257] Although the present application is disclosed as above with the preferred embodiments, it is not intended to limit the present application. Any person skilled in the art may make possible changes and modifications without departing from the spirit and scope of the present application. Therefore, the scope of protection of the present application shall be based on the scope defined by the claims of the present application.
[0258] In a typical configuration, a node device in a blockchain includes one or more processors (CPUs), input / output interfaces, network interfaces, and memory.
[0259] Memory may include non-permanent storage in a computer-readable medium, random access memory (RAM) and / or non-volatile memory in the form of read-only memory (ROM) or flash RAM. Memory is an example of a computer-readable medium.
[0260] 1. Computer-readable media includes permanent and non-permanent, removable and non-removable media that can be implemented by any method or technology to store information. Information can be computer-readable instructions, data structures, program modules, or other data. Examples of computer storage media include, but are not limited to, phase-change memory (PRAM), static random access memory (SRAM), dynamic random access memory (DRAM), random access memory (RAM) of other types, read-only memory (ROM), electrically erasable programmable read-only memory (EEPROM), flash memory or other memory technologies, compact disc read-only memory (CD-ROM), digital versatile disc (DVD) or other optical storage, magnetic cassettes, magnetic tape, magnetic disk storage or other magnetic storage media, or any other non-transmission media that can be used to store information that can be accessed by a computing device. As defined herein, computer-readable media does not include non-transitory media such as modulated data signals and carrier waves.
[0261] 2. Those skilled in the art will appreciate that the embodiments of the present application may be provided as methods, systems, or computer program products. Therefore, the present application may take the form of an entirely hardware embodiment, an entirely software embodiment, or an embodiment combining software and hardware. Furthermore, the present application may take the form of a computer program product implemented on one or more computer-usable storage media (including but not limited to magnetic disk storage, CD-ROM, optical storage, etc.) containing computer-usable program code.
[0262] Although the present application is disclosed as above with the preferred embodiments, it is not intended to limit the present application. Any person skilled in the art may make possible changes and modifications without departing from the spirit and scope of the present application. Therefore, the scope of protection of the present application shall be based on the scope defined by the claims of the present application.
Claims
1. A method for generating an index map, characterized in that: The method comprises: Obtaining weight maps corresponding to each surface level, wherein the weight map includes a white area with a weight of a first preset value and a black area with a weight of a second preset value, the white area being a covered area of the corresponding surface level, the black area being an uncovered area of the corresponding surface level, and the white areas corresponding to every two weight maps do not overlap; Performing color adjustment on the white areas in the weight maps to obtain adjusted weight maps, so that the white areas in the adjusted weight maps respectively present different colors; For each surface level, determining a correspondence between the adjusted color data and an index value of the surface level in a preset texture array, wherein the texture array stores a corresponding map for each surface level, wherein the adjusted color data is color data of the white area in the adjusted weight map corresponding to the surface level; The adjusted weight maps are superimposed to obtain an index map, and the index map is used to index the map corresponding to each surface level from the texture array according to the corresponding relationship.
2. The method according to claim 1, characterized in that The step of adjusting the color of the white area in each weight map to obtain each adjusted weight map includes: The colors of the white areas in the weight maps are adjusted to different grayscales to obtain the adjusted weight maps.
3. The method according to claim 2, characterized in that The step of adjusting the white areas in the weight maps to different grayscales to obtain the adjusted weight maps comprises: Determine a first grayscale value corresponding to each of the weight maps, each of the weight maps corresponds to a different first grayscale value; For each of the weight maps, multiplying the pixel value of each pixel in the weight map by the first grayscale value to obtain the adjusted weight map; Determining the correspondence between the adjusted color data and the index value of the surface level in the preset texture array includes: Determine a correspondence between the adjusted first grayscale value corresponding to the weight map and the index value of the surface level corresponding to the weight map in a preset texture array.
4. The method according to claim 3, characterized in that The index value has a first range, and the grayscale value has a second range. Determining the first grayscale value corresponding to each of the weight maps includes: discretize the grayscale value according to the first range and the second range to obtain a discretized grayscale value; The first grayscale values corresponding to the weight maps are determined respectively from the discretized grayscale values.
5. The method according to claim 3, characterized in that The grayscale value has a value range of the second range, and determining the first grayscale value corresponding to each of the weight maps includes: Determine the number of surface levels; discretize the grayscale values in the second range into the number of grayscale values; The first grayscale values corresponding to the weight maps are determined respectively from the number of grayscale values.
6. The method according to claim 3, characterized in that The index value has a first range, and the grayscale value has a second range. Determining the first grayscale value corresponding to each of the weight maps includes: Determining a first ratio of an index value of each of the surface levels corresponding to each of the weight maps to an interval length of the first range; The product of the first ratio and the interval length of the second range is determined as the first grayscale value corresponding to each of the weight maps.
7. The method according to claim 6, wherein determining the correspondence between each of the adjusted weight maps and the index value of each of the surface levels in the preset texture array comprises: Determining a second ratio of the adjusted first grayscale value corresponding to each of the weight maps to the interval length of the second range; The ratio of the index value of each surface level to the corresponding second ratio is set as the interval length of the first range, and the correspondence between the adjusted color data and the index value of each surface level in the preset texture array is determined.
8. The method according to claim 1, characterized in that The step of superimposing the adjusted weight maps to obtain an index map includes: The pixel values of the pixels at the same position in the adjusted weight maps are summed to obtain the pixel value of each pixel in the index map.
9. A method for generating a virtual terrain, characterized in that: The method comprises: Obtaining an index map, wherein the index map is generated by the index map generation method according to any one of claims 1 to 8; Indexing the maps corresponding to each surface level from a preset texture array according to the index map; The maps are mixed to generate a virtual terrain.
10. The method according to claim 9, characterized in that The step of indexing the maps corresponding to each surface level from a preset texture array according to the index map includes: Determining color data for each pixel in the index map; Determining the index values corresponding to the respective surface levels according to the color data and a preset correspondence relationship corresponding to the index map, wherein the correspondence relationship is obtained during the process of generating the index map; The texture array is indexed based on the index value to obtain maps corresponding to each of the surface levels.
11. The method according to claim 9, characterized in that The step of mixing the maps to generate a virtual terrain includes: determining the coverage area corresponding to each of the surface levels; The maps are mixed according to the coverage area to generate a virtual terrain.
12. The method according to claim 9, characterized in that The step of mixing the maps to generate a virtual terrain includes: Height-blending the textures to generate a virtual terrain; or The maps are weighted mixed to generate a virtual terrain.
13. The method according to claim 12, characterized in that The step of highly blending the textures to generate a virtual terrain comprises: Obtaining height information corresponding to each of the surface layers; The texture is height-blended based on the height information to generate a virtual terrain.
14. The method according to any one of claims 1 to 13, characterized in that The map corresponding to each of the surface levels includes at least one of the following: a diffuse map, a normal map, a metalness map, an ambient occlusion map, a height map, and a specular map.
15. A device for generating an index map, characterized in that: The device comprises: A first acquisition unit is configured to acquire weight maps corresponding to each surface level, wherein the weight map includes a white area having a weight of a first preset value and a black area having a weight of a second preset value, the white area being a covered area of the corresponding surface level, the black area being an uncovered area of the corresponding surface level, and the white areas corresponding to every two weight maps do not overlap with each other; an adjusting unit, configured to perform color adjustment on the white area in each of the weight maps to obtain each of the weight maps after adjustment, so that the white area in each of the weight maps after adjustment presents a different color; a determining unit configured to determine, for each surface level, a correspondence between the adjusted color data and an index value of the surface level in a preset texture array, wherein the texture array stores a corresponding map for each surface level, wherein the adjusted color data is color data of the white area in the adjusted weight map corresponding to the surface level; A superposition unit is used to superimpose the adjusted weight maps to obtain an index map, and the index map is used to index the map corresponding to each surface level from the texture array according to the corresponding relationship.
16. A device for generating a virtual terrain, characterized in that: The device comprises: A second acquisition unit, configured to acquire an index map, wherein the index map is generated by the index map generation method according to any one of claims 1 to 8; An indexing unit, configured to index a map corresponding to each surface level from a preset texture array according to the index map; The mixing unit is used to mix the maps to generate a virtual terrain.
17. An electronic device, characterized in that: include: processor; as well as The memory is used to store a data processing program. After the electronic device is powered on and the program is run by the processor, the method according to any one of claims 1 to 14 is executed.
18. A computer-readable storage medium, characterized in that A data processing program is stored, and the program is run by a processor to perform the method according to any one of claims 1 to 14.