Water body rendering method, apparatus, and electronic device
By dividing the terrain model into multiple water areas and controlling the rendering parameters using vertex colors and normal maps, the problem of high computational cost and high performance overhead when rendering water in existing technologies is solved, achieving a low-overhead and efficient rendering effect on mobile terminals.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-10-17
- Publication Date
- 2026-04-07
AI Technical Summary
In existing technologies, rendering water bodies requires modifying the terrain system, which involves a large amount of computation and high performance overhead, making it particularly unfriendly to mobile devices with limited resources.
By dividing the terrain model into multiple water areas, using vertex colors and normal maps to control rendering parameters, and using a patch method to render water on the terrain system, the rendering effects of deep water areas and transition areas are handled separately.
It reduces rendering computation and saves performance overhead, making it suitable for rendering water bodies on resource-limited mobile devices, and the visual effect is close to that of terrain system rendering.
Smart Images

Figure CN115641402B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of model rendering technology, and in particular to a water rendering method, apparatus and electronic device. Background Technology
[0002] In game scenes or other virtual scenes, terrain systems often need to render water bodies, such as lakes, rivers, and oceans. In related technologies, water bodies are treated as part of the terrain system and require rendering of the entire terrain system. If water bodies are added, deleted, or modified, the terrain system needs to be modified, resulting in a significant workload. At the same time, water bodies have a large number of polygons, leading to a large computational load and significant performance overhead when rendering and displaying them on terminal devices. Summary of the Invention
[0003] In view of this, the purpose of the present invention is to provide a water rendering method, apparatus and electronic device to reduce the amount of rendering computation, save performance overhead, and be more user-friendly for mobile terminals with limited resources.
[0004] In a first aspect, embodiments of the present invention provide a water rendering method, the method comprising: acquiring a terrain model for rendering a target water body; wherein, the model faces in the terrain model are provided with vertex colors; the vertex colors are used to characterize the water body region to which the model faces belong in the target water body; the water body region includes a deep water region and a transition region; the vertex colors of the model faces in the transition region gradually change along a specified direction; determining the model position of the pixel to be rendered mapped onto the terrain model; sampling the normal map at least once based on the position parameters of the model position and a preset time parameter to obtain the normal direction of the pixel to be rendered; wherein, the normal direction is used to control the rendering wave effect; for the model position belonging to the deep water region, rendering the pixel to be rendered corresponding to the model position based on the normal direction, the lighting direction of the model position, and a first color parameter; for the model position belonging to the transition region, determining a second color parameter based on the position parameters of the model position, the vertex color corresponding to the model position, and a preset time parameter; the second color parameter is used to control the water color and foam effect in the rendering transition region; and rendering the pixel to be rendered corresponding to the model position based on the second color parameter, the lighting direction of the model position, and the normal direction to obtain the rendered target water body.
[0005] The aforementioned terrain model includes multiple models; for a terrain model located at the edge of the target water body, the terrain model includes a deep water area and a transition area; in the deep water area, the vertex color of the model face is a preset first fixed value; in the transition area, the further away the model face is from the deep water area, the greater the difference between the vertex color of the model face and the first fixed value.
[0006] The above-mentioned terrain model for the edge of the target water body includes a waterfront area; the vertex color of the model face in the waterfront area is a preset second fixed value; the second fixed value is different from the first fixed value; in the transition area, the closer the model face is to the waterfront area, the smaller the difference between the vertex color of the model face and the second fixed value.
[0007] Before the above steps of obtaining the terrain model for rendering the target water body, the method further includes: setting regional boundary lines on the initial terrain model to divide the initial terrain model into multiple water body regions through the regional boundary lines; generating model surfaces of the water body regions based on the edge lines of the water body regions; wherein the edge lines of the water body regions include: regional boundary lines surrounding the water body regions and / or model edge lines of the initial terrain model; setting the vertex colors of the model surfaces within the water body regions according to the type of water body region, thereby obtaining the terrain model for rendering the target water body.
[0008] The steps described above, which involve sampling the normal map at least once based on the model's position parameters and preset time parameters to obtain the normal direction of the pixel to be rendered, include: sampling the normal map based on the model's position parameters, preset time parameters, and preset first configuration parameters to obtain a first sampling result; and determining the normal direction of the pixel to be rendered based on the first sampling result.
[0009] The aforementioned first configuration parameters include initial value parameters and coordinate value parameters. The step of sampling the normal map based on the model's position parameters, preset time parameters, and preset first configuration parameters to obtain a first sampling result includes: generating a first position vector based on the model's position coordinates; using the product of the initial value parameters and the first position vector as a first intermediate result, and using the product of the time parameters and coordinate value parameters as a second intermediate result; determining the sum of the first intermediate result and the second intermediate result as the first sampling coordinates; and sampling the normal map according to the first sampling coordinates to obtain the first sampling result.
[0010] The aforementioned first configuration parameter also includes an amplitude parameter; the step of determining the normal direction of the pixel to be rendered based on the first sampling result includes: extracting the normal component in the horizontal direction from the first sampling result; and determining the normal direction of the pixel to be rendered based on the product of the extracted normal component and the amplitude parameter.
[0011] The aforementioned first configuration parameters include multiple sets; the parameter values between the multiple sets of first configuration parameters are different; the step of determining the normal direction of the pixel to be rendered based on the first sampling result includes: for each set of first configuration parameters, performing sampling of the normal map based on the position parameters of the model position, the preset time parameters, and the preset first configuration parameters to obtain the first sampling result, thereby obtaining multiple first sampling results; and determining the normal direction of the pixel to be rendered based on the multiple first sampling results.
[0012] The steps described above for determining the second color parameter for model locations belonging to the transition region, based on the model location's position parameters, the vertex color corresponding to the model location, and preset time parameters, include: for model locations belonging to the transition region, sampling a preset noise map based on the model location's position parameters and preset time parameters to obtain a second sampling result; determining foam control parameters based on the second sampling result and the vertex color corresponding to the model location; and determining the second color parameter based on the foam control parameters, preset foam color parameters, and water color parameters.
[0013] The steps described above for sampling a preset noise map to obtain a second sampling result for model locations belonging to the transition region, based on the model location's position parameters and preset time parameters, include: generating a second position vector based on the model location's position coordinates for model locations belonging to the transition region; adding the product of the preset second configuration parameter and the time parameter to the second position vector to obtain an addition result; determining the second sampling coordinates by multiplying the addition result by the preset third configuration parameter; and sampling the noise map according to the second sampling coordinates to obtain the second sampling result.
[0014] The steps for determining the foam control parameters based on the second sampling result and the vertex color corresponding to the model position include: extracting the channel vertex color value of the first specified channel from the vertex color corresponding to the model position; subtracting the channel vertex color value from the preset third fixed value to obtain the first channel parameter; performing a square root operation on the first channel parameter to obtain the second channel parameter; and determining the foam control parameters based on the second sampling result, the first channel parameter, and the second channel parameter.
[0015] The steps for determining the foam control parameters based on the second sampling result, the first channel parameter, and the second channel parameter include: extracting the channel sampling value of the second specified channel from the second sampling result; multiplying the channel sampling value by the fourth power of the configuration parameter and the second channel parameter as the third intermediate result; multiplying the fifth configuration parameter and the time parameter as the fourth intermediate result; calculating the difference between the third intermediate result and the fourth intermediate result; and multiplying the square of the sine of the difference by the first channel parameter to obtain the foam control parameters.
[0016] The above-mentioned steps for determining the second color parameter based on foam control parameters, preset foam color parameters, and water color parameters include: determining the water color parameter based on the first color parameter and preset shallow water color parameters; and using the foam control parameter as an interpolation weight to interpolate the water color parameter and foam color parameter to obtain the second color parameter.
[0017] The steps for determining the water body color parameters based on the first color parameter and the preset shallow water color parameter include: using the sixth power of the configuration parameter of the first channel parameter as the interpolation weight to perform interpolation processing on the first color parameter and the shallow water color parameter to obtain the water body color parameters; wherein, the first channel parameter is obtained by: extracting the channel vertex color value of the first specified channel from the vertex color corresponding to the model position; and subtracting the channel vertex color value from the preset third fixed value to obtain the first channel parameter.
[0018] The above steps for rendering the pixels to be rendered corresponding to the model position based on the second color parameter, the lighting direction and the normal direction of the model position include: determining the rendering transparency parameter based on the vertex color corresponding to the model position; and rendering the pixels to be rendered corresponding to the model position based on the rendering transparency parameter, the second color parameter, the lighting direction and the normal direction of the model position.
[0019] Secondly, embodiments of the present invention provide a water body rendering apparatus, comprising: a model acquisition module for acquiring a terrain model for rendering a target water body; wherein, the model faces in the terrain model are provided with vertex colors; the vertex colors are used to characterize the water body region to which the model faces belong in the target water body; the water body region includes a deep water region and a transition region; the vertex colors of the model faces in the transition region gradually change along a specified direction; and a normal direction determination module for determining the model position of the pixel to be rendered mapped onto the terrain model; based on the position parameters of the model position and preset time parameters, the normal map is sampled at least once to obtain the normal direction of the pixel to be rendered; wherein, the normal direction... The system is used to control the rendering of wave effects. The first rendering module is used to render the pixels to be rendered at the model positions belonging to the deep water area based on the normal direction, the lighting direction of the model position, and the first color parameter. The second rendering module is used to determine the second color parameter for the model positions belonging to the transition area based on the position parameters of the model position, the vertex color corresponding to the model position, and the preset time parameter. The second color parameter is used to control the water color and foam effect in the transition area. Based on the second color parameter, the lighting direction and normal direction of the model position, the pixels to be rendered at the model positions are rendered to obtain the rendered target water body.
[0020] Thirdly, embodiments of the present invention provide an electronic device, including a processor and a memory, wherein the memory stores machine-executable instructions that can be executed by the processor, and the processor executes the machine-executable instructions to implement the above-described water rendering method.
[0021] Fourthly, embodiments of the present invention provide a machine-readable storage medium storing machine-executable instructions. When the machine-executable instructions are invoked and executed by a processor, the machine-executable instructions cause the processor to implement the above-described water rendering method.
[0022] The embodiments of the present invention bring the following beneficial effects:
[0023] The aforementioned water rendering method, apparatus, and electronic device acquire a terrain model for rendering a target water body. The model faces in the terrain model are assigned vertex colors. These vertex colors characterize the water region to which the model faces belong within the target water body. The water region includes deep water and transition regions. In the transition region, the vertex colors of the model faces gradually change along a specified direction. The model position of the pixel to be rendered, mapped onto the terrain model, is determined. Based on the position parameters of the model position and preset time parameters, the normal map is sampled at least once to obtain the normal direction of the pixel to be rendered. The normal direction is used to control the rendering of wave effects. For model positions belonging to deep water regions, the pixel to be rendered corresponding to the model position is rendered based on the normal direction, the lighting direction of the model position, and a first color parameter. For model positions belonging to transition regions, a second color parameter is determined based on the position parameters of the model position, the vertex color corresponding to the model position, and preset time parameters. The second color parameter is used to control the water color and foam effects in the transition region. Based on the second color parameter, the lighting direction of the model position, and the normal direction, the pixel to be rendered corresponding to the model position is rendered to obtain the rendered target water body.
[0024] In this method, the terrain model is pre-divided into multiple water areas, and different algorithms are used to calculate rendering parameters for different water areas to complete the rendering of the water bodies. This method does not require modification of the overall parameters of the terrain system. It renders water bodies on the terrain system through patches, resulting in lower computational load and saving performance overhead. It is more user-friendly for mobile devices with limited resources and is beneficial for rendering on mobile devices.
[0025] Other features and advantages of the invention will be set forth in the description which follows, and will be apparent in part from the description, or may be learned by practicing the invention. The objects and other advantages of the invention are realized and obtained in accordance with the structures particularly pointed out in the description, claims and drawings.
[0026] To make the above-mentioned objects, features and advantages of the present invention more apparent and understandable, preferred embodiments are described below in detail with reference to the accompanying drawings. Attached Figure Description
[0027] To more clearly illustrate the specific embodiments of the present invention or the technical solutions in the prior art, the drawings used in the description of the specific embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are some embodiments of the present invention. For those skilled in the art, other drawings can be obtained from these drawings without creative effort.
[0028] Figure 1 A flowchart of a water body rendering method provided in an embodiment of the present invention;
[0029] Figure 2 This is a schematic diagram of a region boundary line provided in an embodiment of the present invention;
[0030] Figure 3 A schematic diagram of a model surface provided in an embodiment of the present invention;
[0031] Figure 4 This is a schematic diagram of the structure of a water rendering device provided in an embodiment of the present invention;
[0032] Figure 5 This is a schematic diagram of the structure of an electronic device provided in an embodiment of the present invention. Detailed Implementation
[0033] To make the objectives, technical solutions, and advantages of the embodiments of the present invention clearer, the technical solutions of the present invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of the present invention, not all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of the present invention.
[0034] The following describes the technical terms used in this embodiment:
[0035] 1. PixelShader
[0036] A shader is a program specifically designed for rendering graphics. Through shaders, you can customize how the graphics card renders objects to achieve the desired effect. A PixelShader is a type of shader that instructs the computer how to calculate pixel values.
[0037] 2. UV
[0038] During the modeling process, UV coordinates are generated manually or automatically on the model surface. UV mapping then maps the polygons on the 3D object's surface to the corresponding points on the texture map's UV coordinates. UV mapping is a 3D modeling process that projects a 2D image onto the 3D model's surface for texture mapping. UV generally refers to UV coordinates, which are the coordinates of the polygons on the 3D object's surface generated by the UV mapping process and the corresponding texture map coordinates.
[0039] 3. Lerp
[0040] Lerp is a commonly used rendering instruction function. The Lerp(a,b,c) function is equivalent to a*(1-c)+b*c.
[0041] 4. Mesh
[0042] A mesh consists of faces and vertices, and in this context, it refers to a rendering object in computer graphics.
[0043] 5. Opacity
[0044] In this invention, Opacity refers to a parameter of a transparent rendering object, with a range of [0,1]. When Opacity is 1, it is completely opaque, and when it is 0, it is completely transparent.
[0045] In virtual scene terrain systems, water bodies such as lakes, rivers, and oceans are part of the terrain system, and the content of the terrain system is represented by generating corresponding meshes. If you want to render a water body in the terrain system, you need to modify the terrain system, which is a lot of work. On the other hand, rendering water bodies as part of the terrain system through terrain meshes is in line with physical laws, but it uses a lot of model surfaces to render the water bodies. When rendering and displaying water bodies on terminal devices, the amount of computation is large, resulting in significant performance overhead, which is not friendly to mobile terminals.
[0046] Alternatively, water bodies can be added to the terrain system using decorative elements. However, since water bodies are generally below ground level, rendering water bodies using decorative elements is unlikely to achieve the desired visual effect.
[0047] Based on the above, the present invention provides a water rendering method, apparatus, and electronic device. This technology can be applied to game scenes of SLG (Simulation Game) games, as well as game scenes of other types of games and other virtual scenes.
[0048] To facilitate understanding of this embodiment, a water rendering method disclosed in this invention will first be described in detail, such as... Figure 1 As shown, the water rendering method includes the following steps:
[0049] Step S102: Obtain a terrain model for rendering the target water body; wherein, the model faces in the terrain model are set with vertex colors; the vertex colors are used to characterize the water body region to which the model faces belong in the target water body; the water body region includes deep water region and transition region; the vertex colors of the model faces in the transition region gradually change along a specified direction;
[0050] Before rendering the target water body, a terrain model needs to be created for rendering it; this is the asset creation process. The target water body can be a lake, river, ocean, etc. The terrain model can be a portion of the terrain system in the virtual scene; that is, the terrain model that needs to be rendered for the target water body. In SLG games, the terrain system is divided into multiple map tile models, and the terrain model used to render the target water body typically includes one or more map tile models.
[0051] To achieve a good visual effect in the rendered target water body, it needs to be divided into multiple water regions, each rendered using a different method. This step includes deep water areas and transition areas; in other methods, it may also include shoreline areas. The visual appearance of different water regions varies; for example, deep water is darker, completely obscuring the terrain color and creating wave effects; transition areas have lighter water, producing foam effects; and shoreline areas have very light water, or even no water color at all, primarily displaying the terrain color.
[0052] In the process of creating a terrain model, to divide water areas, vertex colors can be used to distinguish the water areas to which model faces belong. In actual implementation, the terrain model can be divided into multiple water areas by boundary lines. For each water area, a model face is generated, and the vertex color of the model face is set.
[0053] For deep water areas, the rendering effect is the same at all locations; therefore, the vertex color in deep water areas can be set to a fixed value. For transition areas, which can be understood as the areas where the water transitions from deep water to the shore, the rendering effects such as the water color in transition areas also need to change gradually. To achieve a gradual change in rendering effect, the vertex color in transition areas usually also changes gradually. The specified direction can be from the deep water area to the shore area. For example, the vertex color gradually changes from the direction of the deep water area to the direction of the shore area, and the color value of the vertex color can gradually increase or gradually decrease.
[0054] Step S104: Determine the model position of the pixel to be rendered mapped onto the terrain model; based on the position parameters of the model position and the preset time parameters, sample the normal map at least once to obtain the normal direction of the pixel to be rendered; wherein, the normal direction is used to control the rendering wave effect;
[0055] The virtual camera captures the terrain model in the virtual scene to obtain the scene image. In this process, it is necessary to determine the model position corresponding to each pixel to be rendered in the scene image based on parameters such as the position and orientation of the virtual camera in the virtual scene. That is, the spatial coordinate of the pixel to be rendered in the three-dimensional space of the virtual scene.
[0056] The normal direction of the pixels to be rendered is mainly used to control the wave effect of the rendered water. When the water is calm, the normal direction is perpendicular to the water plane; when the water has waves, the normal direction of the wave position is not perpendicular to the water plane. By controlling the normal direction, parameters such as the width, height, and density of the waves can be controlled to a certain extent.
[0057] In practical implementation, the normal map stores multiple normal directions, each stored in a different position within the map. Based on the model's position and time parameters, the sampling position of the normal map is determined, thus obtaining the corresponding normal direction. The time parameter dynamically changes over time and also has a certain period. Referencing the time parameter when sampling the normal map can simulate the dynamic effects of waves, as well as the periodic changes in waves.
[0058] For a single pixel to be rendered, the normal map can be sampled once, resulting in the visual effect of a single wave for that pixel. Alternatively, the normal map can be sampled multiple times, resulting in the visual effect of multiple waves superimposed on the same pixel. The number of sampling times can be determined based on the actual visual representation requirements of the target water body.
[0059] Step S106: For the model position belonging to the deep water area, render the pixel to be rendered corresponding to the model position based on the normal direction, the lighting direction of the model position and the first color parameter.
[0060] In deep water areas, the water color is relatively uniform, such as dark blue or turquoise. Therefore, the lighting and shadow effects of the pixels to be rendered can be determined by the normal direction and the direction of illumination, and the color effect of the pixels to be rendered can be determined by the preset first color parameter, thus enabling the rendering of the pixels to be rendered.
[0061] Step S108: For the model position belonging to the transition area, a second color parameter is determined based on the position parameter of the model position, the vertex color corresponding to the model position, and the preset time parameter; the second color parameter is used to control the water color and foam effect of the rendering transition area; based on the second color parameter, the lighting direction and normal direction of the model position, the pixel to be rendered corresponding to the model position is rendered to obtain the rendered target water body.
[0062] For the transition region, the closer to the water's edge, the lighter the water color; therefore, the water color needs to change according to the model's position. Furthermore, the transition region includes not only wave effects but also foam effects, which are both dynamic and periodic. Therefore, the vertex colors of the model's position and the time parameter are considered when determining the second color parameter for the pixel to be rendered. The vertex colors in the transition region gradually change, thus controlling the water color to change gradually with the model's position. Additionally, the time parameter is dynamic and random, controlling the dynamic periodic changes of the foam effect. Therefore, the second color parameter, when generated, considers both the gradual change in water color and the dynamic periodic changes of the foam effect. Based on this, the second color parameter can be used to control the water color and foam effect of the pixel to be rendered.
[0063] Furthermore, the lighting and shadow effects of the pixel to be rendered can be determined by the normal direction and the lighting direction, and the color effect of the pixel to be rendered can be determined by the second color parameter, thus completing the rendering of the pixel to be rendered.
[0064] It should be noted that the above water rendering method is performed on top of the terrain system. Water is not part of the terrain system, and therefore does not need to be rendered through the terrain system's mesh.
[0065] The above water rendering method involves obtaining a terrain model for rendering the target water body. The model faces in the terrain model are assigned vertex colors. These vertex colors represent the water region to which the model face belongs within the target water body. The water region includes deep water and transition regions. In the transition region, the vertex colors of the model faces gradually change along a specified direction. The method determines the model position of the pixel to be rendered mapped onto the terrain model. Based on the position parameters of the model position and preset time parameters, the normal map is sampled at least once to obtain the normal direction of the pixel to be rendered. The normal direction is used to control the rendering wave effect. For model positions belonging to the deep water region, the pixel to be rendered corresponding to the model position is rendered based on the normal direction, the lighting direction of the model position, and a first color parameter. For model positions belonging to the transition region, a second color parameter is determined based on the position parameters of the model position, the vertex color corresponding to the model position, and preset time parameters. The second color parameter is used to control the water color and foam effect in the transition region. Based on the second color parameter, the lighting direction of the model position, and the normal direction, the pixel to be rendered corresponding to the model position is rendered to obtain the rendered target water body.
[0066] In this method, the terrain model is pre-divided into multiple water areas, and different algorithms are used to calculate rendering parameters for different water areas to complete the rendering of the water bodies. This method does not require modification of the overall parameters of the terrain system. It renders water bodies on the terrain system through patches, resulting in lower computational load and saving performance overhead. It is more user-friendly for mobile devices with limited resources and is beneficial for rendering on mobile devices.
[0067] Furthermore, for SLG games or other games with a fixed perspective, the water rendering method in this embodiment can achieve a visual effect similar to the Mesh rendering method of the terrain system, while also greatly reducing performance overhead and production costs.
[0068] The following examples further describe how to create assets for rendering terrain models of target water bodies.
[0069] Specifically, the terrain model includes multiple parts; for the terrain model located at the edge of the target water body, the terrain model includes a deep water area and a transition area; in the deep water area, the vertex color of the model face is a preset first fixed value; in the transition area, the further away the model face is from the deep water area, the greater the difference between the vertex color of the model face and the first fixed value.
[0070] In some virtual scenes, the terrain system is divided into multiple terrain models of specific shapes, such as hexagons. For a large target body of water, it may occupy multiple terrain models. Among these multiple terrain models, some terrain models may be located at the center of the target body of water. In this case, the entire terrain model is a deep water area, and it can be rendered according to the rendering method for the pixels to be rendered in the deep water area in this embodiment. For terrain models located at the edge of the target body of water, the terrain model will contain a part of the deep water area, a part of the transition area, and possibly a waterfront area.
[0071] In this embodiment, the vertex color determines which water region the model face belongs to. In one implementation, the vertex color of the model face in the deep water region is a first fixed value, for example, the first fixed value is 1; for the transition region, the vertex color of the model face near the deep water region is 1 or close to 1, and the vertex color decreases as it gets farther away from the deep water region, until the vertex color becomes 0.
[0072] For a terrain model located at the edge of the target water body, the terrain model also includes a waterfront area; the vertex color of the model face in the waterfront area is a preset second fixed value; the second fixed value is different from the first fixed value; in the transition area, the closer the model face is to the waterfront area, the smaller the difference between the vertex color of the model face and the second fixed value.
[0073] For example, the vertex color in the deep water region is set to 1, and the vertex color in the waterfront region is set to 0. Typically, the transition region is located between the deep water region and the waterfront region. In the transition region, the vertex color of the model face closer to the deep water region is close to 1, and the vertex color of the model face closer to the waterfront region is close to 0.
[0074] In one specific implementation, the creation of terrain model assets may include the following steps 21-23:
[0075] Step 21: Set regional boundary lines on the initial terrain model to divide the initial terrain model into multiple water body regions through the regional boundary lines;
[0076] The regional boundary line can be set according to the position of the initial terrain model in the target water body. For example, for the initial terrain model at the edge of the water body, the initial terrain model can be divided into deep water area, transition area and waterfront area by the regional boundary line. Figure 2 This is an example of a regional boundary line. The initial terrain model is a hexagonal model, and the bold lines represent the regional boundary lines, which divide the initial terrain model into a deep-water area, a transition area, and a waterfront area.
[0077] Step 22: Generate a model surface for the water body region based on its edge lines; wherein, the edge lines of the water body region include: the regional boundary line surrounding the water body region and / or the model edge lines of the initial terrain model;
[0078] For different water bodies, the edge line may include only the regional boundary line, only the model edge line, or both the regional boundary line and the model edge line. In the above... Figure 2 In the middle, the edge line of the deep water area includes part of the regional boundary line and part of the model edge line; while the edge line of the transition area only includes the regional boundary line; the edge line of the waterfront area includes part of the regional boundary line and part of the model edge line.
[0079] The edge line of a water body region can also be understood as the line that surrounds that water body region. In actual implementation, a model surface for each water body region can be generated. Specifically, multiple points can be set on the edge line of the water body region, these points can be connected to obtain multiple lines, and the surface formed by these lines can be used as the model surface.
[0080] Figure 3 As an example, in the deep water area, multiple points are set on the boundary line, and the model edge line includes two vertices. By connecting the points on the boundary line and the vertices, the model surface of the deep water area can be generated. The model surface of the waterfront area is generated in the same way. For the transition area, multiple points are set on each boundary line. By connecting the points on two boundary lines, the model surface of the transition area is obtained.
[0081] In most cases, the model faces are triangular, and the number of model faces in the water area can be preset, for example, the total number of faces can be set to 50. It is understandable that the more model faces there are, the more points need to be set on the boundary line of the area.
[0082] Step 23: Based on the type of water body region, set the vertex color of the model face within the water body region to obtain the terrain model used for rendering the target water body.
[0083] In order to use different rendering methods for different water areas, it is necessary to configure different material slots for each water area so that different rendering algorithms can be used for different water areas.
[0084] At the start of rendering, the terrain model used to render the target water body needs to be meshed to determine the model position corresponding to each pixel to be rendered in the scene, and then the Pixel Shader is called to start calculating the rendering result.
[0085] For the aforementioned waterfront area, it is set to transparent and not displayed. That is, in the waterfront area, the rendering effect of the water body is not displayed, only the rendering effect of the terrain itself, such as the land effect, is displayed.
[0086] For deep water and transition areas, the normal direction of the pixels to be rendered needs to be determined in advance. Specifically, based on the model's position parameters, preset time parameters, and preset first configuration parameters, the normal map is sampled to obtain a first sampling result; based on this first sampling result, the normal direction of the pixels to be rendered is determined. The aforementioned first configuration parameters typically include one or more parameters, which usually need to be set in advance; the aforementioned position parameters, time parameters, and first configuration parameters are used to determine the sampling coordinates, and then the normal map is sampled according to these sampling coordinates; the normal map also needs to be set in advance, and this normal map includes multiple normal directions, with different normal directions stored at different position coordinates in the normal map.
[0087] In one specific implementation, the first configuration parameter includes an initial value parameter and a coordinate value parameter; in this embodiment, the initial value parameter is represented as R1, and the coordinate value parameter is represented as (SU1, SV1). The coordinate value parameter can represent the offset rate of the first position vector; the larger the rate, the faster the wave cycle.
[0088] First, a first position vector is generated based on the position coordinates of the model. Since the terrain model is located in a three-dimensional world space, the position coordinates are three-dimensional coordinates. In this embodiment, after obtaining the position coordinates of the model, the position coordinates are normalized to a specific length unit, such as meters. Then, the X and Y coordinates are extracted from the normalized position coordinates. The extracted X and Y coordinates form a two-dimensional vector, namely the first position vector mentioned above, which can be represented as WPUV1.
[0089] Then, the product of the initial value parameter and the first position vector is used as the first intermediate result, and the product of the time parameter and the coordinate value parameter is used as the second intermediate result; the sum of the first intermediate result and the second intermediate result is determined as the first sampling coordinate; the normal map is sampled according to the first sampling coordinate to obtain the first sampling result.
[0090] The first sampling coordinate can be represented as SampleUV1, and the first sampling coordinate can be calculated using the following formula:
[0091] SampleUV1=R1*WPUV1+Time*(SU1,SV1)
[0092] Where R1 is the initial value parameter mentioned above; WPUV1 is the first position vector mentioned above; Time is the time parameter mentioned above, which can be the clock time provided by the rendering engine; (SU1,SV1) is the coordinate value parameter mentioned above.
[0093] After obtaining the first sampling result, further processing is required to obtain the normal direction of the pixel to be rendered. Specifically, the first configuration parameter mentioned above also includes an amplitude parameter, which can be represented as I1; extracting the normal component in the horizontal direction from the first sampling result; and determining the normal direction of the pixel to be rendered based on the product of the extracted normal component and the amplitude parameter.
[0094] The first sampling result includes three channels: RGB, which respectively store the normal components in the X, Y, and Z directions. The normal components in the X and Y directions can be obtained from the RG channel, which are the normal components in the aforementioned horizontal plane direction. The Z direction is perpendicular to the horizontal plane direction.
[0095] To further enrich the wave effects in the water and reduce the repetitiveness of the waves, the aforementioned first configuration parameters include multiple sets; the parameter values of the multiple sets of first configuration parameters are different. As can be seen from the foregoing embodiments, the first set of first configuration parameters includes the initial value parameter R1, the coordinate value parameter (SU1, SV1), and the wave amplitude parameter I1. Each set of first configuration parameters can correspond to a wave effect. Through multiple configuration parameters, multiple wave effects can be superimposed, and different wave effects have different wave heights, wave widths, and frequencies. For example, taking three sets of first configuration parameters as an example, the first set of first configuration parameters is the initial value parameter R1, the coordinate value parameter (SU1, SV1), and the wave amplitude parameter I1; the second set of first configuration parameters is the initial value parameter R2, the coordinate value parameter (SU2, SV2), and the wave amplitude parameter I2; and the third set of first configuration parameters is the initial value parameter R3, the coordinate value parameter (SU3, SV3), and the wave amplitude parameter I3.
[0096] For each set of first configuration parameters, the normal map is sampled based on the model's position parameters, preset time parameters, and preset first configuration parameters to obtain the first sampling result, resulting in multiple first sampling results; based on the multiple first sampling results, the normal direction of the pixel to be rendered is determined.
[0097] By performing the above processing using the first configuration parameters of each group, a normal direction can be calculated. Multiple normal directions are obtained in total. The multiple normal directions are superimposed, and the superposition result is normalized to obtain the final normal direction of the pixel to be rendered.
[0098] For example, using R1 and (SU2,SV2) from the second set of first configuration parameters, the sampling coordinate SampleUV2 = R2*WPUV + Time*(SU2,SV2) is calculated; the normal map is sampled using the sampling coordinate SampleUV2 to obtain another sampling coordinate, which in turn yields another first sampling result. This first sampling result is then processed using the amplitude parameter I2 to obtain another normal direction. The third set of first configuration parameters is used in the same way.
[0099] After obtaining the normal direction of the pixel to be rendered using the above method, for deep water areas, the pixel to be rendered corresponding to the model position is rendered directly based on the normal direction, the lighting direction at the model position, and the first color parameter, thus obtaining the rendering result of the pixel to be rendered. The first color parameter can be pre-configured.
[0100] For the transition region, since it is connected to the deep water region, the normal direction is calculated in the same way as that of the deep water region, ensuring a continuous visual effect between the two regions. Besides the normal direction, the transition region also needs to calculate the color parameters of the pixels to be rendered before rendering. Specifically, for the model location within the transition region, based on the model's position parameters and preset time parameters, a preset noise map is sampled to obtain a second sampling result; based on the second sampling result and the vertex color corresponding to the model's position, foam control parameters are determined; based on the foam control parameters, preset foam color parameters, and water color parameters, second color parameters are determined.
[0101] The noise map here can be preset, and different color parameters are stored at different positions of the noise map. The sampling coordinates of the noise map are determined based on the position and time parameters, which can make the obtained second sampling result have periodic variation characteristics. The second sampling result, together with the vertex color of the model position, determines the foam control parameters, which can make the foam change periodic variation characteristics. At the same time, the model position is also taken into account. For example, the periodic variation of the foam is synchronized with the periodic variation of the waves, and the foam gradually becomes smaller as it gets closer to the water's edge.
[0102] In one specific implementation, firstly, for the model location belonging to the transition area, a second position vector is generated based on the position coordinates of the model location. Since the terrain model is located in three-dimensional world space, the position coordinates are three-dimensional coordinates. In this embodiment, after obtaining the position coordinates of the model location, the position coordinates are normalized to a specific length unit, such as meters. Then, the X and Y coordinates are extracted from the normalized position coordinates. The extracted X and Y coordinates form a two-dimensional vector, namely the second position vector mentioned above, which can be represented as WPUV2.
[0103] Then, the product of the preset second configuration parameter and the time parameter is added to the second position vector to obtain the sum; the product of the sum and the preset third configuration parameter is determined as the second sampling coordinate; the noise map is sampled according to the second sampling coordinate to obtain the second sampling result.
[0104] The second sampling coordinates mentioned above can be represented as SampleUV, and can be calculated using the following formula:
[0105] SampleUV=S0*(S1*Time+WPUV2);
[0106] Where S0 represents the third configuration parameter; S1 represents the second configuration parameter; Time represents the time parameter, which can be the clock time provided by the rendering engine; and WPUV2 represents the second position vector.
[0107] After obtaining the second sampling result, the channel vertex color value of the first specified channel is extracted from the vertex color corresponding to the model position; for example, this first specified channel can usually be the R channel. Then, the first channel parameter is obtained by subtracting the channel vertex color value from a preset third fixed value; specifically, this third fixed value can be 1, the channel vertex color value is represented as x, and the first channel parameter is obtained by calculating 1-x, represented as R0. The square root of the first channel parameter is performed to obtain the second channel parameter; the second channel parameter can be obtained by sqrt(1-R0), and this second channel parameter is represented as S. Finally, based on the second sampling result, the first channel parameter, and the second channel parameter, the foam control parameters are determined.
[0108] When determining the foam control parameters, the channel sampling value of the second designated channel is extracted from the second sampling result; for example, the second designated channel can be the R channel, that is, the red component in the second sampling result; the product of the fourth configuration parameter power of the channel sampling value and the second channel parameter is used as the third intermediate result; the product of the fifth configuration parameter and the time parameter is used as the fourth intermediate result; the difference between the third intermediate result and the fourth intermediate result is calculated, and the square of the sine value of the difference is multiplied by the first channel parameter to obtain the foam control parameters.
[0109] The foam control parameter here is denoted as FoamFactor, and it can be calculated using the following formula:
[0110] FoamFactor=sin 2 (S*pow(R,S2)-S3*Time)*R0
[0111] Where S represents the second channel parameter mentioned above; R represents the channel sample value mentioned above; S2 represents the fourth configuration parameter; pow(R,S2) represents the fourth configuration parameter raised to the power of the channel sample value; S3 represents the fifth configuration parameter; Time represents the time parameter, which can be the clock time provided by the rendering engine; and R0 represents the first channel parameter.
[0112] After obtaining the foam control parameters, the water body color parameters are determined based on the first color parameter and the preset shallow water color parameter. The foam control parameters are used as interpolation weights to interpolate the water body color parameters and the foam color parameters to obtain the second color parameter.
[0113] The first color parameter here is the color parameter configured for the aforementioned deep water area, and the shallow water color parameter is also a pre-configured color parameter. Generally, the color corresponding to the shallow water color parameter is lighter than the light color corresponding to the first color parameter. For example, the first color parameter corresponds to dark blue, while the shallow water color parameter corresponds to light blue.
[0114] In one approach, the foam control parameter is denoted as FoamFactor, the water color parameter as WaterColor, and the foam color parameter as FoamFactor. The second color parameter can be calculated using the lerp function, i.e., lerp(WaterColor, FoamColor, FoamFactor). Of course, besides the lerp function, other interpolation functions can also be used to interpolate the water color parameter and the foam color parameter to obtain the second color parameter.
[0115] Specifically, when calculating the water color parameters, the sixth power of the configuration parameter of the first channel parameter is used as the interpolation weight to interpolate the first color parameter and the shallow water color parameter to obtain the water color parameters. The first channel parameter is obtained by extracting the channel vertex color value of the first specified channel from the vertex color corresponding to the model position; and subtracting the channel vertex color value from the preset third fixed value to obtain the first channel parameter.
[0116] The water color parameter is denoted as WaterColor and can be calculated using the following formula: WaterColor = lerp(ColorD, ColorS, pow(R0, S4); where ColorD represents the first color parameter mentioned above; ColorS represents the shallow water color parameter; R0 represents the first channel parameter; and S4 represents the preset sixth configuration parameter. Of course, besides the lerp function, other interpolation functions can also be used to interpolate the first color parameter and the shallow water color parameter to obtain the water color parameter.
[0117] Additionally, for transition areas, rendering transparency parameters, typically expressed as Opacity values, need to be set. Specifically, the rendering transparency parameters are determined based on the vertex color corresponding to the model's location; then, based on the rendering transparency parameters, the second color parameter, and the lighting and normal directions at the model's location, the pixels to be rendered at that location are rendered. For example, the R channel color value of the vertex color at the model's location is used, and this color value is mapped to a preset numerical range to obtain the aforementioned rendering transparency parameters.
[0118] For example, the color value range of the R channel in the vertex color is [0,1], while the range of the rendering transparency parameter is [0.5,1]. By mapping the color value of the R channel in the vertex color to [0.5,1], the rendering transparency parameter of the pixel to be rendered can be obtained.
[0119] For the aforementioned method embodiments, see [link to relevant documentation]. Figure 4 The diagram shows a structural schematic of a water rendering device, which includes:
[0120] The model acquisition module 40 is used to acquire a terrain model for rendering the target water body; wherein, the model faces in the terrain model are set with vertex colors; the vertex colors are used to represent the water body region to which the model faces belong in the target water body; the water body region includes deep water region and transition region; in the transition region, the vertex colors of the model faces gradually change along a specified direction;
[0121] The normal direction determination module 42 is used to determine the model position of the pixel to be rendered mapped onto the terrain model; based on the position parameters of the model position and the preset time parameters, the normal map is sampled at least once to obtain the normal direction of the pixel to be rendered; wherein, the normal direction is used to control the rendering wave effect;
[0122] The first rendering module 44 is used to render the pixels to be rendered corresponding to the model position that belongs to the deep water area based on the normal direction, the lighting direction of the model position and the first color parameter.
[0123] The second rendering module 46 is used to determine a second color parameter for the model position belonging to the transition area based on the position parameter of the model position, the vertex color corresponding to the model position, and the preset time parameter; the second color parameter is used to control the water color and foam effect of the rendering transition area; based on the second color parameter, the lighting direction and normal direction of the model position, the pixel to be rendered corresponding to the model position is rendered to obtain the rendered target water body.
[0124] The aforementioned water rendering device acquires a terrain model for rendering a target water body. The model faces in the terrain model are assigned vertex colors. These vertex colors represent the water region to which the model faces belong within the target water body. The water region includes deep water and transition regions. In the transition region, the vertex colors of the model faces gradually change along a specified direction. The device determines the model position of the pixel to be rendered mapped onto the terrain model. Based on the position parameters of the model position and preset time parameters, it samples the normal map at least once to obtain the normal direction of the pixel to be rendered. The normal direction is used to control the rendering of wave effects. For model positions belonging to deep water regions, the device renders the corresponding pixel based on the normal direction, the lighting direction of the model position, and a first color parameter. For model positions belonging to transition regions, a second color parameter is determined based on the position parameters of the model position, the vertex color corresponding to the model position, and preset time parameters. The second color parameter controls the water color and foam effects in the transition region. Based on the second color parameter, the lighting direction of the model position, and the normal direction, the device renders the corresponding pixel to obtain the rendered target water body.
[0125] In this method, the terrain model is pre-divided into multiple water areas, and different algorithms are used to calculate rendering parameters for different water areas to complete the rendering of the water bodies. This method does not require modification of the overall parameters of the terrain system. It renders water bodies on the terrain system through patches, resulting in lower computational load and saving performance overhead. It is more user-friendly for mobile devices with limited resources and is beneficial for rendering on mobile devices.
[0126] The aforementioned terrain model includes multiple models; for a terrain model located at the edge of the target water body, the terrain model includes a deep water area and a transition area; in the deep water area, the vertex color of the model face is a preset first fixed value; in the transition area, the further away the model face is from the deep water area, the greater the difference between the vertex color of the model face and the first fixed value.
[0127] The above-mentioned terrain model for the edge of the target water body includes a waterfront area; the vertex color of the model face in the waterfront area is a preset second fixed value; the second fixed value is different from the first fixed value; in the transition area, the closer the model face is to the waterfront area, the smaller the difference between the vertex color of the model face and the second fixed value.
[0128] The aforementioned device also includes a model generation module, used for: setting regional boundary lines on the initial terrain model to divide the initial terrain model into multiple water body regions through the regional boundary lines; generating model surfaces of the water body regions based on the edge lines of the water body regions; wherein the edge lines of the water body regions include: regional boundary lines surrounding the water body regions and / or model edge lines of the initial terrain model; and setting the vertex colors of the model surfaces within the water body regions according to the type of water body region, to obtain a terrain model for rendering the target water body.
[0129] The aforementioned normal direction determination module is also used to: sample the normal map based on the position parameters of the model position, preset time parameters, and preset first configuration parameters to obtain a first sampling result; and determine the normal direction of the pixel to be rendered based on the first sampling result.
[0130] The aforementioned first configuration parameters include initial value parameters and coordinate value parameters; the aforementioned normal direction determination module is further used to: generate a first position vector based on the position coordinates of the model position; use the product of the initial value parameters and the first position vector as a first intermediate result, and use the product of the time parameters and the coordinate value parameters as a second intermediate result; determine the sum of the first intermediate result and the second intermediate result as the first sampling coordinates; and sample the normal map according to the first sampling coordinates to obtain the first sampling result.
[0131] The first configuration parameter mentioned above also includes an amplitude parameter; the normal direction determination module mentioned above is further used to: extract the normal component in the horizontal direction from the first sampling result; and determine the normal direction of the pixel to be rendered based on the product of the extracted normal component and the amplitude parameter.
[0132] The aforementioned first configuration parameters include multiple sets; the parameter values between the multiple sets of first configuration parameters are different; the aforementioned normal direction determination module is also used for: for each set of first configuration parameters, performing a step of sampling the normal map based on the model position parameters, preset time parameters and preset first configuration parameters to obtain a first sampling result, thereby obtaining multiple first sampling results; and determining the normal direction of the pixel to be rendered based on the multiple first sampling results.
[0133] The second rendering module is also used to: for model positions belonging to the transition region, sample a preset noise map based on the position parameters of the model position and preset time parameters to obtain a second sampling result; determine the foam control parameters based on the second sampling result and the vertex color corresponding to the model position; and determine the second color parameters based on the foam control parameters, preset foam color parameters and water color parameters.
[0134] The second rendering module is further configured to: generate a second position vector based on the position coordinates of the model position for the model position belonging to the transition region; add the product of the preset second configuration parameter and the time parameter to the second position vector to obtain the addition result; determine the second sampling coordinates by multiplying the addition result with the preset third configuration parameter; and sample the noise map according to the second sampling coordinates to obtain the second sampling result.
[0135] The second rendering module is further configured to: extract the channel vertex color value of the first specified channel from the vertex color corresponding to the model position; subtract the channel vertex color value from the preset third fixed value to obtain the first channel parameter; perform a square root operation on the first channel parameter to obtain the second channel parameter; and determine the foam control parameter based on the second sampling result, the first channel parameter, and the second channel parameter.
[0136] The second rendering module is further configured to: extract the channel sample value of the second specified channel from the second sampling result; multiply the fourth power of the channel sample value by the second channel parameter as the third intermediate result; multiply the fifth configuration parameter by the time parameter as the fourth intermediate result; calculate the difference between the third intermediate result and the fourth intermediate result, and multiply the square of the sine of the difference by the first channel parameter to obtain the foam control parameter.
[0137] The second rendering module is also used to: determine the water body color parameters based on the first color parameters and the preset shallow water color parameters; and use the foam control parameters as interpolation weights to interpolate the water body color parameters and the foam color parameters to obtain the second color parameters.
[0138] The second rendering module is further configured to: use the sixth power of the configuration parameter of the first channel parameter as the interpolation weight to interpolate the first color parameter and the shallow water color parameter to obtain the water color parameter; wherein, the first channel parameter is obtained by: extracting the channel vertex color value of the first specified channel from the vertex color corresponding to the model position; and subtracting the channel vertex color value from the preset third fixed value to obtain the first channel parameter.
[0139] The second rendering module is also used to: determine the rendering transparency parameter based on the vertex color corresponding to the model position; and render the pixels to be rendered corresponding to the model position based on the rendering transparency parameter, the second color parameter, the lighting direction and normal direction of the model position.
[0140] This embodiment also provides an electronic device, including a processor and a memory. The memory stores machine-executable instructions that can be executed by the processor, and the processor executes the machine-executable instructions to implement the above-described water rendering method. This electronic device can be a server or a touch-screen terminal device.
[0141] See Figure 5 As shown, the electronic device includes a processor 100 and a memory 101. The memory 101 stores machine-executable instructions that can be executed by the processor 100. The processor 100 executes the machine-executable instructions to implement the above-described water rendering method.
[0142] Furthermore, Figure 5 The electronic device shown also includes a bus 102 and a communication interface 103, with the processor 100, the communication interface 103 and the memory 101 connected via the bus 102.
[0143] The memory 101 may include high-speed random access memory (RAM) or non-volatile memory, such as at least one disk storage device. Communication between this system network element and at least one other network element is achieved through at least one communication interface 103 (which can be wired or wireless), such as the Internet, wide area network, local area network, or metropolitan area network. The bus 102 may be an ISA bus, PCI bus, or EISA bus, etc. The bus can be divided into address bus, data bus, control bus, etc. For ease of representation, Figure 5 The symbol is represented by a single double-headed arrow, but this does not mean that there is only one bus or one type of bus.
[0144] Processor 100 may be an integrated circuit chip with signal processing capabilities. In implementation, each step of the above method can be completed by the integrated logic circuitry in the hardware of processor 100 or by instructions in software form. Processor 100 may be a general-purpose processor, including a Central Processing Unit (CPU), a Network Processor (NP), etc.; it may also be a Digital Signal Processor (DSP), an Application Specific Integrated Circuit (ASIC), a Field-Programmable Gate Array (FPGA), or other programmable logic devices, discrete gate or transistor logic devices, or discrete hardware components. It can implement or execute the methods, steps, and logic block diagrams disclosed in the embodiments of this invention. The general-purpose processor may be a microprocessor or any conventional processor. The steps of the methods disclosed in the embodiments of this invention can be directly manifested as execution by a hardware decoding processor, or execution by a combination of hardware and software modules in the decoding processor. The software module can reside in a readily available storage medium in the art, such as random access memory, flash memory, read-only memory, programmable read-only memory, electrically erasable programmable memory, or registers. This storage medium is located in memory 101, and the processor 100 reads the information from memory 101 and, in conjunction with its hardware, completes the steps of the method described in the foregoing embodiments.
[0145] The processor in the aforementioned electronic device, by executing machine-executable instructions, can perform the following operations in the aforementioned water rendering method:
[0146] Obtain a terrain model for rendering the target water body; wherein, the model faces in the terrain model are set with vertex colors; the vertex colors are used to represent the water body region to which the model faces belong in the target water body; the water body region includes deep water region and transition region; in the transition region, the vertex colors of the model faces gradually change along a specified direction; determine the model position of the pixel to be rendered mapped onto the terrain model; based on the position parameters of the model position and the preset time parameters, sample the normal map at least once to obtain the normal direction of the pixel to be rendered; wherein, the normal direction is used to control the rendering wave effect; for the model position belonging to the deep water region, render the pixel to be rendered corresponding to the model position based on the normal direction, the lighting direction of the model position, and the first color parameter; for the model position belonging to the transition region, determine the second color parameter based on the position parameters of the model position, the vertex color corresponding to the model position, and the preset time parameter; the second color parameter is used to control the water color and foam effect in the transition region; based on the second color parameter, the lighting direction and the normal direction of the model position, render the pixel to be rendered corresponding to the model position to obtain the rendered target water body.
[0147] The terrain model includes multiple parts; for the terrain model located at the edge of the target water body, the terrain model includes a deep water area and a transition area; in the deep water area, the vertex color of the model face is a preset first fixed value; in the transition area, the further away the model face is from the deep water area, the greater the difference between the vertex color of the model face and the first fixed value.
[0148] For a terrain model located at the edge of the target water body, the terrain model also includes a waterfront area; the vertex color of the model face in the waterfront area is a preset second fixed value; the second fixed value is different from the first fixed value; in the transition area, the closer the model face is to the waterfront area, the smaller the difference between the vertex color of the model face and the second fixed value.
[0149] Set region boundaries on the initial terrain model to divide the initial terrain model into multiple water body regions; generate model faces of the water body regions based on the edge lines of the water body regions; wherein, the edge lines of the water body regions include: the region boundaries surrounding the water body regions and / or the model edge lines of the initial terrain model; set the vertex colors of the model faces within the water body regions according to the type of water body region to obtain the terrain model used to render the target water body.
[0150] Based on the model's position parameters, preset time parameters, and preset first configuration parameters, the normal map is sampled to obtain a first sampling result; based on the first sampling result, the normal direction of the pixel to be rendered is determined.
[0151] The first configuration parameters include initial value parameters and coordinate value parameters; based on the position coordinates of the model position, a first position vector is generated; the product of the initial value parameters and the first position vector is used as the first intermediate result, and the product of the time parameter and the coordinate value parameters is used as the second intermediate result; the sum of the first intermediate result and the second intermediate result is determined as the first sampling coordinates; the normal map is sampled according to the first sampling coordinates to obtain the first sampling result.
[0152] The first configuration parameters also include amplitude parameters; extracting the normal components in the horizontal direction from the first sampling result; and determining the normal direction of the pixel to be rendered based on the product of the extracted normal components and the amplitude parameters.
[0153] The first configuration parameters include multiple sets; the parameter values between the multiple sets of first configuration parameters are different; for each set of first configuration parameters, the normal map is sampled based on the position parameters of the model position, the preset time parameters, and the preset first configuration parameters to obtain the first sampling result, resulting in multiple first sampling results; based on the multiple first sampling results, the normal direction of the pixel to be rendered is determined.
[0154] For model locations belonging to transition regions, based on the model location's position parameters and preset time parameters, a preset noise map is sampled to obtain a second sampling result; based on the second sampling result and the vertex color corresponding to the model location, foam control parameters are determined; based on the foam control parameters, preset foam color parameters, and water color parameters, a second color parameter is determined.
[0155] For model locations belonging to the transition region, a second position vector is generated based on the model's position coordinates; the product of the preset second configuration parameter and the time parameter is added to the second position vector to obtain the sum; the product of the sum and the preset third configuration parameter is determined as the second sampling coordinates; the noise map is sampled according to the second sampling coordinates to obtain the second sampling result.
[0156] Extract the channel vertex color value of the first specified channel from the vertex color corresponding to the model position; subtract the channel vertex color value from the preset third fixed value to obtain the first channel parameter; perform a square root operation on the first channel parameter to obtain the second channel parameter; determine the foam control parameter based on the second sampling result, the first channel parameter and the second channel parameter.
[0157] Extract the channel sample value of the second specified channel from the second sampling result; multiply the fourth power of the channel sample value by the second channel parameter as the third intermediate result; multiply the fifth configuration parameter by the time parameter as the fourth intermediate result; calculate the difference between the third intermediate result and the fourth intermediate result, and multiply the square of the sine of the difference by the first channel parameter to obtain the foam control parameter.
[0158] Based on the first color parameter and the preset shallow water color parameter, the water body color parameter is determined; the foam control parameter is used as the interpolation weight to interpolate the water body color parameter and the foam color parameter to obtain the second color parameter.
[0159] The sixth power of the first channel parameter is used as the interpolation weight to interpolate the first color parameter and the shallow water color parameter to obtain the water color parameter. The first channel parameter is obtained by extracting the channel vertex color value of the first specified channel from the vertex color corresponding to the model position; and subtracting the channel vertex color value from the preset third fixed value to obtain the first channel parameter.
[0160] Based on the vertex color corresponding to the model position, the rendering transparency parameter is determined; based on the rendering transparency parameter, the second color parameter, the lighting direction and normal direction of the model position, the pixel to be rendered corresponding to the model position is rendered.
[0161] In this method, the terrain model is pre-divided into multiple water areas, and different algorithms are used to calculate rendering parameters for different water areas to complete the rendering of the water bodies. This method does not require modification of the overall parameters of the terrain system. It renders water bodies on the terrain system through patches, resulting in lower computational load and saving performance overhead. It is more user-friendly for mobile devices with limited resources and is beneficial for rendering on mobile devices.
[0162] This embodiment also provides a machine-readable storage medium storing machine-executable instructions. When the machine-executable instructions are called and executed by a processor, the machine-executable instructions cause the processor to implement the above-described water rendering method.
[0163] The machine-executable instructions stored in the aforementioned machine-readable storage medium can be executed to perform the following operations in the aforementioned water rendering method:
[0164] Obtain a terrain model for rendering the target water body; wherein, the model faces in the terrain model are set with vertex colors; the vertex colors are used to represent the water body region to which the model faces belong in the target water body; the water body region includes deep water region and transition region; in the transition region, the vertex colors of the model faces gradually change along a specified direction; determine the model position of the pixel to be rendered mapped onto the terrain model; based on the position parameters of the model position and the preset time parameters, sample the normal map at least once to obtain the normal direction of the pixel to be rendered; wherein, the normal direction is used to control the rendering wave effect; for the model position belonging to the deep water region, render the pixel to be rendered corresponding to the model position based on the normal direction, the lighting direction of the model position, and the first color parameter; for the model position belonging to the transition region, determine the second color parameter based on the position parameters of the model position, the vertex color corresponding to the model position, and the preset time parameter; the second color parameter is used to control the water color and foam effect in the transition region; based on the second color parameter, the lighting direction and the normal direction of the model position, render the pixel to be rendered corresponding to the model position to obtain the rendered target water body.
[0165] The terrain model includes multiple parts; for the terrain model located at the edge of the target water body, the terrain model includes a deep water area and a transition area; in the deep water area, the vertex color of the model face is a preset first fixed value; in the transition area, the further away the model face is from the deep water area, the greater the difference between the vertex color of the model face and the first fixed value.
[0166] For a terrain model located at the edge of the target water body, the terrain model also includes a waterfront area; the vertex color of the model face in the waterfront area is a preset second fixed value; the second fixed value is different from the first fixed value; in the transition area, the closer the model face is to the waterfront area, the smaller the difference between the vertex color of the model face and the second fixed value.
[0167] Set region boundaries on the initial terrain model to divide the initial terrain model into multiple water body regions; generate model faces of the water body regions based on the edge lines of the water body regions; wherein, the edge lines of the water body regions include: the region boundaries surrounding the water body regions and / or the model edge lines of the initial terrain model; set the vertex colors of the model faces within the water body regions according to the type of water body region to obtain the terrain model used to render the target water body.
[0168] Based on the model's position parameters, preset time parameters, and preset first configuration parameters, the normal map is sampled to obtain a first sampling result; based on the first sampling result, the normal direction of the pixel to be rendered is determined.
[0169] The first configuration parameters include initial value parameters and coordinate value parameters; based on the position coordinates of the model position, a first position vector is generated; the product of the initial value parameters and the first position vector is used as the first intermediate result, and the product of the time parameter and the coordinate value parameters is used as the second intermediate result; the sum of the first intermediate result and the second intermediate result is determined as the first sampling coordinates; the normal map is sampled according to the first sampling coordinates to obtain the first sampling result.
[0170] The first configuration parameters also include amplitude parameters; extracting the normal components in the horizontal direction from the first sampling result; and determining the normal direction of the pixel to be rendered based on the product of the extracted normal components and the amplitude parameters.
[0171] The first configuration parameters include multiple sets; the parameter values between the multiple sets of first configuration parameters are different; for each set of first configuration parameters, the normal map is sampled based on the position parameters of the model position, the preset time parameters, and the preset first configuration parameters to obtain the first sampling result, resulting in multiple first sampling results; based on the multiple first sampling results, the normal direction of the pixel to be rendered is determined.
[0172] For model locations belonging to transition regions, based on the model location's position parameters and preset time parameters, a preset noise map is sampled to obtain a second sampling result; based on the second sampling result and the vertex color corresponding to the model location, foam control parameters are determined; based on the foam control parameters, preset foam color parameters, and water color parameters, a second color parameter is determined.
[0173] For model locations belonging to the transition region, a second position vector is generated based on the model's position coordinates; the product of the preset second configuration parameter and the time parameter is added to the second position vector to obtain the sum; the product of the sum and the preset third configuration parameter is determined as the second sampling coordinates; the noise map is sampled according to the second sampling coordinates to obtain the second sampling result.
[0174] Extract the channel vertex color value of the first specified channel from the vertex color corresponding to the model position; subtract the channel vertex color value from the preset third fixed value to obtain the first channel parameter; perform a square root operation on the first channel parameter to obtain the second channel parameter; determine the foam control parameter based on the second sampling result, the first channel parameter and the second channel parameter.
[0175] Extract the channel sample value of the second specified channel from the second sampling result; multiply the fourth power of the channel sample value by the second channel parameter as the third intermediate result; multiply the fifth configuration parameter by the time parameter as the fourth intermediate result; calculate the difference between the third intermediate result and the fourth intermediate result, and multiply the square of the sine of the difference by the first channel parameter to obtain the foam control parameter.
[0176] Based on the first color parameter and the preset shallow water color parameter, the water body color parameter is determined; the foam control parameter is used as the interpolation weight to interpolate the water body color parameter and the foam color parameter to obtain the second color parameter.
[0177] The sixth power of the first channel parameter is used as the interpolation weight to interpolate the first color parameter and the shallow water color parameter to obtain the water color parameter. The first channel parameter is obtained by extracting the channel vertex color value of the first specified channel from the vertex color corresponding to the model position; and subtracting the channel vertex color value from the preset third fixed value to obtain the first channel parameter.
[0178] Based on the vertex color corresponding to the model position, the rendering transparency parameter is determined; based on the rendering transparency parameter, the second color parameter, the lighting direction and normal direction of the model position, the pixel to be rendered corresponding to the model position is rendered.
[0179] In this method, the terrain model is pre-divided into multiple water areas, and different algorithms are used to calculate rendering parameters for different water areas to complete the rendering of the water bodies. This method does not require modification of the overall parameters of the terrain system. It renders water bodies on the terrain system through patches, resulting in lower computational load and saving performance overhead. It is more user-friendly for mobile devices with limited resources and is beneficial for rendering on mobile devices.
[0180] The computer program products of the water rendering method, apparatus and electronic device provided in the embodiments of the present invention include a computer-readable storage medium storing program code. The instructions included in the program code can be used to execute the methods described in the preceding method embodiments. For specific implementation, please refer to the method embodiments, which will not be repeated here.
[0181] Those skilled in the art will clearly understand that, for the sake of convenience and brevity, the specific working process of the system and apparatus described above can be referred to the corresponding process in the foregoing method embodiments, and will not be repeated here.
[0182] Furthermore, in the description of the embodiments of the present invention, unless otherwise explicitly specified and limited, the terms "installation," "connection," and "linking" should be interpreted broadly. For example, they can refer to a fixed connection, a detachable connection, or an integral connection; they can refer to a mechanical connection or an electrical connection; they can refer to a direct connection or an indirect connection through an intermediate medium; and they can refer to the internal connection of two components. Those skilled in the art can understand the specific meaning of the above terms in the present invention based on the specific circumstances.
[0183] If the aforementioned functions are implemented as software functional units and sold or used as independent products, they can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of this invention, essentially, or the part that contributes to the prior art, or a portion of the technical solution, can be embodied in the form of a software product. This computer software product is stored in a storage medium and includes several instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) to execute all or part of the steps of the methods described in the various embodiments of this invention. The aforementioned storage medium includes various media capable of storing program code, such as USB flash drives, portable hard drives, read-only memory (ROM), random access memory (RAM), magnetic disks, or optical disks.
[0184] In the description of this invention, it should be noted that the terms "center," "upper," "lower," "left," "right," "vertical," "horizontal," "inner," and "outer," etc., indicate the orientation or positional relationship based on the orientation or positional relationship shown in the accompanying drawings. They are used only for the convenience of describing the invention and for simplifying the description, and do not indicate or imply that the device or element referred to must have a specific orientation, or be constructed and operated in a specific orientation. Therefore, they should not be construed as limitations on the invention. Furthermore, the terms "first," "second," and "third" are used for descriptive purposes only and should not be construed as indicating or implying relative importance.
[0185] Finally, it should be noted that the above embodiments are merely specific implementations of the present invention, used to illustrate the technical solutions of the present invention, and not to limit it. The scope of protection of the present invention is not limited thereto. Although the present invention has been described in detail with reference to the foregoing embodiments, those skilled in the art should understand that any person skilled in the art can still modify or easily conceive of changes to the technical solutions described in the foregoing embodiments within the technical scope disclosed in the present invention, or make equivalent substitutions for some of the technical features; and these modifications, changes, or substitutions do not cause the essence of the corresponding technical solutions to deviate from the spirit and scope of the technical solutions of the embodiments of the present invention, and should all be covered within the scope of protection of the present invention. Therefore, the scope of protection of the present invention should be determined by the scope of the claims.
Claims
1. A water body rendering method, characterized in that, The method includes: Obtain a terrain model for rendering a target water body; wherein, the model faces in the terrain model are set with vertex colors; the vertex colors are used to characterize the water body region to which the model faces belong in the target water body; the water body region includes a deep water region and a transition region; the vertex colors of the model faces in the transition region gradually change along a specified direction; Determine the model position on the terrain model where the pixel to be rendered is mapped; based on the position parameters of the model position and preset time parameters, sample the normal map at least once to obtain the normal direction of the pixel to be rendered; wherein, the normal direction is used to control the rendering wave effect; For a model location belonging to a deep water area, the corresponding pixel to be rendered is rendered based on the normal direction, the lighting direction of the model location, and the first color parameter. For a model location belonging to the transition region, a second color parameter is determined based on the location parameters of the model location, the vertex color corresponding to the model location, and a preset time parameter. The second color parameter is used to control the rendering of the water color and foam effect in the transition region. Based on the second color parameter, the lighting direction of the model location, and the normal direction, the pixel to be rendered corresponding to the model location is rendered to obtain the rendered target water body.
2. The method according to claim 1, characterized in that, The terrain model includes multiple models; for the terrain model located at the edge of the target water body, the terrain model includes a deep water area and a transition area; The vertex color of the model face in the deep water region is a preset first fixed value; in the transition region, the further away the model face is from the deep water region, the greater the difference between the vertex color of the model face and the first fixed value.
3. The method according to claim 2, characterized in that, For a terrain model located at the edge of the target water body, the terrain model also includes a waterfront area; The vertex color of the model face in the waterfront area is a preset second fixed value; the second fixed value is different from the first fixed value; in the transition area, the closer the model face is to the waterfront area, the smaller the difference between the vertex color of the model face and the second fixed value.
4. The method according to claim 1, characterized in that, Prior to the step of obtaining a terrain model for rendering the target water body, the method further includes: Set regional boundary lines on the initial terrain model to divide the initial terrain model into multiple water body regions through the regional boundary lines; Based on the edge lines of the water body region, a model surface of the water body region is generated; wherein, the edge lines of the water body region include: the region boundary line surrounding the water body region and / or the model edge lines of the initial terrain model; Based on the type of water body region, the vertex colors of the model faces within the water body region are set to obtain a terrain model used for rendering the target water body.
5. The method according to claim 1, characterized in that, The step of sampling the normal map at least once based on the position parameters of the model location and preset time parameters to obtain the normal direction of the pixel to be rendered includes: Based on the location parameters of the model position, the preset time parameters, and the preset first configuration parameters, the normal map is sampled to obtain the first sampling result; Based on the first sampling result, the normal direction of the pixel to be rendered is determined.
6. The method according to claim 5, characterized in that, The first configuration parameters include initial value parameters and coordinate value parameters; The step of sampling the normal map based on the position parameters of the model position, preset time parameters, and preset first configuration parameters to obtain a first sampling result includes: Based on the position coordinates of the model location, a first position vector is generated; The product of the initial value parameter and the first position vector is used as the first intermediate result, and the product of the time parameter and the coordinate value parameter is used as the second intermediate result; the sum of the first intermediate result and the second intermediate result is determined as the first sampling coordinate. The normal map is sampled according to the first sampling coordinates to obtain the first sampling result.
7. The method according to claim 5, characterized in that, The first configuration parameter also includes the amplitude parameter; The step of determining the normal direction of the pixel to be rendered based on the first sampling result includes: Extract the normal component in the horizontal direction from the first sampling result; The normal direction of the pixel to be rendered is determined based on the product of the extracted normal component and the amplitude parameter.
8. The method according to claim 5, characterized in that, The first configuration parameters include multiple sets; the parameter values are different among the multiple sets of the first configuration parameters; the step of determining the normal direction of the pixel to be rendered based on the first sampling result includes: For each set of first configuration parameters, the normal map is sampled based on the position parameters of the model position, the preset time parameters, and the preset first configuration parameters to obtain a first sampling result, resulting in multiple first sampling results. Based on the multiple first sampling results, the normal direction of the pixel to be rendered is determined.
9. The method according to claim 1, characterized in that, For a model location belonging to a transition region, the step of determining the second color parameter based on the model location's position parameters, the vertex color corresponding to the model location, and preset time parameters includes: For model locations belonging to the transition region, based on the location parameters of the model location and the preset time parameters, a preset noise map is sampled to obtain a second sampling result; Based on the second sampling result and the vertex color corresponding to the model position, the foam control parameters are determined; Based on the foam control parameters, preset foam color parameters, and water color parameters, a second color parameter is determined.
10. The method according to claim 9, characterized in that, For model locations belonging to transition regions, the step of sampling a preset noise map based on the model location's position parameters and preset time parameters to obtain a second sampling result includes: For model locations belonging to the transition region, a second position vector is generated based on the position coordinates of the model location; The product of the preset second configuration parameter and the time parameter is added to the second position vector to obtain the sum; the product of the sum and the preset third configuration parameter is determined as the second sampling coordinate. The noise map is sampled according to the second sampling coordinates to obtain the second sampling result.
11. The method according to claim 9, characterized in that, The step of determining the foam control parameters based on the second sampling result and the vertex color corresponding to the model position includes: Extract the channel vertex color value of the first specified channel from the vertex color corresponding to the model position; The first channel parameter is obtained by subtracting the channel vertex color value from the preset third fixed value; the second channel parameter is obtained by taking the square root of the first channel parameter. Based on the second sampling result, the first channel parameters, and the second channel parameters, foam control parameters are determined.
12. The method according to claim 11, characterized in that, The step of determining foam control parameters based on the second sampling result, the first channel parameters, and the second channel parameters includes: Extract the channel sample value of the second specified channel from the second sampling result; The product of the fourth power of the channel sample value and the second channel parameter is used as the third intermediate result; the product of the fifth configuration parameter and the time parameter is used as the fourth intermediate result; the difference between the third intermediate result and the fourth intermediate result is calculated, and the square of the sine of the difference is multiplied by the first channel parameter to obtain the foam control parameter.
13. The method according to claim 9, characterized in that, The step of determining the second color parameter based on the foam control parameters, preset foam color parameters, and water color parameters includes: Based on the first color parameter and the preset shallow water color parameter, the water body color parameter is determined; Using the foam control parameters as interpolation weights, the water color parameters and the foam color parameters are interpolated to obtain the second color parameter.
14. The method according to claim 13, characterized in that, The step of determining the water body color parameter based on the first color parameter and the preset shallow water color parameter includes: The first color parameter and the shallow water color parameter are interpolated by using the sixth power of the first channel parameter as the interpolation weight to obtain the water body color parameter. The first channel parameter is obtained by extracting the channel vertex color value of the first specified channel from the vertex color corresponding to the model position; and subtracting the channel vertex color value from the preset third fixed value to obtain the first channel parameter.
15. The method according to claim 1, characterized in that, The step of rendering the pixel to be rendered corresponding to the model position based on the second color parameter, the lighting direction of the model position, and the normal direction includes: The rendering transparency parameter is determined based on the vertex color corresponding to the model position; Based on the rendering transparency parameter, the second color parameter, the lighting direction of the model position, and the normal direction, the pixel to be rendered corresponding to the model position is rendered.
16. A water body rendering device, characterized in that, The device includes: The model acquisition module is used to acquire a terrain model for rendering a target water body; wherein, the model faces in the terrain model are set with vertex colors; the vertex colors are used to characterize the water body region to which the model faces belong in the target water body; the water body region includes a deep water region and a transition region; the vertex colors of the model faces in the transition region gradually change along a specified direction; The normal direction determination module is used to determine the model position of the pixel to be rendered mapped onto the terrain model; based on the position parameters of the model position and preset time parameters, the normal map is sampled at least once to obtain the normal direction of the pixel to be rendered; wherein, the normal direction is used to control the rendering wave effect; The first rendering module is used to render the pixels to be rendered corresponding to the model position that belongs to the deep water area, based on the normal direction, the lighting direction of the model position and the first color parameter. The second rendering module is used to determine a second color parameter for a model position belonging to the transition region based on the position parameter of the model position, the vertex color corresponding to the model position, and a preset time parameter; the second color parameter is used to control the rendering of the water color and foam effect in the transition region; based on the second color parameter, the lighting direction of the model position, and the normal direction, the pixel to be rendered corresponding to the model position is rendered to obtain the rendered target water body.
17. An electronic device, characterized in that, It includes a processor and a memory, the memory storing machine-executable instructions that can be executed by the processor, the processor executing the machine-executable instructions to implement the water rendering method according to any one of claims 1-15.
18. A machine-readable storage medium, characterized in that, The machine-readable storage medium stores machine-executable instructions, which, when invoked and executed by a processor, cause the processor to implement the water rendering method according to any one of claims 1-15.
Citation Information
Patent Citations
Model mapping method and device and electronic equipment
CN114463477A
Building edge automatic fusion transition method and device based on depth detection
CN114581320A