Water body effect rendering method and device, equipment and storage medium
By determining the position of objects above the water surface and using binary mask maps for rendering, the method improves rendering efficiency and realism of water effects in game scenes, addressing the limitations of existing depth-based methods.
Patent Information
- Application Number
- CN202411053762.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-08-01
- Publication Date
- 2024-12-06
AI Technical Summary
Existing game development technologies for rendering water effects rely on depth maps, which are computationally intensive and cause performance lags, reducing rendering efficiency and player experience.
A method and device for rendering water effects that determine a target object above the water surface, generate a binary mask map, and perform preset effect rendering on the water body model, avoiding dependence on scene depth maps, and integrating vortex models for enhanced realism.
This approach simplifies the implementation process, reduces unnecessary computing overhead, and enhances the visual realism and immersion of water effects in game scenes.
Smart Images

Figure CN119091018A_ABST
Abstract
Description
Technical Field
[0001] The present disclosure relates to the field of computer technology, and in particular to a method, device, equipment and storage medium for rendering water effects. Background Art
[0002] In game development, the visual effects of water scenes usually have an important impact on the player's gaming experience. In related technologies, the display of water effects can be achieved by collecting the depth map in the scene. However, sampling the depth map in the scene is a relatively performance-consuming operation, which can easily cause lags during the game and reduce the rendering efficiency of the water effect. Summary of the invention
[0003] In order to solve at least one of the technical problems mentioned above, the present disclosure proposes a method, device, equipment and storage medium for rendering water effects.
[0004] According to a first aspect of an embodiment of the present disclosure, a method for rendering a water effect is provided, the method comprising:
[0005] Acquire a target scene set in a target game engine, wherein the target scene includes a water body model and at least one object model;
[0006] Determine a target object in the target scene, wherein the target object is an object in the at least one object model that is higher than a water surface of the water body model;
[0007] Generate a binary mask map based on the position of the target object in the target scene; the binary mask map includes a first color area and a second color area, and the second color area is the area corresponding to the target object;
[0008] Based on the second color area, determining a water body rendering area in the first color area;
[0009] The effect rendering area in the water body model is rendered with a preset effect to obtain a water body model with the preset effect, and the effect rendering area corresponds to the water body rendering area.
[0010] In an optional embodiment, the color value of the pixel point in the first color area is a first color value, the color value of the pixel point in the second color area is a second color value, and determining the water body rendering area in the first color area based on the second color area includes:
[0011] For each pixel point in the binary mask map, determining a target area in the binary mask map, wherein the target area is a square area with the pixel point as the center and a preset width as the side length;
[0012] In the case where there is a reference pixel in the target area, determining the shortest distance from the pixel to the reference pixel, where the reference pixel is a pixel in the second color area;
[0013] Based on the preset width, the closest distance is normalized to obtain a grayscale value corresponding to the pixel point;
[0014] An area formed by pixels whose grayscale values meet a preset condition is determined as the water body rendering area, and the preset condition is that the grayscale value is greater than the first color value and less than the second color value.
[0015] In an optional embodiment, before performing preset effect rendering on the effect rendering area in the water body model, the method further includes:
[0016] Generate a feathered mask map based on the grayscale value corresponding to each pixel in the binary mask map;
[0017] Performing blur processing on the feathered mask map to generate a blurred mask map;
[0018] Applying the blur mask map to the water model.
[0019] In an optional embodiment, the method further includes:
[0020] Creating a vortex preform model, wherein the vortex preform model includes a vortex edge region and a vortex concave region;
[0021] Integrate the vortex preform model into the water model; the vortex edge area is located on the water surface of the water model, and the vortex concave area is located below the water surface of the water model;
[0022] A preset vortex effect is rendered in the vortex concave area.
[0023] In an optional embodiment, rendering a preset vortex effect in the vortex concave area includes:
[0024] Rendering a transparent circle at the boundary between the vortex edge area and the vortex concave area, wherein the transparent circle is used to limit the rendering range of the vortex concave area;
[0025] In the template buffer of the target game engine, the template value of the transparent circular area is set to a preset template value; the template buffer is used to store the template value of the pixel, so that the rendering process is performed in the area formed by the pixels matching the corresponding template value;
[0026] configuring the template value of the preset swirl effect to be the preset template value;
[0027] Render the preset swirl effect.
[0028] In an optional embodiment, after rendering a preset vortex effect in the vortex concave area, the method further includes:
[0029] Creating a water flow direction diagram that matches the vortex depression area; the water flow direction diagram is used to record the flow direction and flow speed of the water flow outside the vortex depression area;
[0030] The water model is rendered based on the water flow direction diagram to obtain a water model with a vortex display effect.
[0031] In an optional embodiment, generating a binary mask map based on the position of the target object in the target scene includes:
[0032] Creating an initial mask map according to the size of the target scene; all pixels of the initial mask map have the first color value;
[0033] Based on the coordinates of the target object in the target scene, determine the pixel points corresponding to the coordinates in the initial mask map;
[0034] The corresponding pixel point is set to the second color value to obtain the binary mask map.
[0035] In an optional embodiment, determining the target object in the target scene includes:
[0036] Creating a detection box, wherein the bottom height of the detection box is the water surface height of the water body model;
[0037] In the area of the target scene, collision detection is performed based on the detection box to determine the target object in contact with the detection box.
[0038] In an optional embodiment, the method further includes:
[0039] Applying a preset vortex map to a preset area of the water model;
[0040] Determine the sinking depth of each vertex according to the distance from each vertex of the preset area to the center of the preset vortex map;
[0041] The sinking depth is applied to corresponding vertices in the preset area to obtain a water model with a vortex display effect.
[0042] According to a second aspect of an embodiment of the present disclosure, a device for rendering a water effect is provided, the device comprising:
[0043] A target scene acquisition module is configured to acquire a target scene set in a target game engine, wherein the target scene includes a water body model and at least one object model;
[0044] a target object determination module, configured to determine a target object in the target scene, wherein the target object is an object in the at least one object model that is higher than a water surface of the water body model;
[0045] A binary mask map generation module is configured to generate a binary mask map based on the position of the target object in the target scene; the binary mask map includes a first color area and a second color area, and the second color area is an area corresponding to the target object;
[0046] a water body rendering area determination module, configured to determine a water body rendering area in the first color area based on the second color area;
[0047] The preset effect rendering module is configured to perform preset effect rendering on the effect rendering area in the water body model to obtain a water body model with the preset effect, and the effect rendering area corresponds to the water body rendering area.
[0048] In an optional embodiment, the water body rendering area determination module includes:
[0049] A target region determining unit is configured to determine a target region in the binary mask map for each pixel in the binary mask map, wherein the target region is a square region with the pixel as the center and a preset width as the side length;
[0050] A closest distance determining unit is configured to determine the closest distance from the pixel to the reference pixel when there is a reference pixel in the target area, the reference pixel being a pixel in the second color area;
[0051] A closest distance processing unit is configured to perform normalization processing on the closest distance based on the preset width to obtain a grayscale value corresponding to the pixel point;
[0052] The rendering area determination unit is configured to determine an area formed by pixels whose grayscale values meet a preset condition as the water body rendering area, wherein the preset condition is that the grayscale value is greater than the first color value and less than the second color value.
[0053] In an optional embodiment, before performing preset effect rendering on the effect rendering area in the water body model, the device further includes:
[0054] A feathered mask map generation module is configured to generate a feathered mask map based on the grayscale value corresponding to each pixel in the binary mask map;
[0055] A fuzzy mask map generating module is configured to perform fuzzy processing on the feathered mask map to generate a fuzzy mask map;
[0056] The blur mask map application module is configured to apply the blur mask map to the water body model.
[0057] In an optional embodiment, the device further comprises:
[0058] A vortex preform creation module is configured to create a vortex preform model, wherein the vortex preform model includes a vortex edge region and a vortex concave region;
[0059] A vortex preform integration module is configured to integrate the vortex preform model into the water model; the vortex edge area is located on the water surface of the water model, and the vortex concave area is located below the water surface of the water model;
[0060] The preset vortex effect rendering module is configured to render a preset vortex effect in the vortex concave area.
[0061] In an optional embodiment, the preset swirl effect rendering module includes:
[0062] A transparent graphics rendering unit is configured to render a transparent circle at a boundary between the vortex edge area and the vortex concave area, wherein the transparent circle is used to limit a rendering range of the vortex concave area;
[0063] A template value setting unit is configured to set the template value of the transparent circular area to a preset template value in a template buffer of the target game engine; the template buffer is used to store the template value of the pixel so that the rendering process is performed in the area formed by the pixels matching the corresponding template value;
[0064] a preset swirl effect configuration unit, configured to configure the template value of the preset swirl effect to the preset template value;
[0065] The preset vortex effect rendering unit is configured to render the preset vortex effect.
[0066] In an optional embodiment, after rendering the preset vortex effect in the vortex concave area, the device further includes:
[0067] A water flow direction map creation module is configured to create a water flow direction map that matches the vortex concave area; the water flow direction map is used to record the flow direction and flow speed of the water flow outside the vortex concave area;
[0068] The water flow direction map rendering module is configured to render the water model based on the water flow direction map to obtain a water model with a vortex display effect.
[0069] In an optional embodiment, the binary mask map generation module includes:
[0070] An initial mask map creating unit is configured to create an initial mask map according to the size of the target scene; all pixels of the initial mask map are the first color value;
[0071] A pixel point determination unit is configured to determine, based on the coordinates of the target object in the target scene, the pixel points corresponding to the coordinates in the initial mask map;
[0072] The binary mask map generating unit is configured to set the corresponding pixel point to the second color value to obtain the binary mask map.
[0073] In an optional embodiment, the target object determination module includes:
[0074] A detection box creating unit is configured to create a detection box, wherein the bottom height of the detection box is the water surface height of the water body model;
[0075] The collision detection unit is configured to perform collision detection based on the detection box in the area of the target scene to determine the target object in contact with the detection box.
[0076] In an optional embodiment, the device further comprises:
[0077] A preset vortex map application module is configured to apply a preset vortex map to a preset area of the water body model;
[0078] A sinking depth determination module is configured to determine the sinking depth of each vertex according to the distance from each vertex of the preset area to the center of the preset vortex map;
[0079] The sinking depth application module is configured to apply the sinking depth to corresponding vertices in the preset area to obtain a water model with a vortex display effect.
[0080] According to a third aspect of an embodiment of the present disclosure, a computer-readable storage medium is provided, in which at least one instruction or at least one program is stored, and the at least one instruction or at least one program is loaded and executed by a processor to implement a method as described in any one of the first aspects above.
[0081] According to a fourth aspect of an embodiment of the present disclosure, an electronic device is provided, comprising at least one processor and a memory communicatively connected to the at least one processor; wherein the memory stores instructions executable by the at least one processor, and the at least one processor implements a method as described in any one of the above-mentioned first aspects by executing the instructions stored in the memory.
[0082] According to a fifth aspect of an embodiment of the present disclosure, a computer program product is provided, the computer program product comprising a computer program, the computer program being stored in a readable storage medium, at least one processor of a computer device reading and executing the computer program from the readable storage medium, so that the computer device performs a method as described in any one of the above-mentioned first aspects.
[0083] It is to be understood that both the foregoing general description and the following detailed description are exemplary and explanatory only and are not restrictive of the disclosure.
[0084] The implementation of this disclosure has the following beneficial effects:
[0085] By determining the position of the target object above the water surface in the scene, a binary mask map is generated, and the water rendering area is determined in the first color area based on the second color area of the binary mask map, thereby avoiding dependence on the scene depth map, simplifying the implementation process of the water effect, reducing unnecessary computing overhead, and improving rendering efficiency; performing preset effect rendering in the effect rendering area corresponding to the water rendering area makes the visual effect more realistic, enhancing the user's immersion in the scene.
[0086] Further features and aspects of the present disclosure will become apparent from the following detailed description of exemplary embodiments with reference to the attached drawings. BRIEF DESCRIPTION OF THE DRAWINGS
[0087] In order to more clearly illustrate the technical solutions and advantages in the embodiments of this specification or the prior art, the drawings required for use in the embodiments or the prior art descriptions are briefly introduced below. Obviously, the drawings described below are only some embodiments of this specification. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative work.
[0088] Figure 1 A schematic diagram showing an application environment according to an embodiment of the present disclosure;
[0089] Figure 2 A flow chart showing a method for rendering water effects according to an embodiment of the present disclosure is shown;
[0090] Figure 3 A schematic diagram showing a binary mask map according to an embodiment of the present disclosure;
[0091] Figure 4 A flowchart of determining a water body rendering area according to an embodiment of the present disclosure is shown;
[0092] Figure 5 A schematic diagram showing a froth effect according to an embodiment of the present disclosure;
[0093] Figure 6 A schematic diagram showing a depth effect according to an embodiment of the present disclosure;
[0094] Figure 7 A flowchart showing a preset swirl effect of rendering according to an embodiment of the present disclosure is shown;
[0095] Figure 8 A schematic diagram showing a vortex preform model according to an embodiment of the present disclosure;
[0096] Fig. 9 Another flowchart of rendering a preset swirl effect according to an embodiment of the present disclosure is shown;
[0097] Fig.10 A block diagram of a water effect rendering device according to an embodiment of the present disclosure is shown;
[0098] Fig.11 A block diagram of an electronic device for rendering water effects according to an embodiment of the present disclosure is shown;
[0099] Fig.12 A block diagram of another electronic device for rendering water effects according to an embodiment of the present disclosure is shown. DETAILED DESCRIPTION
[0100] In order to enable ordinary persons in the art to better understand the technical solutions of the present disclosure, the technical solutions in the embodiments of the present disclosure will be clearly and completely described below in conjunction with the accompanying drawings.
[0101] It should be noted that the terms "first", "second", etc. in the specification and claims of the present disclosure and the above-mentioned drawings are used to distinguish similar objects, and are not necessarily used to describe a specific order or sequence. It should be understood that the data used in this way can be interchanged where appropriate, so that the embodiments of the present disclosure described herein can be implemented in an order other than those illustrated or described herein. The embodiments described in the following exemplary embodiments do not represent all embodiments consistent with the present disclosure. Instead, they are merely examples of devices and methods consistent with some aspects of the present disclosure as detailed in the appended claims.
[0102] It should be noted that the user information (including but not limited to user device information, user personal information, etc.) and data (including but not limited to data for display, data for analysis, etc.) involved in this disclosure are all information and data authorized by the user or fully authorized by all parties.
[0103] See also Figure 1 , Figure 1 A schematic diagram of an application environment according to an embodiment of the present disclosure is shown, and the application environment may include a terminal 100 and a server 200 .
[0104] In an optional embodiment, the terminal 100 can be used to provide services such as water effect rendering corresponding to the game scene to any user. Specifically, the terminal 100 may include but is not limited to electronic devices such as smart phones, desktop computers, tablet computers, laptops, smart speakers, digital assistants, augmented reality (AR) / virtual reality (VR) devices, smart wearable devices, etc., and may also be software running on the above electronic devices, such as applications. Optionally, the operating system running on the electronic device may include but is not limited to Android system, IOS system, Linux, Windows, etc.
[0105] In an optional embodiment, the server 200 may provide background services for the terminal 100. Specifically, the server 200 may be an independent physical server, or a server cluster or distributed system composed of multiple physical servers, or a cloud server providing cloud computing services.
[0106] In addition, it should be noted that Figure 1 What is shown is only one application environment provided by the present disclosure. In actual application, other application environments may also be included, for example, more terminals may be included.
[0107] In the embodiments of this specification, the terminal 100 and the server 200 may be directly or indirectly connected via wired or wireless communication, which is not limited in this disclosure.
[0108] Figure 2 A flow chart of a method for rendering water effects according to an embodiment of the present disclosure is shown. Figure 2 As shown, the method may include the following steps:
[0109] In step S201, a target scene set in a target game engine is obtained.
[0110] The present disclosure does not limit the target scene. In one embodiment, the target scene may include a water body model and at least one object model. Specifically, the target game engine may be Unity, and the target scene may be a three-dimensional scene. The water body model is a model used to represent the water body in the three-dimensional scene, including the geometric shape and material properties of the water surface. The object model is a model used to represent objects in the three-dimensional scene, such as buildings, ground, trees, and stones, including the geometric data, material information, and texture of the objects.
[0111] In step 203, a target object in the target scene is determined.
[0112] The present disclosure does not limit the target object. In one embodiment, the target object is an object in at least one object model that is higher than the water surface of the water body model. For example, in a game scene, there is a lake (water body model), there is ground (object model) around the lake, trees (object model) are located on the ground around the lake, there are stones (object models) in the lake, and the stones are completely immersed in water. In this scene, the target objects are the ground and trees that are higher than the lake surface.
[0113] The present disclosure does not limit the method of determining the target object. In one embodiment, the above-mentioned determination of the target object in the target scene includes: creating a detection box, the bottom height of the detection box is the water surface height of the water body model; in the area of the target scene, collision detection is performed based on the detection box to determine the target object in contact with the detection box. Collision detection is a core technology in computer graphics and physics engines, which is used to determine whether two or more objects collide or contact. The axis-aligned bounding box (AABB) is a simple and effective collision detection method. An axis-aligned bounding box is usually defined by a center point and a set of half-sizes (i.e., half of the length in each axis direction). Since the axis-aligned bounding box is axis-aligned, the edges are always parallel to the coordinate axes. Therefore, collision detection based on the axis-aligned bounding box simplifies the calculation process of collision detection and improves the efficiency of collision detection.
[0114] In the embodiment of the present disclosure, the axis-aligned bounding box is used as the detection box body, and the length and width of the bottom of the detection box body are not limited. When the area of the bottom of the detection box body is defined to be smaller than the plane area of the target scene, it is only necessary to move the detection box body to traverse the entire target scene area. In the process of moving the detection box body to traverse the target scene, the Physics.OverlapBox method is called to perform collision detection. In the Unity engine, each object in the scene is represented by an axis-aligned bounding box to represent its boundary. The Physics.OverlapBox method determines whether each possible collision body overlaps with the detection box body by detecting the respective ranges of the two axis-aligned bounding boxes. The Physics.OverlapBox method needs to define the axis-aligned bounding box as the detection box body, and the center point and size of the detection box body are used as parameters. The center point of the detection box body is the coordinate of the center position of the detection box body, and the size of the detection box body is half of the length of the detection box body in the X-axis, Y-axis, and Z-axis directions, respectively. By comparing whether the axis-aligned bounding box where the object is located overlaps with the detection box body in the range of the X, Y, and Z axes, it is determined whether the two are in contact. Specifically, assuming that AABB1 represents a detection box with a center point (x1, y1, z1) and a half size (hx1, hy1, hz1), and AABB2 represents an object in the scene with a center point (x2, y2, z2) and a half size (hx2, hy2, hz2), for each axis, the overlap judgment condition is:
[0115] For the X axis: |x1-x2|≤hx1+hx2;
[0116] For the Y axis: |y1-y2|≤hy1+hy2;
[0117] For the Z axis: |z1-z2|≤hz1+hz2;
[0118] If the above conditions are met on all three axes, the two axis-aligned bounding boxes overlap. Finally, the Physics.OverlapBox method returns a Collider array containing all colliders that overlap with the detection box. Each Collider object represents a collider, i.e., a target object, and the position information of the relevant target object can be accessed through the Collider object.
[0119] By setting the bottom height of the detection box to the water surface height of the water model and performing collision detection based on the detection box, the detection range can be flexibly controlled, and the target object above the water surface can be accurately located and quickly determined, which reduces unnecessary calculations and improves detection efficiency.
[0120] In step S205, a binary mask map is generated based on the position of the target object in the target scene.
[0121] The present disclosure does not limit the binary mask map. In one embodiment, the binary mask map includes a first color region and a second color region. The second color region is a region corresponding to the target object. Correspondingly, the first color region is a water surface region. Figure 3 As shown, Figure 3 A schematic diagram of a binary mask map according to an embodiment of the present disclosure is shown. Figure 3 It can be seen that the binary mask map includes a first color area (black area) and a second color area (white area).
[0122] The present disclosure does not limit the method of generating a binary mask map. In one embodiment, the above-mentioned generation of a binary mask map based on the position of the target object in the target scene may include: creating an initial mask map according to the size of the target scene; determining the pixel points corresponding to the coordinates in the initial mask map based on the coordinates of the target object in the target scene; setting the corresponding pixel points to a second color value to obtain a binary mask map. Specifically, all pixels of the initial mask map are first color values. The present disclosure does not limit the first color value, which can be 0, indicating that the pixel points are black. The pixel points corresponding to the target object in the initial mask map are set to a second color value. The present disclosure does not limit the second color value, which can be 1, indicating that the pixel points are white. The size of the initial mask map is consistent with the size of the plane corresponding to the target scene, so that the initial mask map can just cover the plane corresponding to the target scene.
[0123] By determining the coordinates of the target object in the target scene, the target object can be precisely located to ensure that the mask map can accurately reflect the position of the target object; based on the coordinates of the target object, the corresponding pixels of the initial mask map are set to the second color value to clearly mark the position of the target object.
[0124] In step S207, based on the second color area, a water body rendering area is determined in the first color area; the color value of the pixel point in the first color area is the first color value, and the color value of the pixel point in the second color area is the second color value.
[0125] The present disclosure does not limit the method for determining the water body rendering area. In one embodiment, Figure 4 A flow chart of determining a water body rendering area according to an embodiment of the present disclosure is shown. Figure 4 The above-mentioned determining the water body rendering area in the first color area based on the second color area may include the following steps:
[0126] In step S401, for each pixel in the binary mask map, a target area is determined in the binary mask map; the target area is a positive area centered on the pixel and having a preset width as a side length. The preset width directly affects the display range and visual effect of the rendering effect. The present disclosure does not limit the preset width. A most suitable preset width can be determined by observing the water effect in real situations, such as the foam effect.
[0127] In step S403, when there are reference pixels in the target area, the shortest distance between the pixels is determined; the reference pixels are pixels in the second color area.
[0128] The present disclosure does not limit the method for determining the closest distance. In one embodiment, the closest distance from a given pixel to a target object in a target area can be determined by calculating a function of a distance field (Signed Distance Field, SDF). A distance field is a numerical representation used to describe the distance from each point to the nearest boundary (or a specific area). Calculating the distance field includes creating a two-dimensional array of the same size as the target area to store the distance from each pixel to the nearest boundary; marking all reference pixels in the target area, i.e., pixels in the second color area; traversing each pixel in the target area and calculating its distance to the nearest reference pixel. This distance is usually calculated using the Euclidean distance, i.e. Where (x1, y1) are the coordinates of the given pixel, and (x2, y2) are the coordinates of the reference pixel. By traversing each pixel in the target area, it is determined whether there is a reference pixel, i.e., a pixel of the second color area, in the target area. If there is a reference pixel, the closest distance from the given pixel to the reference pixel, i.e., the Euclidean distance, is determined. Specifically, the square value of the closest distance from each pixel in the binary mask map to the reference pixel is initialized to a preset value. The present disclosure does not limit the preset value, and it can be the square of half the preset width; for each pixel, the given pixel is taken as the center pixel, and the step size of the traversal is determined to be the pixel size; the target area around the center pixel is traversed, and each time a pixel in the target area is reached, it is determined whether the current pixel is a reference pixel. If so, the square of the distance from the current pixel to the center pixel is calculated, and the calculated value is compared with the square value of the closest distance, and the smaller value is taken as the square value of the closest distance; after the traversal is completed, the square root operation is performed on the square value of the closest distance to obtain the closest distance.
[0129] In step S405, the nearest distance is normalized based on the preset width to obtain the grayscale value corresponding to the pixel. In a specific embodiment, the ratio of the nearest distance to half of the preset width is calculated, and then the obtained ratio is subtracted from 1, and then the obtained difference is normalized using the saturate() function. The saturate() function limits the input value to the range of 0 to 1. If the input value is less than 0, it returns 0, if the input value is greater than 1, it returns 1; if the input value is between 0 and 1, it returns the input value itself. The grayscale value corresponding to each pixel is obtained by normalizing using the saturate() function.
[0130] In step S407, an area formed by pixels whose grayscale values meet a preset condition is determined as a water body rendering area; the preset condition is that the grayscale value is greater than the first color value and less than the second color value. Specifically, an area formed by pixels whose grayscale values are greater than 0 and less than 1 is determined as a water body rendering area.
[0131] By calculating the nearest distance from each pixel to the reference pixel in the target area and normalizing the nearest distance, the water rendering area at the edge of the water surface can be flexibly and efficiently identified in the binary mask map, avoiding dependence on the scene depth map, simplifying the implementation process of the water effect, reducing unnecessary computing overhead, and improving rendering efficiency.
[0132] In step S209, preset effect rendering is performed on the effect rendering area in the water body model to obtain a water body model with preset effects; the effect rendering area corresponds to the water body rendering area.
[0133] In an optional embodiment, before performing preset effect rendering on the effect rendering area in the water body model to obtain the water body model with the preset effect, the method may further include:
[0134] Based on the grayscale value corresponding to each pixel in the binary mask map, a feathered mask map is generated; the feathered mask map is blurred to generate a blurred mask map; the blurred mask map is applied to the water model. Feathering refers to the process of softening the edge in image processing. Applying the grayscale value to the corresponding pixel point can generate a feathering effect, making the edge transition more natural.
[0135] The present disclosure does not limit the blurring technique, and commonly used blurring algorithms such as Gaussian blur, box blur and mean blur can be used. Preferably, Gaussian blur is used to provide a smooth blurring effect. Gaussian blur is based on a Gaussian function, which is a bell-shaped curve used to define a weight distribution. The effect of Gaussian blur is to smooth the image by weighted averaging each pixel in the image with its surrounding pixels according to the weight. The formula of the Gaussian function is: Among them, (,y) is the coordinate relative to the center of the kernel, and σ is the standard deviation. Gaussian blur requires the definition of kernel size and standard deviation. Kernel size is usually selected as an odd number such as 3, 5, 7, etc. to ensure that the kernel has a center point. Too large a kernel size may cause the blurring effect to be too strong. The standard deviation is used to control the intensity of the blur. The commonly used value is between 0.5-2.0. Too large a kernel size may cause the edge transition to be too blurred. The kernel size and standard deviation need to be adjusted according to the actual effect. Too large a kernel size and standard deviation will cause loss of image details and shape distortion, while too small a kernel size and standard deviation may not completely eliminate the aliasing effect; Generate a Gaussian kernel based on the given kernel size and standard deviation. Specifically, determine the size of the kernel, use the Gaussian formula to calculate the value of each element in the kernel, and ensure that the kernel The sum of all elements of is 1; use the generated Gaussian kernel to perform a convolution operation on the image to achieve a blurring effect. Specifically, align the center of the kernel with each pixel of the image, multiply each value in the kernel with the corresponding image pixel and sum them to obtain the blurred pixel value. When processing image boundaries, the image may need to be padded (such as zero padding or boundary replication). Zero padding is to fill zero values around the image boundary to ensure that there are enough pixels to calculate when the convolution kernel is applied to the edge of the image. Boundary replication is to copy and fill the pixel values of the image boundary outside the boundary, so that the pixel values on the boundary will be reused in the convolution calculation, which can maintain the consistency of the boundary pixel values and make the edge blurring effect more natural.
[0136] Texture mapping is a technique for applying a two-dimensional image (texture) to the surface of a three-dimensional model. In Unity, the Texture2D class is used to represent and manipulate two-dimensional textures. By loading a blur mask map, you can use texture coordinates (UV coordinates) in the fragment shader to sample the blur mask map, and use these sampled values to affect the rendering effect of the water body. UV coordinates are two-dimensional texture coordinates used to position textures on the surface of a three-dimensional model, and each vertex has a UV coordinate. The fragment shader is a program running on the graphics processing unit (GPU) that is responsible for calculating the color of each pixel. In the fragment shader, you can use UV coordinates to sample pixel values from the texture and adjust the final rendering effect based on these values.
[0137] The present disclosure does not limit the manner of applying the blur mask map to the water model. In one embodiment, the blur mask map can be loaded through the Texture2D class in Unity, and then the texture coordinates, i.e., UV coordinates, are used in the fragment shader to sample the blur mask map. Finally, the sampled blur mask values are used to adjust the relevant properties of the water body, and the relevant properties may be transparency, color, normal, reflection, refraction, etc.
[0138] By generating a feathered mask map and blurring it, a smooth transition effect can be produced at the hard boundary of the binary mask map; applying the blurred mask map to the water model makes the combination between the water model and the object model more natural and the visual effect better.
[0139] The present disclosure does not limit the preset rendering effect. In one embodiment, the preset rendering effect is a foam display effect, such as Figure 5 As shown, Figure 5 A schematic diagram of a foam effect according to an embodiment of the present disclosure is shown. Specifically, a foam texture map can be loaded through the Texture2D class, and then the foam texture map can be sampled using texture coordinates, i.e., UV coordinates, in the fragment shader to achieve the foam effect in the effect rendering area. The foam texture is displayed at the edge of the water body or in the collision area between the water surface and the object, which increases the details and makes the water body more realistic and vivid.
[0140] In one embodiment, the preset rendering effect is a depth display effect, such as Figure 6 As shown, Figure 6 A schematic diagram of the depth effect according to an embodiment of the present disclosure is shown. Specifically, the blurred mask map can be loaded through the Texture2D class, and the fragment shader of the water body model can be modified to collect the grayscale value of the blurred mask map in the effect rendering area to adjust the transparency of the water body. The transparency of the water body is adjusted according to the depth value to simulate the change of the depth of the water body, so that the visual effect of the water body is more three-dimensional and layered.
[0141] By using a fuzzy mask texture map to control the rendering of water effects in the effect rendering area of the water model, complex visual effects can be achieved without adding a lot of calculations, so that the foam and depth effects can be better integrated with the surrounding environment, the visual effects are more realistic, and the user's immersion in the scene is enhanced.
[0142] In an alternative embodiment, Figure 7 A flowchart of rendering a preset swirl effect according to an embodiment of the present disclosure is shown. Figure 7 , the above method may further include:
[0143] In step S701 , a vortex preform model is created.
[0144] In a specific embodiment, the vortex preform model includes a vortex edge area and a vortex recess area. Specifically, the vortex preform model is a three-dimensional model in the shape of a funnel, such as Figure 8 , Figure 8 A schematic diagram showing a vortex preform model according to an embodiment of the present disclosure.
[0145] In step S703, the vortex prefabricated model is integrated into the water model; the vortex edge area is located on the water surface of the water model, and the vortex concave area is located below the water surface of the water model.
[0146] The present disclosure does not limit the way in which the vortex preform model is integrated into the water model. In one embodiment, the created vortex preform model is dragged into the Unity scene; in the Unity scene view or the hierarchy view, the water model is selected as the parent object, and the vortex preform model is dragged under the parent object as a child object. Using the vortex preform as a child object of the water model can make the position, rotation and scale of the vortex preform model consistent with the parent object, i.e., the water model. No matter how the water model is moved or rotated, the vortex preform will move relative to the water model, maintain an appropriate positional relationship, ensure that the vortex effect always corresponds to the position of the water surface, and increase the realism and consistency of the scene.
[0147] In step S705, a preset vortex effect is rendered in the vortex concave area.
[0148] The vertex shader is responsible for processing each vertex, such as position transformation, normal calculation, color calculation, etc. In this process, any vertex-related attributes can be calculated and passed to the fragment shader. In an optional embodiment, before rendering the preset vortex effect in the vortex concave area, a feathering effect can be applied to the vortex edge area. Specifically, the distance from each vertex corresponding to the vortex edge area to the center position of the vortex prefabricated model is calculated in the vertex shader, and the value is passed to the fragment shader; in the fragment shader, the feathering effect is applied according to the distance value, so that the farther from the center position of the vortex prefabricated model, the higher the transparency, forming a smooth transition. The feathering effect can make the transition between the vortex effect and the surrounding water body smoother, avoid harsh edges, and make the visual effect more natural.
[0149] By integrating the vortex prefab model into the water body model and rendering a preset vortex effect on the vortex concave area of the vortex prefab model, the vortex can be made to show a vivid and realistic three-dimensional sense in the game scene.
[0150] In an optional embodiment, the above-mentioned rendering of a preset vortex effect in the vortex concave area includes:
[0151] A transparent circle is rendered at the boundary line between the vortex edge area and the vortex concave area, and the transparent circle is used to limit the rendering range of the vortex concave area; in the template buffer of the target game engine, the template value of the transparent circle area is set to a preset template value; the template buffer is used to store the template value of the pixel, so that the rendering process is performed in the area formed by the pixels matching the corresponding template value; the template value of the preset vortex effect is configured as the preset template value; and the preset vortex effect is rendered.
[0152] Stencil Test is a technique used to control pixel rendering. It determines whether certain pixels can be drawn by the values stored in the stencil buffer. The stencil buffer is a special buffer where each pixel corresponds to a stencil value. The behavior of the stencil test can be controlled by setting stencil functions and operations.
[0153] Specifically, make preparations: ensure that the rendering state is correctly configured to support the rendering of transparent circles and swirl effects, including enabling depth testing, stencil testing, blending, etc.; load and set the shader program for rendering transparent circles and swirl effects; use glClearStencil to clear the stencil buffer and set an initial value;
[0154] Rendering a transparent circle: determining the position and size of the transparent circle. Specifically, the transparent circle is located at the boundary between the vortex edge area and the vortex concave area. Before rendering the transparent circle, use glStencilFunc and glStencilOp to set the conditions and operations of the template test so as to update the value of the template buffer when rendering the transparent circle. In one embodiment, the template function can be configured as GL_ALWAYS to ensure that the template test passes unconditionally for any value in the current template buffer, that is, no conditional judgment is performed on the value in the template buffer. Then, use GL_REPLACE as the template operation to replace the value in the transparent circular area in the template buffer with a preset template value. The present disclosure does not limit the preset template value, and it only needs to be able to distinguish other elements in the scene. For example, in the current scene, the template value of the water body is 0, and the template value of the ship is 1. The template value of the circular area can be set to 2.
[0155] Configure the stencil value of the preset swirl effect: Before rendering the preset swirl effect, you need to set the stencil function to check whether the value in the stencil buffer is equal to the preset stencil value. You can use glStencilFunc to set the stencil function, set the comparison function to GL_EQUAL, and set the reference value to the preset stencil value, for example, glStencilFunc(GL_EQUAL,2,0xFF). GL_EQUAL is the stencil test function, which means that the test passes when the value in the stencil buffer is equal to the reference value. 2 is the reference value. glStencilFunc(GL_EQUAL,2,0xFF) ensures that only pixels with a value of 2 in the stencil buffer pass the test.
[0156] Rendering preset swirl effect: Use the shader and rendering commands corresponding to the preset swirl effect to render the preset swirl effect. Since the template test is set to pass only when the value in the template buffer is equal to the preset template value, the swirl effect will only be rendered within the transparent circular area, that is, the swirl concave area.
[0157] By rendering a transparent circle and setting a stencil buffer, you can use the stencil test to control the rendering operation during the rendering process. You can only render in areas where the stencil value matches, accurately control the rendering range of the preset vortex effect, and make the vortex show vivid and realistic three-dimensional and occlusion effects in the game scene.
[0158] In step S707, a water flow direction diagram matching the vortex depression area is created.
[0159] In an optional embodiment, after rendering a preset vortex effect in the vortex depression area, a water flow direction map matching the vortex depression area can be created, and the water flow direction map is used to record the flow direction and flow speed of the water flow outside the vortex depression area.
[0160] The present disclosure does not limit the water flow map. In one embodiment, the water flow map is a Flowmap map. A Flowmap map is a texture map used to simulate the flow effect of a water body. By encoding the flow direction and flow speed information in the map, a dynamic water flow effect can be achieved during the rendering process. Each pixel of a Flowmap map usually contains two main information: flow direction and flow speed. The flow direction is represented by a color value (usually red and green channels), and the flow speed can be represented by the brightness of the color. The brightness value is usually stored in a color channel of the map (such as the blue channel). By reading the value of this channel in the shader, the flow speed information of each pixel can be obtained.
[0161] The present disclosure does not limit the creation of a water flow diagram. In one embodiment, it is first necessary to define a water surface coordinate system centered on the water surface of the water body model. The system may take a certain point on the water surface as the origin, such as the center of the water surface or a fixed point, and have an X-axis and a Y-axis parallel to the water surface, and a Z-axis perpendicular to the water surface. The world coordinates of the center position of the vortex preform model are obtained, and the world coordinates are converted into coordinates of the water surface coordinate system. The transformation matrix from the world coordinate system to the water surface coordinate system may be calculated by using information of the world coordinate system and the water surface coordinate system. The transformation matrix includes rotation and translation components so as to transform the center position of the vortex preform model from the global space to the local space of the water surface. The center position of the vortex preform model is converted into the local space of the water surface. The world coordinate a is multiplied by the transformation matrix to obtain the local coordinate b of the center position of the vortex preform model in the water surface coordinate system; with the local coordinate b as the center, the flow information of the water flow in the surrounding area of the local coordinate b is determined, including the flow direction and the flow speed, and the flow information of the water flow in the surrounding area of the vortex center position can be obtained through the fluid simulation software; based on the local coordinate b, the calculated flow information is mapped to each pixel of the Flowmap map, and the flow direction in the flow information can be encoded into the red channel and the green channel of the Flowmap map, which is achieved by mapping the U direction and the V direction to the values of the red channel and the green channel respectively. The flow speed in the flow information can be represented by the brightness of the color.
[0162] In step S709, the water model is rendered based on the water flow direction diagram to obtain a water model with a vortex display effect.
[0163] Specifically, write or modify the shader program for water body rendering so that the shader program can read the Flowmap map and offset the sampling coordinates of the water body texture according to its information; read the Flowmap map, obtain the flow direction and flow speed, calculate the offset of the texture coordinates according to the flow direction vector and the flow speed, and apply the offset to the UV coordinates of the water body texture to produce a distortion effect. By rendering the water model based on the water flow map, the water ripple effect outside the vortex depression area can be adapted and integrated with the vortex depression area, so that the rendered water model can present a realistic vortex effect, presenting the effect of water flow outside the vortex depression area flowing around the vortex, significantly enhancing the user's immersion in the scene.
[0164] In an alternative embodiment, Fig. 9 A flowchart of another method for rendering a preset swirl effect according to an embodiment of the present disclosure is shown. Fig. 9 , the above method may further include:
[0165] In step S901, a preset vortex map is applied to a preset area of the water model;
[0166] Specifically, the preset vortex map fits the preset area of the water model, that is, the vortex effect is displayed in the preset area; the preset vortex map is used to simulate the vortex effect of the water surface. The present disclosure does not limit the preset vortex map, and an image containing vortex texture and color information is sufficient. The present disclosure does not limit the preset area of the water model. A mask texture can be created, in which white represents the preset area and black represents the non-regional part, or a UV coordinate range can be directly specified as the preset area. Specifically, in the fragment shader, it is determined whether the current fragment is within the area according to the definition of the preset area, and whether to apply the preset vortex map is selected based on the judgment result. If the current fragment is within the preset area, the color and texture of the preset vortex map are used. If it is not within the preset area, other textures of the water model (such as the texture of a calm water surface) or some transition effect can be used.
[0167] In step S903, the sinking depth of each vertex is determined according to the distance from each vertex in the preset area to the center of the preset vortex map.
[0168] The present disclosure does not limit the method for determining the sinking depth. In one embodiment, a variable of a vertex shader is defined to receive the position of the center of a preset vortex map. The input of the vertex shader includes the position information of the vertex. The distance from the current vertex to the center of the preset vortex map is calculated, which usually involves vector subtraction and vector length calculation. Vector subtraction refers to subtracting the corresponding components of two vectors. Assuming that the vertex position is Position and the center position of the preset vortex map is Center, the vector subtraction can be expressed as distanceVector=Position-Center. The distanceVector obtained is a vector pointing from the center of the vortex map to the vertex position. The length of the vector can be calculated using the length() function of GLSL. The length of the vector represents the distance from the origin to the end point of the vector. The length() function can be used to calculate the length of the distanceVector, that is, the distance from the vertex to the center of the vortex map. The sinking depth can be calculated based on the distance by mapping the distance to a preset depth range, for example, using a simple linear mapping. The Z coordinates of the vertices of the preset area are adjusted according to the calculated sinking depth. Based on the Z coordinates of the vertices of the preset area, the depth values of the vertices of the preset area are determined, and the depth values are written to the depth buffer (Depth In the vertex shader, by calculating the distance from each vertex in the preset area to the center of the preset vortex map and calculating the sinking depth based on the distance, the vertex closer to the center of the preset vortex map sinks deeper, thereby generating a funnel-shaped vortex shape; by writing the depth values of the vertices in the preset area into the depth buffer, a vivid and realistic stereoscopic and occlusion effect can be displayed in the game scene, significantly enhancing the user's immersion in the scene.
[0169] In step S905, the sinking depth is applied to the corresponding vertices in the preset area to obtain a water model with a vortex display effect.
[0170] A model-view-projection matrix (Model-View-ProjectionMatrix) is usually used in the vertex shader to transform the local coordinates of the vertex into the clip space coordinates, including model transformation (ModelTransformation): transforming the vertex from the local coordinate system (such as model space) to the world coordinate system, view transformation (View Transformation): transforming the vertex in the world coordinate system to the camera view space, and projection transformation (Projection Transformation): projecting the vertex in the view space to the clip space. Clip space (ClipSpace) is a coordinate system in the graphics rendering pipeline and is the last stage of vertex position after vertex shader processing. gl_Position is a predefined variable in the vertex shader that is used to store the final position of the vertex after the model-view projection transformation. The vertex position in the clip space is a four-dimensional vector (x, y, z, w), where (x, y, z) represents the spatial coordinates of the vertex, and w is usually used for perspective division. In the vertex shader, the final position of the vertex in the clip space can be modified by calculating the new vertex position and assigning it to gl_Position.
[0171] The present disclosure does not limit the manner in which the sinking depth is applied to vertices. In one embodiment, the calculated sinking depth is applied to the vertex by modifying the position of the vertex in the vertex shader. Specifically, it is achieved by modifying the gl_Position variable, and the modified vertex position is converted to the clipping space using the model view projection matrix and assigned to gl_Position. gl_Position is used in the vertex shader to store the final position of the vertex after the model view projection transformation.
[0172] The preset vortex map ensures the vortex effect on the water surface, while the offset of the vertex position ensures that the vertices are transformed correctly, ultimately rendering the expected visual effect.
[0173] It can be seen from the technical solutions provided in the above embodiments of this specification that in this specification, by determining the position of the target object above the water surface in the scene, a binary mask map is generated, and based on the second color area of the binary mask map, the water body rendering area is determined in the first color area, thereby avoiding dependence on the scene depth map, simplifying the implementation process of the water body effect, reducing unnecessary computing overhead, and improving rendering efficiency; performing preset effect rendering in the effect rendering area corresponding to the water body rendering area, the visual effect is more realistic, and the user's immersion in the scene is enhanced; by using template testing to control the rendering operation, rendering is only performed in the area where the template value matches, and the rendering range of the preset vortex effect is accurately controlled, so that the vortex can show a vivid and realistic three-dimensional sense and occlusion effect in the game scene, and the water body model is rendered based on the water body flow direction map, so that the rendered water body model can present a realistic vortex effect, showing that the water flow outside the vortex concave area flows around the vortex; the preset vortex map ensures the vortex effect on the water body surface, and at the same time, the offset of the vertex position ensures that the vertex is correctly transformed, and finally renders a three-dimensional visual effect.
[0174] Fig.10 A block diagram of a water effect rendering device according to an embodiment of the present disclosure is shown. Fig.10 , the device comprises:
[0175] A target scene acquisition module 1001 is configured to acquire a target scene set in a target game engine, wherein the target scene includes a water body model and at least one object model;
[0176] A target object determination module 1002 is configured to determine a target object in the target scene, wherein the target object is an object in the at least one object model that is higher than a water surface of the water body model;
[0177] A binary mask map generating module 1003 is configured to generate a binary mask map based on the position of the target object in the target scene; the binary mask map includes a first color area and a second color area, and the second color area is an area corresponding to the target object;
[0178] A water body rendering region determining module 1004 is configured to determine a water body rendering region in the first color region based on the second color region;
[0179] The preset effect rendering module 1005 is configured to perform preset effect rendering on the effect rendering area in the water body model to obtain a water body model with the preset effect, and the effect rendering area corresponds to the water body rendering area.
[0180] In an optional embodiment, the water body rendering area determination module 1004 includes:
[0181] A target region determining unit is configured to determine a target region in the binary mask map for each pixel in the binary mask map, wherein the target region is a square region with the pixel as the center and a preset width as the side length;
[0182] A closest distance determining unit is configured to determine the closest distance from the pixel to the reference pixel when there is a reference pixel in the target area, the reference pixel being a pixel in the second color area;
[0183] A closest distance processing unit is configured to perform normalization processing on the closest distance based on the preset width to obtain a grayscale value corresponding to the pixel point;
[0184] The rendering area determination unit is configured to determine an area formed by pixels whose grayscale values meet a preset condition as the water body rendering area, wherein the preset condition is that the grayscale value is greater than the first color value and less than the second color value.
[0185] In an optional embodiment, before performing preset effect rendering on the effect rendering area in the water body model, the device further includes:
[0186] A feathered mask map generation module is configured to generate a feathered mask map based on the grayscale value corresponding to each pixel in the binary mask map;
[0187] A fuzzy mask map generating module is configured to perform fuzzy processing on the feathered mask map to generate a fuzzy mask map;
[0188] The blur mask map application module is configured to apply the blur mask map to the water body model.
[0189] In an optional embodiment, the device further comprises:
[0190] A vortex preform creation module is configured to create a vortex preform model, wherein the vortex preform model includes a vortex edge region and a vortex concave region;
[0191] A vortex preform integration module is configured to integrate the vortex preform model into the water model; the vortex edge area is located on the water surface of the water model, and the vortex concave area is located below the water surface of the water model;
[0192] The preset vortex effect rendering module is configured to render a preset vortex effect in the vortex concave area.
[0193] In an optional embodiment, the preset swirl effect rendering module includes:
[0194] A transparent graphics rendering unit is configured to render a transparent circle at a boundary line between the vortex edge area and the vortex concave area, wherein the transparent circle is used to limit a rendering range of the vortex concave area;
[0195] A template value setting unit is configured to set the template value of the transparent circular area to a preset template value in a template buffer of the target game engine; the template buffer is used to store the template value of the pixel so that the rendering process is performed in the area formed by the pixels matching the corresponding template value;
[0196] a preset swirl effect configuration unit, configured to configure the template value of the preset swirl effect to the preset template value;
[0197] The preset vortex effect rendering unit is configured to render the preset vortex effect.
[0198] In an optional embodiment, after rendering the preset vortex effect in the vortex concave area, the device further includes:
[0199] A water flow direction map creation module is configured to create a water flow direction map that matches the vortex concave area; the water flow direction map is used to record the flow direction and flow speed of the water flow outside the vortex concave area;
[0200] The water flow direction map rendering module is configured to render the water model based on the water flow direction map to obtain a water model with a vortex display effect.
[0201] In an optional embodiment, the binary mask map generation module 1003 includes:
[0202] An initial mask map creating unit is configured to create an initial mask map according to the size of the target scene; all pixels of the initial mask map are the first color value;
[0203] A pixel point determination unit is configured to determine, based on the coordinates of the target object in the target scene, the pixel points corresponding to the coordinates in the initial mask map;
[0204] The binary mask map generating unit is configured to set the corresponding pixel point to the second color value to obtain the binary mask map.
[0205] In an optional embodiment, the target object determination module 1002 includes:
[0206] A detection box creating unit is configured to create a detection box, wherein the bottom height of the detection box is the water surface height of the water body model;
[0207] The collision detection unit is configured to perform collision detection based on the detection box in the area of the target scene to determine the target object in contact with the detection box.
[0208] In an optional embodiment, the device further comprises:
[0209] A preset vortex map application module is configured to apply a preset vortex map to a preset area of the water body model;
[0210] A sinking depth determination module is configured to determine the sinking depth of each vertex according to the distance from each vertex of the preset area to the center of the preset vortex map;
[0211] The sinking depth application module is configured to apply the sinking depth to corresponding vertices in the preset area to obtain a water model with a vortex display effect.
[0212] Fig.11 A block diagram of an electronic device for rendering water effects according to an embodiment of the present disclosure is shown. The electronic device may be a terminal, and its internal structure diagram may be as shown in FIG. Fig.11 As shown. The electronic device includes a processor, a memory, a network interface, a display screen and an input device connected through a system bus. Among them, the processor of the electronic device is used to provide computing and control capabilities. The memory of the electronic device includes a non-volatile storage medium and an internal memory. The non-volatile storage medium stores an operating system and a computer program. The internal memory provides an environment for the operation of the operating system and the computer program in the non-volatile storage medium. The network interface of the electronic device is used to communicate with an external terminal through a network connection. When the computer program is executed by the processor, a method for rendering a water body effect is implemented. The display screen of the electronic device can be a liquid crystal display screen or an electronic ink display screen, and the input device of the electronic device can be a touch layer covering the display screen, or a button, trackball or touchpad set on the housing of the electronic device, or an external keyboard, touchpad or mouse, etc.
[0213] Fig.12 A block diagram of another electronic device for rendering water effects according to an embodiment of the present disclosure is shown. The electronic device may be a server, and its internal structure diagram may be as shown in FIG. Fig.12As shown. The electronic device includes a processor, a memory and a network interface connected through a system bus. Among them, the processor of the electronic device is used to provide computing and control capabilities. The memory of the electronic device includes a non-volatile storage medium and an internal memory. The non-volatile storage medium stores an operating system and a computer program. The internal memory provides an environment for the operation of the operating system and the computer program in the non-volatile storage medium. The network interface of the electronic device is used to communicate with an external terminal through a network connection. When the computer program is executed by the processor, a method for rendering a water effect is implemented.
[0214] Those skilled in the art will understand that Fig.11 or Fig.12 The structure shown in the figure is merely a block diagram of a partial structure related to the scheme of the present disclosure, and does not constitute a limitation on the electronic device to which the scheme of the present disclosure is applied. The specific electronic device may include more or fewer components than those shown in the figure, or combine certain components, or have a different arrangement of components.
[0215] In an exemplary embodiment, an electronic device is also provided, including: a processor; and a memory for storing instructions executable by the processor; wherein the processor is configured to execute the instructions to implement the water effect rendering method as in the embodiment of the present disclosure.
[0216] In an exemplary embodiment, a computer-readable storage medium is also provided. When instructions in the storage medium are executed by a processor of an electronic device, the electronic device can execute the water effect rendering method in the embodiment of the present disclosure.
[0217] In an exemplary embodiment, a computer program product including instructions is also provided. When the computer program product is run on a computer, the computer is enabled to execute the water effect rendering method in the embodiment of the present disclosure.
[0218] Those skilled in the art can understand that all or part of the processes in the above-mentioned embodiment methods can be completed by instructing the relevant hardware through a computer program, and the computer program can be stored in a non-volatile computer-readable storage medium. When the computer program is executed, it can include the processes of the embodiments of the above-mentioned methods. Among them, any reference to memory, storage, database or other media used in the embodiments provided in this application can include non-volatile and / or volatile memory. Non-volatile memory may include read-only memory (ROM), programmable ROM (PROM), electrically programmable ROM (EPROM), electrically erasable programmable ROM (EEPROM) or flash memory. Volatile memory may include random access memory (RAM) or external cache memory. As an illustration and not limitation, RAM is available in many forms, such as static RAM (SRAM), dynamic RAM (DRAM), synchronous DRAM (SDRAM), double data rate SDRAM (DDRSDRAM), enhanced SDRAM (ESDRAM), synchronous link (Synchlink) DRAM (SLDRAM), memory bus (Rambus) direct RAM (RDRAM), direct memory bus dynamic RAM (DRDRAM), and memory bus dynamic RAM (RDRAM).
[0219] The embodiments of the present disclosure have been described above, and the above description is exemplary, not exhaustive, and is not limited to the disclosed embodiments. Many modifications and changes will be apparent to those of ordinary skill in the art without departing from the scope and spirit of the described embodiments. The selection of terms used herein is intended to best explain the principles of the embodiments, practical applications, or technical improvements in the market, or to enable other persons of ordinary skill in the art to understand the embodiments disclosed herein.
Claims
1. A method for rendering water effects, characterized in that: The method comprises: Acquire a target scene set in a target game engine, wherein the target scene includes a water body model and at least one object model; Determine a target object in the target scene, wherein the target object is an object in the at least one object model that is higher than a water surface of the water body model; Generate a binary mask map based on the position of the target object in the target scene; the binary mask map includes a first color area and a second color area, and the second color area is the area corresponding to the target object; Based on the second color area, determining a water body rendering area in the first color area; The effect rendering area in the water body model is rendered with a preset effect to obtain a water body model with the preset effect, and the effect rendering area corresponds to the water body rendering area.
2. The method for rendering water effects according to claim 1, characterized in that: The color value of the pixel point in the first color area is a first color value, the color value of the pixel point in the second color area is a second color value, and determining the water body rendering area in the first color area based on the second color area includes: For each pixel point in the binary mask map, determining a target area in the binary mask map, wherein the target area is a square area with the pixel point as the center and a preset width as the side length; In the case where there is a reference pixel in the target area, determining the shortest distance from the pixel to the reference pixel, where the reference pixel is a pixel in the second color area; Based on the preset width, the closest distance is normalized to obtain a grayscale value corresponding to the pixel point; An area formed by pixels whose grayscale values meet a preset condition is determined as the water body rendering area, and the preset condition is that the grayscale value is greater than the first color value and less than the second color value.
3. The method for rendering water effects according to claim 2, characterized in that: Before performing preset effect rendering on the effect rendering area in the water body model, the method further includes: Generate a feathered mask map based on the grayscale value corresponding to each pixel in the binary mask map; Performing blur processing on the feathered mask map to generate a blurred mask map; Applying the blur mask map to the water model.
4. The method for rendering water effects according to claim 1, characterized in that: The method further comprises: Creating a vortex preform model, wherein the vortex preform model includes a vortex edge region and a vortex concave region; Integrate the vortex preform model into the water model; the vortex edge area is located on the water surface of the water model, and the vortex concave area is located below the water surface of the water model; A preset vortex effect is rendered in the vortex concave area.
5. The method for rendering water effects according to claim 4, characterized in that: The rendering of a preset vortex effect in the vortex concave area includes: Rendering a transparent circle at the boundary between the vortex edge area and the vortex concave area, wherein the transparent circle is used to limit the rendering range of the vortex concave area; In the template buffer of the target game engine, the template value of the transparent circular area is set to a preset template value; the template buffer is used to store the template value of the pixel, so that the rendering process is performed in the area formed by the pixels matching the corresponding template value; configuring the template value of the preset swirl effect to be the preset template value; Render the preset swirl effect.
6. A method for rendering water effects according to claim 4 or 5, characterized in that: After rendering the preset vortex effect in the vortex concave area, the method further includes: Creating a water flow direction diagram that matches the vortex depression area; the water flow direction diagram is used to record the flow direction and flow speed of the water flow outside the vortex depression area; The water model is rendered based on the water flow direction diagram to obtain a water model with a vortex display effect.
7. The method for rendering water effects according to claim 2, characterized in that: The step of generating a binary mask map based on the position of the target object in the target scene comprises: Creating an initial mask map according to the size of the target scene; all pixels of the initial mask map have the first color value; Based on the coordinates of the target object in the target scene, determine the pixel points corresponding to the coordinates in the initial mask map; The corresponding pixel point is set to the second color value to obtain the binary mask map.
8. A method for rendering water effects according to claim 1 or 7, characterized in that: The determining of the target object in the target scene includes: Creating a detection box, wherein the bottom height of the detection box is the water surface height of the water body model; In the area of the target scene, collision detection is performed based on the detection box to determine the target object in contact with the detection box.
9. The method for rendering water effects according to claim 1, characterized in that: The method further comprises: Applying a preset vortex map to a preset area of the water model; Determine the sinking depth of each vertex according to the distance from each vertex of the preset area to the center of the preset vortex map; The sinking depth is applied to corresponding vertices in the preset area to obtain a water model with a vortex display effect.
10. A device for rendering water effects, characterized in that: The device comprises: A target scene acquisition module is configured to acquire a target scene set in a target game engine, wherein the target scene includes a water body model and at least one object model; a target object determination module, configured to determine a target object in the target scene, wherein the target object is an object in the at least one object model that is higher than a water surface of the water body model; A binary mask map generation module is configured to generate a binary mask map based on the position of the target object in the target scene; the binary mask map includes a first color area and a second color area, and the second color area is an area corresponding to the target object; a water body rendering area determination module, configured to determine a water body rendering area in the first color area based on the second color area; The preset effect rendering module is configured to perform preset effect rendering on the effect rendering area in the water body model to obtain a water body model with the preset effect, and the effect rendering area corresponds to the water body rendering area.
11. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores at least one instruction or at least one program, and the at least one instruction or at least one program is loaded and executed by the processor to implement the method for rendering water effects as described in any one of claims 1-9.
12. An electronic device, characterized in that: It includes at least one processor and a memory communicatively connected to the at least one processor; wherein the memory stores instructions executable by the at least one processor, and the at least one processor implements the method for rendering water effects as described in any one of claims 1 to 9 by executing the instructions stored in the memory.
13. A computer program product, characterized in that The computer program product includes a computer program, which is stored in a readable storage medium. At least one processor of a computer device reads and executes the computer program from the readable storage medium, so that the computer device executes the method for rendering water effects as described in any one of claims 1 to 9.
Citation Information
Cited By
Digital twinborn scene efficient rendering method based on dynamic and static combination and vertex shader
CN119850848A
