Water surface edge softening method and water system modeling method
By creating edge gradient maps in the Cesium platform, the problem of insufficient water edge processing was solved, achieving a natural transition between water and land, and enhancing the realism and immersion of water rendering.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- KUNMING MAPU SPACE TECH CO LTD
- Filing Date
- 2026-03-18
- Publication Date
- 2026-06-02
AI Technical Summary
The existing Cesium standard water rendering solution lacks the softening effect on the water surface edges, resulting in obvious visual boundaries between the water body and the surrounding terrain or buildings, which affects the visual coherence and realism of the scene.
By creating an edge gradient map, including calculating the water surface texture size, drawing the water surface outline on the Canvas and stroking it layer by layer, an edge softening texture is generated. The edge of the water surface is then rendered using a GPU shader to achieve a natural transition between the water surface and the land.
It significantly enhances the realism and immersion of water surface rendering, improves the integration of water surface with other scene elements, and provides a more comfortable user experience.
Smart Images

Figure CN122134907A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of water system modeling technology, and in particular to a method for softening the edges of water surfaces and a water system modeling method. Background Technology
[0002] In urban 3D modeling, water system models are a crucial component in constructing realistic virtual scenes, typically forming a complete digital city system together with other modules such as buildings. In 3D geographic information platforms like Cesium, water surface rendering technology directly impacts the visual realism and immersiveness of the scene. However, existing Cesium standard water surface rendering solutions primarily focus on the basic visual attributes of water bodies, such as color, wave frequency, animation speed, and amplitude, but lack softening processing of water surface edges. This results in a harsh and unnatural visual boundary between the water body and surrounding terrain or buildings, affecting the overall visual coherence and realism of the scene and severely limiting the visual expressiveness of the water system model. Summary of the Invention
[0003] The technical problem to be solved by the present invention is to provide a method for softening the edges of water surfaces. By creating an edge gradient texture map, a natural transition between the water surface and the land is achieved, which effectively improves the integration of the water surface with other scene elements and significantly enhances the realism and immersion of water surface rendering.
[0004] To address the aforementioned technical problems, this invention provides a method for softening water surface edges, comprising creating an edge-softening texture, including the following steps: S1. Calculate the texture size of the water surface: First, calculate the minimum rectangular geographic range that can cover the water surface outline based on the geographic latitude and longitude coordinates of the water surface outline; then calculate the texture size of the water surface based on the minimum rectangular geographic range and the preset pixel ratio. S2. Create a Canvas: Create a Canvas based on the texture size, and convert the geographical coordinates of the water surface into Canvas pixel coordinates; S3. Draw the basic water surface outline: Draw a polygonal water surface outline on the Canvas and fill it with red to represent the entire water surface area; the red channel value of the red area is 1.0. S4. Create a gradient texture by stroking layer by layer: On the Canvas, mark a line at a distance of edgeBlur from the water surface outline, and then stroke the line layer by layer within the area between this line and the water surface outline; the method for stroking layer by layer is as follows: S41, Stroke: Use black to outline the water surface. The outer edge of the black stroke always fits the outline of the water surface, and the position of the inner edge is determined by the width of each stroke layer. The width of each stroke layer increases, and the pixel width of the i-th stroke layer is i. The value of the transparency α(i) of the i-th stroke layer decreases exponentially from i=0 to i=edgeBlur-2. The value range of α(i) is [0, 1]. α(i)=0 represents complete transparency; α(i)=1 represents complete opacity; α(0)=1, and α(edgeBlur-1)=0 is defined. edgeBlur represents the pixel width of the edge softening, which can be customized by the user and has a system default value; i represents the current stroke level, and the value of i ranges from 0 to edgeBlur-1; when i=0, it represents the water surface outline, that is, the 0th stroke, and the transparency of this stroke is 1, which means it is completely opaque. S42, Color Blending: After each layer of stroke is completed, the black stroke of that layer is blended with the current background color, and the RGBA components of the blended color rgba() are calculated; the blended color is then used as the new background color for that area; r is the value of the red channel, g is the value of the green channel, b is the value of the blue channel, and a is the value of the opacity. S43, Repeat steps S141 and S42 until the color blending of the edgeBlur-1 layer stroke is completed; S5. Convert the Canvas content into an image texture and generate an edge-softening texture.
[0005] Furthermore, the formula for calculating the transparency α(i) of the i-th layer stroke is as follows: α(i) = e^(-[ln(1 + edgeBlur) / edgeBlur]×i).
[0006] Furthermore, the method for color mixing in step S42 is as follows: Let the RGBA of the background color before blending be rgba(nr,0,0,na); nr is the red channel value of the current background color, and na is the opacity of the current background color; the RGBA of the i-th layer of black stroke to be blended is rgba(0,0,0,α(i)), and the formula for calculating the rgba value of the blended color is as follows: r = nr × (1 - α(i)); g=b=0; a = α(i) 2 +na×(1-α(i)); That is, the mixed color RGBA components are rgba(nr×(1-α(i)), 0, 0, α(i)). 2+na×(1-α(i))).
[0007] Furthermore, after the edge-softening texture is created, the GPU shader renders the water surface by sampling the red channel values of the edge-softening texture, including the following steps: S61, the value S of the red channel of the edge-softening texture sampled by the GPU shader; the value range of S is [0,1]. S62. Calculate the foreground color vector C1: C1=C_blend×(1-S)+C_water×S; in: C_blend represents the RGB components of the nearshore color vector; C_water represents the RGB components of the basic color vector of the water surface; S63. Calculate the final transparency α using the following formula: α=[A_blend×(1-S)+A_water×S]×S×O; in: A_blend: The transparency component value of the nearshore color; A_water: The transparency component of the base color of the water surface; O: Global transparency coefficient; S64. Perform Alpha blending to obtain the final RGB color C. The calculation formula is as follows: C = C1 × α + C2 × (1 - α); Where C refers to the RGB component of the final color; C1 refers to the RGB component of the foreground color; C2 refers to the RGB component of the background color; and α is the final transparency.
[0008] Furthermore, the algorithm for the system default value of edgeBlur is as follows: S4.1 Calculate the texture size based on the smallest rectangular geographic range that can cover the water surface outline and the preset "number of pixels per meter": Texture size = length of the short side of the rectangle × number of pixels per meter; S4.2 Divide the calculated texture size by 100 and then round down to get the default value of edgeBlur.
[0009] Furthermore, the calculation of the water surface texture size in S1 based on the minimum rectangular geographical range and a preset pixel ratio includes the following steps: S1.1 Define basic parameters: minimum texture width minWidth, maximum texture width maxWidth, and number of pixels per meter pixelsPerMeter; S1.2. Based on the geographical latitude and longitude coordinates of the water surface outline, calculate the smallest rectangular geographical area that can cover the water surface outline. Calculate the longitude difference Δλ and latitude difference Δφ of the rectangular region; S1.3 Define the values of the Earth's equatorial radius Re and the Earth's polar radius R; S1.4 Calculate the actual physical width of a geographical region using longitude differences: The actual physical width of the geographical region = Δλ × (2πRe) ÷ 360; Where Re is the Earth's equatorial radius; S1.5 Calculate the actual physical altitude of a geographical region using latitude differences: Actual physical altitude of a geographical region = Δφ × π × (Re + R) ÷ 360; Where Re is the Earth's equatorial radius; R is the Earth's polar radius; S1.6 Calculate the initial texture size: Convert the actual physical size to the texture pixel size: Initial texture width (pixels) = width (meters) × pixelsPerMeter; Initial texture height (pixels) = height (meters) × pixelsPerMeter; S1.7, Apply minimum width limit: If the initial texture width is less than the minimum texture width (minWidth), scale it up proportionally: Adjusted texture width = minWidth; Adjusted texture height = initial texture height × (minWidth ÷ initial texture width); S1.8, Maximum width limit for application: If the initial texture width is greater than the maximum texture width (maxWidth), scale it down proportionally: Adjusted texture width = maxWidth; Adjusted texture height = initial texture height × (maxWidth ÷ initial texture width); S1.9, Apply the same restrictions to height: Minimum and maximum size checks are also performed on texture height, while maintaining aspect ratio: If the adjusted texture height is less than minWidth; Final texture height = minWidth; Final texture width = adjusted texture width × (minWidth ÷ adjusted texture height); If the adjusted texture height is greater than maxWidth; Final texture height = maxWidth; Final texture width = adjusted texture width × (maxWidth ÷ adjusted texture height); S1.10, Return the calculation results: Finally, it returns the texture width and height that meet the size constraints.
[0010] The present invention also provides a water system modeling method, comprising the following steps: S1. Contour Acquisition: Acquire vertex data of the water surface and generate a two-dimensional polygonal contour of the water area; S2, Water surface creation; S3. Terrain Fitting: For the vertex coordinates of the water area's outline, interpolate the elevation value of that point from the Cesium global terrain service and add the retrieved elevation value to the vertex coordinates to make the water area's outline fit the terrain. S4. Soften the edges of the water surface according to the above-mentioned water surface edge softening method.
[0011] Furthermore, step S2, water surface creation, includes the following steps: S21. Initialize water surface parameters: Create a water surface geometry object and set basic parameters; S22. Calculate the dimensions of the water surface texture; S23. Generate water surface geometry: Convert the geographic coordinates of the vertices of the 2D polygon outline into 3D Cartesian coordinates. Based on the converted 3D Cartesian coordinates, create a water surface polygon geometry that matches the water area outline. According to the initialized water surface parameters, apply the calculated water surface texture size, configure the water surface texture with the corresponding resolution, and complete the setting of the water surface material according to the preset texture and water surface geographic range adaptation rules.
[0012] Furthermore, step S5 is also included: in the GLSL vertex shader, for each vertex of the water area's contour, a new 3D position P' is calculated based on its initial 3D position P, normal direction N, and time t. P'=P+A×sin(ω×t+φ_i)×N; Where: P is the original position of the vertex; P' is the position after the vertex oscillates; A represents the amplitude of the vertex movement. Users can customize the value of A, with a default value of 0.8. ω is the angular frequency of the vertex movement, ω=2π×frequency; where frequency is the preset vertex fluctuation frequency, which can be customized by the user, with a default value of 5000; N is the direction of the normal to the vertex; t represents the current time. The formula for calculating t is t = F × animationSpeed; Where F is the current frame number; animationSpeed is the preset animation speed; the default value is 0.003; F = (czm_frameNumber - 1) mod 15000000 + 1; Where czm_frameNumber represents the total number of frames rendered, starting from 1; φ_i is the phase of the i-th vertex, calculated using the following formula: φ_i=fract[(uv / scale_i)+(t×s_i)+offset_i]; in: fract() is a function that extracts the decimal part, ensuring that the result is within the range [0,1). t represents the current time; the formula for calculating t is t = F × animationSpeed; uv represents vertex texture coordinates; scale_i is the scaling factor for the noise sampling of the i-th vertex; s_i is the sampling direction vector of the i-th vertex; offset_i is the constant offset of the i-th vertex.
[0013] Furthermore, it also includes step S6, superimposing the heights of vertices at the same location under the influence of waves of different frequencies: H = Σ(Ai × sin(ωi × t + φi)); Where: H is the total height of the water surface at a specific location and time; i represents the sequence number of the different characteristic wave components used in the superposition of multi-frequency waves. Each i corresponds to a sine wave component with independent amplitude, frequency and phase. Ai is the amplitude of the i-th wave component; ωi is the angular frequency of the i-th wave component; t represents the current time; the formula for calculating t is t = F × animationSpeed; Where F is the current frame number; animationSpeed is the preset animation speed; φi is the phase of the i-th wave component; Σ represents the summation of all wave components.
[0014] Beneficial effects of this invention: This invention proposes a novel method for softening the edges of water surfaces. By creating an edge gradient texture map, it achieves a natural transition between the water surface and the land, effectively improving the integration of the water surface with other scene elements, significantly enhancing the realism and immersion of the water surface rendering, and providing a more comfortable and professional user experience. Attached Figure Description
[0015] Figure 1 This is a schematic diagram of the multi-layer outlining process; Figure 1 (a) is a schematic diagram of the first layer of outlining process; Figure 1 (b) is a schematic diagram of the second layer of outlining process; Figure 1 (c) is a schematic diagram of the third layer of outlining process; Figure 1 (d) is a schematic diagram of the fourth layer of outlining process; Figure 2 A comparison image showing the effect of softening the water surface edge before and after; Figure 2 (a) is the effect before the water surface edge is softened; Figure 2 (b) is the effect image after the water surface edge has been softened; Figure 3 Comparison images of local effects before and after softening the water surface edge; Figure 3 (a) is a partial view of the water surface before the edge is softened; Figure 3 (b) is a partial rendering of the water surface edge after softening; Figure 4 A comparison image showing the effect before and after simulating water ripples; Figure 4 (a) is the effect before the water ripple effect is simulated; Figure 4 (b) is a simulation of the water ripple effect; Figure 5 A comparison of local effects before and after simulating the water ripple effect; Figure 5 (a) is a partial view of the water ripple effect before simulation; Figure 5 (b) is a partial effect diagram of the simulated water ripple effect. Detailed Implementation
[0016] The specific embodiments of the present invention will be further described below with reference to the accompanying drawings. It should be noted that these descriptions are for the purpose of aiding understanding the present invention, but do not constitute a limitation thereof. Furthermore, the technical features involved in the various embodiments of the present invention described below can be combined with each other as long as they do not conflict with each other.
[0017] Example 1 A method for softening the edges of a water surface includes creating an edge-softening texture, comprising the following steps: S1. Calculate the texture size of the water surface: First, calculate the minimum rectangular geographic range that can cover the water surface outline based on the geographic latitude and longitude coordinates of the water surface outline; then calculate the texture size of the water surface based on the minimum rectangular geographic range and the preset pixel ratio. S2. Create a Canvas: Create a Canvas based on the texture size, and convert the geographical coordinates of the water surface into Canvas pixel coordinates; S3. Draw the basic water surface outline: Draw a polygonal water surface outline on the Canvas and fill it with red to represent the entire water surface area; the red channel value of the red area is 1.0. S4. Create a gradient texture by stroking layer by layer: On the Canvas, mark a line at a distance of edgeBlur from the water surface outline, and then stroke the line layer by layer within the area between this line and the water surface outline; the method for stroking layer by layer is as follows: S41, Stroke: Use black to outline the water surface. The outer edge of the black stroke always fits the outline of the water surface, and the position of the inner edge is determined by the width of each stroke layer. The width of each stroke layer increases, and the pixel width of the i-th stroke layer is i. The value of the transparency α(i) of the i-th stroke layer decreases exponentially from i=0 to i=edgeBlur-2. The value range of α(i) is [0, 1]. α(i)=0 represents complete transparency; α(i)=1 represents complete opacity; α(0)=1, and α(edgeBlur-1)=0 is defined. edgeBlur represents the pixel width of the edge softening, which can be customized by the user and has a system default value; i represents the current stroke level, and the value of i ranges from 0 to edgeBlur-1; when i=0, it represents the water surface outline, that is, the 0th stroke, and the transparency of this stroke is 1, which means it is completely opaque. S42, Color Blending: After each layer of stroke is completed, the black stroke of that layer is blended with the current background color, and the RGBA components of the blended color rgba() are calculated; the blended color is then used as the new background color for that area; r is the value of the red channel, g is the value of the green channel, b is the value of the blue channel, and a is the value of the opacity. S43, repeat steps S141 and S42 until the stroke and color blending of the edgeBlur-1 layer are completed; S5. Convert the Canvas content into an image texture and generate an edge-softening texture.
[0018] Specifically, the formula for calculating the transparency α(i) of the i-th layer stroke is as follows: α(i) = e^(-[ln(1 + edgeBlur) / edgeBlur]×i).
[0019] Specifically, the method for color mixing in step S42 is as follows: Let the RGBA of the background color before blending be rgba(nr,0,0,na); nr is the red channel value of the current background color, and na is the opacity of the current background color; the RGBA of the i-th layer of black stroke to be blended is rgba(0,0,0,α(i)), and the formula for calculating the rgba value of the blended color is as follows: r = nr × (1 - α(i)); g=b=0; a = α(i) 2 +na×(1-α(i)); That is, the mixed color RGBA components are rgba(nr×(1-α(i)), 0, 0, α(i)). 2 +na×(1-α(i))).
[0020] Figure 1 This is a schematic diagram of the multi-layer outlining process; Figure 1 (a) is a schematic diagram of the first layer of outlining process; Figure 1 (b) is a schematic diagram of the second layer of outlining process; Figure 1 (c) is a schematic diagram of the third layer of outlining process; Figure 1 (d) is a schematic diagram of the fourth layer of outlining process; The following is combined with Figure 1 The process of outlining and color blending is explained below: The transparency of the first layer of the stroke is α(1) = e^(-[ln(1 + edgeBlur) / edgeBlur]); After the first layer of stroke is completed, the first layer of black stroke rgba(0,0,0,α(1)) and red background rgba(255,0,0,1.0) are mixed. The RGBA of the mixed color is rgba(255×(1-α(1)),0,0,α(1)). 2+1-α(1)); and the mixed color rgba(255×(1-α(1)),0,0,α(1)). 2 +1-α(1)) is used as the new background color for this area, and is defined as background color number 1; The transparency of the second layer stroke is α(2) = e^(-[ln(1 + edgeBlur) / edgeBlur]×2), and the pixel width of the second layer stroke can completely cover and exceed the first layer stroke. After the second layer of stroke is completed, in the area where the second layer of stroke overlaps with the background color #1, the black stroke rgba(0,0,0,α(2)) and the background color #1 rgba(255×(1-α(1)),0,0,α(1)) are applied. 2 The mixture is +1-α(1)), and the resulting new color RGBA is rgba(255×(1-α(1))×(1-α(2)),0,0,α(2)). 2 +(α(1) 2 -α(1)+1)×(1-α(2))),define this color as background color No.2; In the area where the second layer stroke does not overlap with the base color #1, the black stroke rgba(0,0,0,α(2)) is mixed with the red base color rgba(255,0,0,1). The resulting RGBA color is rgba(255×(1-α(2)),0,0,α(2)). 2 +(1-α(2))), define this color as background color number 3; After the third layer of stroke is completed, in the area where the third layer of stroke overlaps with the base color #2, the black stroke rgba(0,0,0,α(3)) is mixed with the base color #2, and the resulting color is defined as base color #4; in the area where the third layer of stroke overlaps with the base color #3, the black stroke rgba(0,0,0,α(3)) is mixed with the base color #3, and the resulting color is defined as base color #5; in the area where the third layer of stroke does not overlap with the second layer of stroke, the black stroke rgba(0,0,0,α(3)) is mixed with the red base color rgba(255,0,0,1), and the resulting color is defined as base color #5. This process continues until the color blending of the edgeBlur-1 layer is complete.
[0021] After the edge-softening texture is created, the GPU shader renders the water surface by sampling the red channel values of the edge-softening texture, including the following steps: S61, the value S of the red channel of the edge-softening texture sampled by the GPU shader; the value range of S is [0,1], and S is obtained by linearly normalizing the r value of the image texture; S62. Calculate the foreground color vector C1: C1=C_blend×(1-S)+C_water×S; in: C_blend is the RGB component of the nearshore color vector, which can be user-defined. The default value is a hex format color value #001e0f, which is converted to RGB in decimal as rgb(0,30,15). C_water is the RGB component of the water surface base color vector. It supports user customization. The default value is a hex format color value #001e0f, which is converted to RGB in decimal as rgb(0,30,15). S63. Calculate the final transparency α using the following formula: α=[A_blend×(1-S)+A_water×S]×S×O; in: A_blend: The transparency component value of the nearshore color, which can be customized by the user, and the default value is 1; A_water: The transparency component of the water surface's base color, which can be user-defined, with a default value of 1; O: Global transparency factor, which can be customized by the user; the system default value is 0.95. The S64 and Cesium rendering pipelines perform alpha blending to obtain the final RGB color C, calculated using the following formula: C = C1 × α + C2 × (1 - α); Where C refers to the RGB component of the final color; C1 refers to the RGB component of the foreground color; C2 refers to the RGB component of the background color; and α is the final transparency. C2 is the existing color value in the frame buffer before rendering the water surface, representing the composite color of all rendered elements below the water surface and in the background.
[0022] The algorithm for edgeBlur's system default value is as follows: S4.1. Based on the smallest rectangular geographical area that can cover the water surface outline and the preset "number of pixels per meter" (the texture size is calculated as follows: texture size = length of the short side of the rectangle × number of pixels per meter; the default value of the number of pixels per meter is 20 pixels / meter); S4.2 Divide the calculated texture size by 100 and then round down to get the default value of edgeBlur.
[0023] The above calculations ensure that the larger the water surface area, the larger the texture size, the larger the default edgeBlur value, and the wider the edge softening area; conversely, the smaller the water surface area, the smaller the texture size, the smaller the default edgeBlur value, and the narrower the edge softening area. This guarantees that regardless of the water surface size, the edge softening effect maintains a matching proportion, avoiding issues such as insufficient edge softening for large water surfaces or excessive edge softening for small water surfaces.
[0024] S1 calculates the water surface texture size based on the minimum rectangular geographic range and a preset pixel ratio, including the following steps: S1.1 Define basic parameters: minimum texture width minWidth = 64 pixels, maximum texture width maxWidth = 4096 pixels, number of pixels per meter pixelsPerMeter = 20; S1.2. Based on the geographical latitude and longitude coordinates of the water surface outline, calculate the smallest rectangular geographical area that can cover the water surface outline. Calculate the longitude difference Δλ and latitude difference Δφ of the rectangular region; S1.3 Define Earth's parameters: Earth's equatorial radius Re = 6378137.0 and Earth's polar radius R = 6356752.3142; S1.4 Calculate the actual physical width of a geographical region (unit: meters) using longitude differences: The actual physical width of the geographical region = Δλ × (2πRe) ÷ 360; Where Re is the Earth's equatorial radius; S1.5 Calculate the actual physical altitude of a geographical region (unit: meters) using latitude differences: Actual physical altitude of a geographical region = Δφ × π × (Re + R) ÷ 360; Where Re is the Earth's equatorial radius; R is the Earth's polar radius; The average of the equatorial radius and the polar radius is used here to approximate the distance in the latitudinal direction; S1.6 Calculate the initial texture size: Convert the actual physical size to the texture pixel size: Initial texture width (pixels) = width (meters) × pixelsPerMeter; Initial texture height (pixels) = height (meters) × pixelsPerMeter; S1.7, Apply minimum width limit: If the initial texture width is less than the minimum texture width (minWidth), scale it up proportionally: Adjusted texture width = minWidth; Adjusted texture height = initial texture height × (minWidth ÷ initial texture width); S1.8, Maximum width limit for application: If the initial texture width is greater than the maximum texture width (maxWidth), scale it down proportionally: Adjusted texture width = maxWidth; Adjusted texture height = initial texture height × (maxWidth ÷ initial texture width); S1.9, Apply the same restrictions to height: Minimum and maximum size checks are also performed on texture height, while maintaining aspect ratio: If the adjusted texture height is less than minWidth; Final texture height = minWidth; Final texture width = adjusted texture width × (minWidth ÷ adjusted texture height); If the adjusted texture height is greater than maxWidth; Final texture height = maxWidth; Final texture width = adjusted texture width × (maxWidth ÷ adjusted texture height); S1.10, Return the calculation results: Finally, it returns the texture width and height that meet the size constraints.
[0025] Figure 2 A comparison image showing the effect of softening the water surface edge before and after; Figure 2 (a) is the effect before the water surface edge is softened; Figure 2 (b) is the effect image after the water surface edge has been softened; Figure 3 Comparison images of local effects before and after softening the water surface edge; Figure 3 (a) is a partial view of the water surface before the edge is softened; Figure 3 (b) is a partial view showing the softened effect at the water's edge. (Through...) Figure 2 and Figure 3 As can be seen, after the water surface edge softening treatment of this invention, the integration of the water surface with other scene elements is effectively improved, the realism and immersion of the water surface rendering are significantly enhanced, and a more comfortable and professional user experience can be provided.
[0026] Example 2 A water system modeling method includes the following steps: S1. Contour Acquisition: Acquire vertex data of the water surface and generate a two-dimensional polygonal contour of the water area; S2. Water Surface Creation: This includes the following steps: S21. Initialize water surface parameters: Create a water surface geometry object and set basic parameters, including: Geographic coordinates positions; The water surface base color (baseWaterColor) and the nearshore color (blendColor) both have RGBA components. Opacity, default 0.95; EdgeBlur is used to control the degree of blurring on the water surface; Frequency, used to control the undulation frequency of water waves, default value is 5000; The animation speed (animationSpeed) controls the speed at which the wave moves; the default value is 0.003. Amplitude, used to control the wave height, defaults to 0.8; S22. Calculate the dimensions of the water surface texture; S23. Generate water surface geometry: Convert the geographic coordinates of the vertices of the 2D polygon outline into 3D Cartesian coordinates. Based on the converted 3D Cartesian coordinates, create a water surface polygon geometry that matches the water area outline. According to the initialized water surface parameters, apply the calculated water surface texture size, configure the water surface texture with the corresponding resolution, and complete the setting of the water surface material according to the preset texture and water surface geographic range adaptation rules.
[0027] S3. Terrain Fitting: For the vertex coordinates of the water area's outline, interpolate the elevation value of that point from the Cesium global terrain service and add the retrieved elevation value to the vertex coordinates to make the water area's outline fit the terrain. S4. Soften the edges of the water surface according to the water surface edge softening method; S5. In the GLSL vertex shader, for each vertex of the water area's contour, calculate the new 3D position P' of that vertex based on its initial 3D position P, normal direction N, and time t: P'=P+A×sin(ω×t+φ_i)×N, Where: P is the original position of the vertex; P' is the position after the vertex oscillates; A represents the amplitude of the vertex movement. Users can customize the value of A, which is 0.8 by default. ω is the angular frequency of the vertex movement, ω = 2π × frequency; where frequency is the preset vertex oscillation frequency; Users can customize the frequency value, with a default value of 5000; N is the direction of the normal to the vertex; t represents the current time. The formula for calculating t is t = F × animationSpeed; Where F is the current frame number; animationSpeed is the preset animation speed; the default value is 0.003; F = (czm_frameNumber - 1) mod 15000000 + 1; Where czm_frameNumber represents the total number of frames rendered, starting from 1; φ_i is the phase of the i-th vertex, calculated using the following formula: φ_i=fract[(uv / scale_i)+(t×s_i)+offset_i]; in: fract() is a function that extracts the decimal part, ensuring that the result is within the range [0,1). t represents the current time; the formula for calculating t is t = F × animationSpeed; uv represents vertex texture coordinates (spatial position); scale_i is the scaling factor for the noise sampling of the i-th vertex; scale_i is indirectly related to the user-defined frequency parameter, but they are not one-to-one. The frequency parameter can indirectly affect the granularity of noise sampling and the density of waves by scaling the material coordinates. Users cannot directly modify the scale_i value inside the czm_getWaterNoise function. For users, adjusting the frequency parameter can achieve a similar effect to adjusting scale_i, affecting the detail density of water waves. s_i is the sampling direction vector of the i-th vertex; offset_i is the constant offset of the i-th vertex; The parameters s_i, offset_i, and angle are details of the Cesium engine's internal implementation. In the current code: s_i and offset_i are hard-coded in the czm_getWaterNoise function and cannot be directly modified by the user; although the angle parameter is passed as a function parameter, it is currently fixed at 0.0 and is not exposed to the user for configuration.
[0028] S6. Superimpose the heights of vertices at the same location under the influence of waves of different frequencies: H = Σ(Ai × sin(ωi × t + φi)); Where: H is the total height of the water surface at a specific location and time; i represents the sequence number of the different characteristic wave components used in the superposition of multi-frequency waves. Each i corresponds to a sine wave component with independent amplitude, frequency and phase. Ai is the amplitude of the i-th wave component; ωi is the angular frequency of the i-th wave component; t represents the current time; the calculation method for t is the same as before; φi is the phase of the i-th wave component; Σ represents the summation of all wave components.
[0029] S7 renders water surface ripple effects: In the fragment shader, new normals are recalculated based on P' and H. The core texture of the water is constructed by blending the base color and calculating Fresnel reflections and specular highlights. Detailed normal maps and refraction effects are then overlaid to enhance visual realism. The S7 rendering process is based on existing technology.
[0030] Through steps S5-S7, a sine wave superposition algorithm is used to simulate water surface ripples. The vertex shader is used to dynamically displace the vertices of the water surface mesh to achieve a dynamic ripple effect.
[0031] Figure 4 A comparison image showing the effect before and after simulating water ripples; Figure 4 (a) is the effect before the water ripple effect is simulated; Figure 4 (b) is a simulation of the water ripple effect; Figure 5 A comparison of local effects before and after simulating the water ripple effect; Figure 5 (a) is a partial view of the water ripple effect before simulation; Figure 5 (b) is a partial effect diagram of the simulated water ripple effect. (Through...) Figure 4 and Figure 5 As can be seen, after the water ripple simulation of the present invention, the water surface presents a shimmering effect.
[0032] The embodiments of the present invention have been described in detail above with reference to the accompanying drawings, but the present invention is not limited to the described embodiments. For those skilled in the art, various changes, modifications, substitutions, and variations can be made to these embodiments without departing from the principles and spirit of the present invention, and these variations still fall within the protection scope of the present invention.
Claims
1. A method for softening the edge of a water surface, characterized in that: Creating an edge-softening texture involves the following steps: S1. Calculate the texture size of the water surface: First, calculate the minimum rectangular geographic range that can cover the water surface outline based on the geographic latitude and longitude coordinates of the water surface outline; then calculate the texture size of the water surface based on the minimum rectangular geographic range and the preset pixel ratio. S2. Create a Canvas: Create a Canvas based on the texture size, and convert the geographical coordinates of the water surface into Canvas pixel coordinates; S3. Draw the basic water surface outline: Draw a polygonal water surface outline on the Canvas and fill it with red to represent the entire water surface area; the red channel value of the red area is 1.
0. S4. Create a gradient texture by stroking layer by layer: On the Canvas, mark a line at a distance of edgeBlur from the water surface outline, and then stroke the line layer by layer within the area between this line and the water surface outline; the method for stroking layer by layer is as follows: S41, Stroke: Use black to outline the water surface. The outer edge of the black stroke always fits the outline of the water surface, and the position of the inner edge is determined by the width of each stroke layer. The width of each stroke layer increases, and the pixel width of the i-th stroke layer is i. The value of the transparency α(i) of the i-th stroke layer decreases exponentially from i=0 to i=edgeBlur-2. The value range of α(i) is [0, 1]. α(i)=0 represents complete transparency; α(i)=1 represents complete opacity; α(0)=1, and α(edgeBlur-1)=0 is defined; edgeBlur represents the pixel width of the edge softening effect; i represents the current stroke level, and the value of i ranges from 0 to edgeBlur-1; When i=0, it represents the outline of the water surface, that is, the 0th layer of the stroke. The transparency of this layer of the stroke is 1, which means it is completely opaque. S42, Color Blending: After each layer of stroke is completed, the black stroke of that layer is blended with the current background color, and the RGBA component rgba() of the blended color is calculated; the blended color is then used as the new background color for that area. r is the value of the red channel, g is the value of the green channel; b is the value of the blue channel; a is the value of the opacity. S43, Repeat steps S141 and S42 until the color blending of the edgeBlur-1 layer stroke is completed; S5. Convert the Canvas content into an image texture and generate an edge-softening texture.
2. The water surface edge softening method according to claim 1, characterized in that: The formula for calculating the transparency α(i) of the i-th layer stroke is as follows: α(i)=e^(-[ln(1+edgeBlur) / edgeBlur]×i).
3. The water surface edge softening method according to claim 1, characterized in that: The method for color mixing in step S42 is as follows: Let the RGBA of the background color before blending be rgba(nr,0,0,na); nr is the red channel value of the current background color, and na is the opacity of the current background color; the RGBA of the i-th layer of black stroke to be blended is rgba(0,0,0,α(i)), and the formula for calculating the rgba value of the blended color is as follows: r = nr × (1 - α(i)); g=b=0; a=α(i) 2 +na×(1-α(i)); That is, the mixed color RGBA components are rgba(nr×(1-α(i)), 0, 0, α(i)). 2 +na×(1-α(i))).
4. The water surface edge softening method according to claim 1, characterized in that: After the edge-softening texture is created, the GPU shader renders the water surface by sampling the red channel values of the edge-softening texture, including the following steps: S61, the value S of the red channel of the edge-softening texture sampled by the GPU shader; the value range of S is [0,1]. S62. Calculate the foreground color vector C1: C1=C_blend×(1-S)+C_water×S; in: C_blend represents the RGB components of the nearshore color vector; C_water represents the RGB components of the basic color vector of the water surface; S63. Calculate the final transparency α using the following formula: α=[A_blend×(1-S)+A_water×S]×S×O; in: A_blend: The transparency component value of the nearshore color; A_water: The transparency component of the base color of the water surface; O: Global transparency coefficient; S64. Perform Alpha blending to obtain the final RGB color C. The calculation formula is as follows: C = C1 × α + C2 × (1 - α); Where C refers to the RGB component of the final color; C1 refers to the RGB component of the foreground color; C2 refers to the RGB component of the background color; and α is the final transparency.
5. The water surface edge softening method according to claim 1, characterized in that: The algorithm for the system default value of edgeBlur is as follows: S4.1 Calculate the texture size based on the smallest rectangular geographic range that can cover the water surface outline and the preset "number of pixels per meter": Texture size = length of the short side of the rectangle × number of pixels per meter; S4.2 Divide the calculated texture size by 100 and then round down to get the default value of edgeBlur.
6. The water surface edge softening method according to claim 1, characterized in that: The step S1, which calculates the water surface texture size based on the minimum rectangular geographic range and a preset pixel ratio, includes the following steps: S1.1 Define basic parameters: minimum texture width minWidth, maximum texture width maxWidth, and number of pixels per meter pixelsPerMeter; S1.
2. Based on the geographical latitude and longitude coordinates of the water surface outline, calculate the smallest rectangular geographical area that can cover the water surface outline. Calculate the longitude difference Δλ and latitude difference Δφ of the rectangular region; S1.3 Define the values of the Earth's equatorial radius Re and the Earth's polar radius R; S1.4 Calculate the actual physical width of a geographical region using longitude differences: The actual physical width of the geographical region = Δλ × (2πRe) ÷ 360; Where Re is the Earth's equatorial radius; S1.5 Calculate the actual physical altitude of a geographical region using latitude differences: Actual physical altitude of a geographical region = Δφ × π × (Re + R) ÷ 360; Where Re is the Earth's equatorial radius; R is the Earth's polar radius; S1.6 Calculate the initial texture size: Convert the actual physical size to the texture pixel size: Initial texture width (pixels) = width (meters) × pixelsPerMeter; Initial texture height (pixels) = height (meters) × pixelsPerMeter; S1.7, Apply minimum width limit: If the initial texture width is less than the minimum texture width (minWidth), scale it up proportionally: Adjusted texture width = minWidth; Adjusted texture height = initial texture height × (minWidth ÷ initial texture width); S1.8, Maximum width limit for application: If the initial texture width is greater than the maximum texture width (maxWidth), scale it down proportionally: Adjusted texture width = maxWidth; Adjusted texture height = initial texture height × (maxWidth ÷ initial texture width); S1.9, Apply the same restrictions to height: Minimum and maximum size checks are also performed on texture height, while maintaining aspect ratio: If the adjusted texture height is less than minWidth; Final texture height = minWidth; Final texture width = adjusted texture width × (minWidth ÷ adjusted texture height); If the adjusted texture height is greater than maxWidth; Final texture height = maxWidth; Final texture width = adjusted texture width × (maxWidth ÷ adjusted texture height); S1.10, Return the calculation results: Finally, it returns the texture width and height that meet the size constraints.
7. A water system modeling method, characterized in that: Includes the following steps: S1. Contour Acquisition: Acquire vertex data of the water surface and generate a two-dimensional polygonal contour of the water area; S2, Water surface creation; S3. Terrain Fitting: For the vertex coordinates of the water area's outline, interpolate the elevation value of that point from the Cesium global terrain service and add the retrieved elevation value to the vertex coordinates to make the water area's outline fit the terrain. S4. The water surface is softened by the water surface edge softening method according to any one of claims 1-6.
8. The water system modeling method according to claim 7, characterized in that: Step S2, water surface creation, includes the following steps: S21. Initialize water surface parameters: Create a water surface geometry object and set basic parameters; S22. Calculate the dimensions of the water surface texture; S23. Generate water surface geometry: Convert the geographic coordinates of the vertices of the 2D polygon outline into 3D Cartesian coordinates. Based on the converted 3D Cartesian coordinates, create a water surface polygon geometry that matches the water area outline. According to the initialized water surface parameters, apply the calculated water surface texture size, configure the water surface texture with the corresponding resolution, and complete the setting of the water surface material according to the preset texture and water surface geographic range adaptation rules.
9. The water system modeling method according to claim 7, characterized in that: This also includes step S5: In the GLSL vertex shader, for each vertex of the water area's contour, a new 3D position P' is calculated based on its initial 3D position P, normal direction N, and time t. P'=P+A×sin(ω×t+φ_i)×N; Where: P is the original position of the vertex; P' is the position after the vertex oscillates; A is the amplitude of the vertex movement; ω is the angular frequency of the vertex movement; ω = 2π × frequency; where frequency is the preset vertex oscillation frequency; N is the direction of the normal to the vertex; t represents the current time. The formula for calculating t is t = F × animationSpeed; Where F is the current frame number; animationSpeed is the preset animation speed; F=(czm_frameNumber-1)mod15000000+1; Where czm_frameNumber represents the total number of frames rendered, starting from 1; φ_i is the phase of the i-th vertex, calculated using the following formula: φ_i=fract[(uv / scale_i)+(t×s_i)+offset_i]; in: fract() is a function that extracts the decimal part of a number; t represents the current time; the formula for calculating t is t = F × animationSpeed; uv represents vertex texture coordinates; scale_i is the scaling factor for the noise sampling of the i-th vertex; s_i is the sampling direction vector of the i-th vertex; offset_i is the constant offset of the i-th vertex.
10. The water system modeling method according to claim 9, characterized in that: It also includes step S6, which involves superimposing the heights of vertices at the same location under the influence of waves of different frequencies: H = Σ(Ai × sin(ωi × t + φi)); Where: H is the total height of the water surface at a specific location and time; i represents the sequence number of the different characteristic wave components used in the superposition of multi-frequency waves. Each i corresponds to a sine wave component with independent amplitude, frequency and phase. Ai is the amplitude of the i-th wave component; ωi is the angular frequency of the i-th wave component; t represents the current time; the formula for calculating t is t = F × animationSpeed; Where F is the current frame number; animationSpeed is the preset animation speed; φi is the phase of the i-th wave component; Σ represents the summation of all wave components.