A GPU fluid simulation method for real-time interactive applications
By using a position-based fluid particle simulation algorithm and screen space processing on the GPU, the problems of low computational efficiency and poor visual effects of existing fluid simulation methods in real-time interactive applications are solved, realizing efficient 3D fluid simulation and dynamic object interaction, and enhancing the realism of fluid effects.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- NORTHEASTERN UNIV CHINA
- Filing Date
- 2022-12-05
- Publication Date
- 2026-04-21
AI Technical Summary
Existing fluid simulation methods suffer from low computational efficiency, inability to achieve three-dimensional spatial fluid simulation, poor visual effects, or inability to interact with dynamic objects in real-time interactive applications.
A position-based fluid particle simulation algorithm is used to perform fluid simulation on the GPU. Particles are emitted through a particle system, and combined with screen space processing and realistic rendering, smooth reconstruction and rendering of fluid surfaces are achieved.
It improves the simulation efficiency and stability of fluid simulation, enables efficient 3D fluid simulation and dynamic object interaction, and enhances the realism of fluid effects.
Smart Images

Figure CN115906703B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of fluid simulation technology, and in particular to a GPU fluid simulation method for real-time interactive applications. Background Technology
[0002] With the development of fluid simulation technology, realistic real-time fluid animation simulation has been widely used in commercial films, large-scale games and urban disaster prediction systems. Among them, stable and accurate numerical solution models and high computational efficiency have always been important research contents.
[0003] In real-time applications, because simulation is highly sensitive to computational resources, three common fluid simulation solutions exist: One is to use offline baked sequences of 2D images or 3D models, looping them to simulate fluid changes. This method typically uses a meshless approach, with Smoothed Particle Hydrodynamics (SPH) being the most popular method due to its computational simplicity and efficiency compared to other methods. However, converting the simulated particles into a renderable 3D model still requires significant computation. Currently, screen-space techniques are primarily used to generate polygonal meshes or marching cubes from the particle data. Since mesh generation methods are invariably computationally expensive...
[0004] Secondly, a particle system is used to emit a large number of particles. By adjusting the particle speed, size changes, and calculating external forces such as gravity and collisions, an approximate fluid effect can be achieved. In recent years, with the improvement of computing power, especially the popularization of GPU general-purpose computing technology, GPUs, which are originally only used for image rendering and are good at large-scale parallel computing, can participate in particle computing. This greatly expands the number of particles that a particle system can maintain and the complexity of particle motion rules, providing a foundation for real-time fluid particle simulation.
[0005] Thirdly, there is real-time planar fluid simulation based on two-dimensional meshes. This mesh-based simulation method can effectively simulate fluid motion within a two-dimensional plane. Due to the dimensional difference between two-dimensional and three-dimensional spaces, the computational scale of this method is significantly reduced compared to three-dimensional space simulation. Therefore, real-time fluid simulation can be achieved, meeting interactive requirements. The resulting two-dimensional density image can also be rendered using the RayMarching method to obtain a pseudo-three-dimensional visual effect.
[0006] While offline baking methods can achieve high-precision fluid effects, they require a large amount of pre-baked data and the fluid cannot interact with dynamic objects in the scene. Using simple particle emitters can efficiently achieve fluid effects, but it lacks physical simulation and has poor visual effects. Mesh-based real-time 2D fluid calculation methods can achieve interactive fluid effects, but they are limited to planar fluid scenes such as water surfaces and land surfaces, and cannot simulate fluids in 3D space. Summary of the Invention
[0007] The technical problem to be solved by the present invention is to address the shortcomings of the prior art by providing a GPU fluid simulation method for real-time interactive applications, which enables animated simulation of fluids.
[0008] To solve the above-mentioned technical problems, the technical solution adopted by this invention is: a GPU fluid simulation method for real-time interactive applications, in which all calculations are performed on the GPU. First, a particle system is used to emit a large number of particles, and a position-based fluid particle simulation algorithm is used to calculate the positions of the fluid particles and update their motion states. Then, a smooth fluid surface is obtained through screen space processing based on the particle positions. Finally, a realistic rendering method is used to color the fluid surface to obtain a water image. Specifically, the method includes the following steps:
[0009] Step 1: Use a particle system to emit a large number of particles, and then use a position-based fluid particle simulation algorithm to update the positions of the fluid particles, thus completing the update of the particle motion state;
[0010] Step 1.1: Use a particle system to launch a large number of particles in the fluid simulation space, and divide the fluid simulation space into several three-dimensional grid regions to construct a neighboring particle search grid.
[0011] When updating the position of fluid particles, the particle index is written to the corresponding grid. When it is necessary to query the neighboring particles of a certain particle, the grid where the particle is located can be calculated based on the particle coordinates in linear time. Then, it is only necessary to traverse the particles in that grid to obtain all particles within a certain range.
[0012] Step 1.2: Calculate the effects of gravity and collision on the particles; the effect of gravity on the particles is shown in the following formula:
[0013]
[0014] Where, Δp g v0 is the positional influence component caused by gravity, Δt is the current velocity of the particle, g is the time interval between two updates, and g is the gravitational acceleration.
[0015] The impact of the collision on the particles is determined by the depth field of the virtual scene, specifically:
[0016] The depth field of the virtual scene is sampled using particle coordinates to obtain the distance from the particle to the nearest surface in the scene. If the particle is inside the surface or the distance from the particle to the surface is less than a pre-defined particle radius, it indicates that the particle has collided, and collision calculation is required. In the position-based fluid particle simulation algorithm, the collision calculation does not require calculating the force of the collision, but only needs to analyze different situations: when the particle is inside the surface, the new position of the particle is the collision position plus the direction from the particle to the collision position multiplied by the particle radius; when the distance between the particle and the surface is less than a pre-defined particle radius, the new position of the particle is the collision position plus the direction from the collision position to the particle center multiplied by the particle radius.
[0017] Step 1.3: Calculate the interaction between particles inside the fluid, and calculate the displacement vector Δp of the particles based on the incompressible constraint;
[0018] First, iterate through all particles within a distance h around the currently computed particle i, and calculate the kernel function W based on the distances between the particles. Poly6 The value of is shown in the following formula:
[0019]
[0020] Among them, W Poly6 (r,h) is the kernel function, where r is the distance vector from other particles to particle i, and h is the preset maximum search distance;
[0021] Then, iterate through all particles within a distance h around particle i and calculate the density ρ at the location of particle i. i As shown in the formula below:
[0022]
[0023] Where, m j p is the mass of particle j within a distance h around particle i; i To calculate the current position of particle i, p j Let h be the position of particle j within a distance h around particle i;
[0024] Because liquids are incompressible, it is necessary to ensure that the density of each particle i is the same as the static density of the fluid; for the current particle i being calculated, C is defined. i Its density constraint is shown in the following formula:
[0025]
[0026] Where p1,…,p n ρ represents the position of particle i and the positions of its neighboring particles. iρ0 is the density at the current particle location calculated in the previous step, and ρ0 is the density of the fluid in a static state.
[0027] Then calculate the Lagrange multiplier λ corresponding to particle i. i :
[0028]
[0029] Where ∈ is the relaxation parameter. Density constraint C for the i-th particle i At position p k The gradient with respect to position;
[0030] Then, the displacement vector Δp obtained by particle i after passing through its own density constraint and the density constraints of neighboring particles is calculated. i :
[0031]
[0032] Where, λ j Let be the Lagrange multiplier corresponding to particle j;
[0033] Among them, W Spiky (r,h) represents the density constraint C. i At position p k The Spiky kernel function used for gradient calculation with respect to position is shown in the following formula:
[0034]
[0035] For W Spiky Differentiating (r,h) with respect to r, we get:
[0036]
[0037] Assuming all particles in the fluid have the same mass, we can further obtain:
[0038]
[0039] Then C i Regarding position p k gradient As shown in the formula below:
[0040]
[0041] Where k∈1,…,n;
[0042] Depending on the value of k, They are respectively:
[0043]
[0044] Step 1.4: Add the displacement of the particle caused by the external force obtained in Step 1.2 to the displacement caused by the interaction between particles obtained in Step 1.3 to obtain the particle's position change Δp; add the particle's position change Δp to the particle's original position to obtain the particle's new position; at the same time, divide the particle's position change Δp by the unit time Δt to obtain the particle's velocity at that moment, which is used to calculate the influence of the external force on the particle in the next round of particle position update.
[0045] Step 2: After updating the particle motion state, use screen space to reconstruct the fluid surface;
[0046] Step 2.1: Map all fluid particles from three-dimensional world space to two-dimensional screen space;
[0047] Multiply the perspective projection matrix M of the virtual camera with the homogeneous coordinates of the three-dimensional world space of the fluid particle to obtain the two-dimensional coordinates of the fluid particle in the screen space, and obtain the fluid surface image mapped to the two-dimensional screen space.
[0048] Step 2.2: Smooth the fluid surface image mapped to the two-dimensional screen space to obtain a smoothed fluid surface image;
[0049] First, the depth image of the particles is sampled, and then bilateral filtering is used to smooth the areas where the difference in depth values is less than a set threshold, thereby preserving the boundaries between the foreground and background of the fluid image.
[0050] Step 3: Render the fluid realistically based on the smooth fluid surface image and the scene's frame buffer;
[0051] Step 3.1: Color the fluid surface based on depth buffer and color buffer;
[0052] First, the fluid thickness is calculated based on the interpolation between the fluid depth image and the original depth buffer of the scene;
[0053] The basic color of the fluid is obtained by attenuating the incident light color to different degrees according to the fluid thickness.
[0054] Then, based on the fluid's opacity, the fluid's base color is superimposed with the scene color in the color buffer to obtain the color of the fluid's surface;
[0055] Step 3.2: Render the effect of floating foam on the fluid; During fluid simulation, particles with fewer than a set threshold of neighboring particles are marked as foam particles, and then the foam particle image is obtained through screen space mapping; During shading rendering, the foam particle image is sampled, and the fluid surface color is mixed with the foam color according to the sampling results;
[0056] Step 3.3, Caustic Effect Rendering: When sampling the scene depth buffer, the world coordinates corresponding to the screen space coordinates are obtained through matrix transformation. The x and y components of the world coordinates are used as the coordinates in the UV space. The pre-baked caustic map is sampled, and the sampled color is added to the sampling result of the scene color buffer to obtain the caustic effect. Multiple caustic maps are sampled in a loop to make the caustic effect dynamically displayed.
[0057] The beneficial effects of adopting the above technical solution are as follows: The GPU fluid simulation method for real-time interactive applications provided by this invention includes the use of a position-based fluid simulation algorithm, which has advantages such as high simulation efficiency and strong stability compared with traditional simulation algorithms; the use of a screen-space fluid surface reconstruction method can efficiently obtain smooth fluid surface images; the implementation of water effects such as refraction and reflection based on frame buffering, and the use of fluid effects such as foam caustics to enhance the realism of the rendering. As an efficient physical simulation method for real-time fluid simulation, this invention can be widely applied to various scenarios in industrial simulation and video game fields. Attached Figure Description
[0058] Figure 1 A flowchart illustrating a GPU fluid simulation method for real-time interactive applications provided in an embodiment of the present invention;
[0059] Figure 2 A flowchart illustrating the updating of fluid particle positions using a position-based fluid particle simulation algorithm provided in this embodiment of the invention;
[0060] Figure 3 This is a schematic diagram based on depth collision provided for an embodiment of the present invention, wherein (a) shows a particle inside the surface, and (b) shows a particle approaching the surface but still outside the surface;
[0061] Figure 4 This is a schematic diagram of screen mapping provided in an embodiment of the present invention;
[0062] Figure 5 Depth images of fluid particles provided in embodiments of the present invention;
[0063] Figure 6 Implementation of the particle simulation algorithm provided in the embodiments of the present invention
[0064] Figure 7 This is a realistically rendered water effect diagram provided in an embodiment of the present invention;
[0065] Figure 8 This is a reconstructed smooth fluid surface diagram provided for an embodiment of the present invention. Detailed Implementation
[0066] The specific embodiments of the present invention will be described in further detail below with reference to the accompanying drawings and examples. The following examples are for illustrative purposes only and are not intended to limit the scope of the invention.
[0067] In this embodiment, a GPU fluid simulation method for real-time interactive applications is presented. All computational processes are run on the GPU. First, a large number of particles are emitted using a particle system, and the positions of the fluid particles are calculated using a position-based fluid particle simulation algorithm to update the particle motion state. Then, a smooth fluid surface is obtained through screen space processing based on the particle positions. Finally, a realistic rendering method is used to color the fluid surface to obtain a fluid image. Since the state update of a large number of particles and the pixel-level calculation in screen space are both large-scale parallel computations, they are very suitable for GPU processing. Therefore, all computational processes involved in this method are run on the GPU.
[0068] like Figure 1 As shown, the method specifically includes the following steps:
[0069] Step 1: Use a particle system to emit a large number of particles, and then use a position-based fluid particle simulation algorithm (PBF) to update the positions of the fluid particles, thus completing the update of the particle motion state. Figure 2 As shown, the specific steps include:
[0070] Step 1.1: Use a particle system to launch a large number of particles in the fluid simulation space, and divide the fluid simulation space into several three-dimensional grid regions to construct a neighboring particle search grid.
[0071] When calculating particle constraints, it is necessary to obtain the positions of all particles within a certain distance. Searching through all particles would consume significant computational resources and compromise real-time performance. Therefore, a uniform grid hash structure is needed for acceleration. When updating fluid particle positions, the particle's index is written to the corresponding grid. When querying a particle's neighbors, since the grid is uniformly divided, the particle's grid location can be determined linearly based on its coordinates. Then, only the particles within that grid need to be traversed to obtain most particles within a certain range. While this method cannot guarantee the acquisition of all neighboring particles, it significantly reduces computational load and is well-suited for GPU parallel computing, thus enabling rapid neighbor particle lookup.
[0072] Step 1.2: Calculate the effects of gravity and collision on the particles; the effect of gravity on the particles is shown in the following formula:
[0073]
[0074] Where, Δp gv0 is the positional influence component caused by gravity, Δt is the current velocity of the particle, g is the time interval between two updates, and g is the gravitational acceleration.
[0075] In traditional fluid simulation, collisions between fluids and scene objects involve numerous intersection calculations, resulting in low efficiency and unsuitability for real-time simulation. Modern real-time game engines, however, typically maintain a depth field. This depth field, pre-computed, stores the distances from each location in space to the nearest surface. Collision calculations can be performed very conveniently using the depth field.
[0076] The impact of the collision on the particles is determined by the depth field of the virtual scene, specifically:
[0077] The depth field of the virtual scene (i.e., the fluid environment) is sampled using particle coordinates to obtain the distance from the particle to the nearest surface in the scene. If the particle is inside the surface or the distance from the particle to the surface is less than a pre-defined particle radius, it indicates that a collision has occurred, and collision calculation is required. In position-based fluid particle simulation algorithms, collision calculation does not require calculating the forces involved in the collision; it only requires analysis of different situations, such as... Figure 3 As shown: when a particle is inside the surface, the particle's new position is the collision position plus the product of the direction from the collision position and the particle radius; when the particle is less than the predetermined particle radius (i.e., close to the surface but still outside the surface), the particle's new position is the collision position plus the product of the direction from the collision position to the particle center and the particle radius; in this way, it can be ensured that the particle's new position does not result in a collision.
[0078] Step 1.3: Calculate the interaction between particles inside the fluid, and calculate the displacement vector Δp of the particles based on the incompressible constraint;
[0079] First, iterate through all particles within a distance h around the currently computed particle i, and calculate the kernel function W based on the distances between the particles. Poly6 The value of is shown in the following formula:
[0080]
[0081] Among them, W Poly6 (r,h) is the kernel function, where r is the distance vector from other particles to particle i, and h is the preset maximum search distance;
[0082] Then, iterate through all particles within a distance h around particle i and calculate the density ρ at the location of particle i. i As shown in the formula below:
[0083]
[0084] Where, m jp is the mass of particle j within a distance h around particle i; i To calculate the current position of particle i, p j Let h be the position of particle j within a distance h around particle i;
[0085] Because liquids are incompressible, it is necessary to ensure that the density of each particle i is the same as the static density of the fluid; for the current particle i being calculated, C is defined. i Its density constraint is shown in the following formula:
[0086]
[0087] Where p1,…,p n ρ represents the position of particle i and the positions of its neighboring particles. i ρ0 is the density at the current particle location calculated in the previous step, and ρ0 is the density of the fluid in a static state, which is a constant set by the user.
[0088] Then calculate the Lagrange multiplier λ corresponding to particle i. i :
[0089]
[0090] Here, ∈ is a relaxation parameter introduced to avoid the division by zero problem, which is set by the user; Density constraint C for the i-th particle i At position p k The gradient with respect to position;
[0091] Then, the displacement vector Δp obtained by particle i after passing through its own density constraint and the density constraints of neighboring particles is calculated. i :
[0092]
[0093] Where, λ j Let be the Lagrange multiplier corresponding to particle j;
[0094] Among them, W Spiky (r,h) represents the density constraint C. i At position p k The Spiky kernel function used for gradient calculation with respect to position is shown in the following formula:
[0095]
[0096] For W Spiky Differentiating (r,h) with respect to r, we get:
[0097]
[0098] Assuming all particles in the fluid have the same mass, we can further obtain:
[0099]
[0100] Then C i Regarding position p k gradient As shown in the formula below:
[0101]
[0102] Where k∈1,…,n;
[0103] Depending on the value of k, They are respectively:
[0104]
[0105] Step 1.4: Add the displacement of the particle caused by the external force obtained in Step 1.2 to the displacement caused by the interaction between particles obtained in Step 1.3 to obtain the particle's position change Δp; add the particle's position change Δp to the particle's original position to obtain the particle's new position; at the same time, divide the particle's position change Δp by the unit time Δt to obtain the particle's velocity at that moment, which is used to calculate the influence of the external force on the particle in the next round of particle position update.
[0106] Step 2: After updating the particle motion state, reconstruct the fluid surface using screen space. Since building a 3D model from the particles requires significant computational power, it is difficult to implement in real-time applications. Therefore, screen space is used for fluid surface reconstruction. This includes the following two steps:
[0107] Step 2.1: Map all fluid particles from three-dimensional world space to two-dimensional screen space, such as... Figure 4 As shown; particles in three-dimensional space cannot be directly filtered to obtain the fluid surface, therefore they need to be mapped to two-dimensional screen space; firstly, the camera perspective projection matrix M is calculated based on the virtual camera parameters:
[0108]
[0109] Where aspect is the aspect ratio of the camera clipping plane, α is the field of view of the camera, NearZ is the distance from the camera to the near clipping plane, and FarZ is the distance from the camera to the far clipping plane;
[0110] Then, the perspective projection matrix M of the virtual camera is multiplied with the homogeneous coordinates of the three-dimensional world space of the fluid particle to obtain the two-dimensional coordinates of the fluid particle in the screen space, thus obtaining the fluid surface image mapped to the two-dimensional screen space.
[0111] Step 2.2: Smooth the fluid surface image mapped to the two-dimensional screen space to obtain a smoothed fluid surface image;
[0112] Because fluid surface images mapped from world space to screen space have strong graininess, they cannot be directly used for rendering. Therefore, smoothing through filtering is necessary. The depth image of the fluid particles is as follows: Figure 5 As shown, the brightness of each pixel in the image represents the depth value, that is, the distance from that location to the camera. To ensure that the foreground and background of the fluid have clear boundaries, the depth image of the particles is first sampled, and then bilateral filtering is used to smooth the areas where the difference in depth values is less than a set threshold, thereby preserving the boundaries between the foreground and background of the fluid image.
[0113] Step 3: Render the fluid realistically based on the smooth fluid surface image and the scene's frame buffer;
[0114] Step 3.1: Color the fluid surface based on depth buffer and color buffer;
[0115] First, the fluid thickness is calculated based on the interpolation between the fluid depth image and the original depth buffer of the scene;
[0116] Since light is gradually absorbed by the fluid as it propagates, it is necessary to use incident light color that is attenuated to different degrees depending on the thickness of the fluid to obtain the fluid's base color.
[0117] Then, based on the fluid's opacity, the fluid's base color is superimposed with the scene color in the color buffer to obtain the color of the fluid's surface;
[0118] Step 3.2: To enhance the realism of the fluid, it is also necessary to render the effect of floating bubbles on the fluid. When performing fluid simulation, particles with fewer than a set threshold of neighboring particles are marked as foam particles, and then the foam particle image is obtained through screen space mapping. During shading rendering, the foam particle image is sampled, and the fluid surface color is mixed with the foam color according to the sampling results.
[0119] Step 3.3, Caustic Effect Rendering; Caustic effect refers to the phenomenon where strong light rays, when shining on a transparent object, refract and form a focused beam. During scene depth buffer sampling, world coordinates corresponding to screen space coordinates are obtained through matrix transformation. The x and y components of the world coordinates are then used as UV space coordinates to sample the pre-baked caustic map. The sampled colors are added to the sampling results of the scene color buffer to obtain an approximate caustic effect. Multiple caustic maps are cyclically sampled over time as the system runs, allowing the caustic effect to be displayed dynamically.
[0120] In this embodiment, fluid simulation is implemented in the Unity High Precision Rendering Pipeline (HDRP) based on the method of this invention. The specific implementation results are as follows:
[0121] 1) Implementation of PBF particle simulation based on Compute Shader
[0122] In this embodiment, a general-purpose computational shader was used to implement PBF fluid simulation on a GPU, and the simulation results are as follows. Figure 6 As shown.
[0123] GPUs possess massively parallel computing capabilities far superior to CPUs. Therefore, in this embodiment, PBF fluid simulation calculations can be performed on a GPU with extremely high efficiency. In this embodiment, the simulation of the motion of 70,000 fluid particles can still be completed at a rate of 60 frames per second.
[0124] 2) Implementation of Screen Space Fluid Surface Reconstruction
[0125] Leveraging Unity's programmable pipeline, additional rendering batches can be added to obtain information such as the position and normals of fluid particles. Smoothing using a bidirectional filtering algorithm results in a smooth fluid surface, achieving an effect like... Figure 7 As shown.
[0126] 3) Implementation of realistic fluid rendering
[0127] This embodiment uses a custom shader to perform realistic rendering based on fluid information in screen space and lighting information in the scene, resulting in a water effect as shown below. Figure 8 As shown.
[0128] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention, and not to limit them; although the present invention has been described in detail with reference to the foregoing embodiments, those skilled in the art should understand that modifications can still be made to the technical solutions described in the foregoing embodiments, or equivalent substitutions can be made to some or all of the technical features therein; and these modifications or substitutions do not cause the essence of the corresponding technical solutions to deviate from the scope defined by the claims of the present invention.
Claims
1. A GPU fluid simulation method for real-time interactive applications, characterized in that: On the GPU side, a large number of particles are emitted using a particle system, and a position-based fluid particle simulation algorithm is used to calculate the positions of the fluid particles and update their motion states. Specifically, this includes the following steps: Step 1.1: Use a particle system to launch a large number of particles in the fluid simulation space, and divide the fluid simulation space into several three-dimensional grid regions to construct a neighboring particle search grid. When updating the position of fluid particles, the particle index is written to the corresponding grid. When it is necessary to query the neighboring particles of a certain particle, the grid where the particle is located can be calculated based on the particle coordinates in linear time. Then, it is only necessary to traverse the particles in that grid to obtain all particles within a certain range. Step 1.2: Calculate the effects of gravity and collision on the particles; Step 1.3: Calculate the interaction between particles inside the fluid and calculate the displacement vector of the particles based on the incompressible constraint; Step 1.4: Add the displacement of the particle caused by the external force obtained in Step 1.2 to the displacement caused by the interaction between particles obtained in Step 1.3 to obtain the particle's position change; add the particle's position change to the particle's original position to obtain the particle's new position; at the same time, divide the particle's position change by the unit time to obtain the particle's velocity at that moment, which is used to calculate the influence of the external force on the particle in the next round of particle position update. A smooth fluid surface is obtained by processing the screen space based on the particle position; The surface of the fluid is colored using realistic rendering techniques to obtain an image of the water body.
2. The GPU fluid simulation method for real-time interactive applications according to claim 1, characterized in that: The GPU fluid simulation method for real-time interactive applications includes the following steps: Step 1: Use a particle system to emit a large number of particles, and then use a position-based fluid particle simulation algorithm to update the positions of the fluid particles, thus completing the update of the particle motion state; Step 2: After updating the particle motion state, use screen space to reconstruct the fluid surface; Step 2.1: Map all fluid particles from the three-dimensional world space to the two-dimensional screen space to obtain the fluid surface image mapped to the two-dimensional screen space; Step 2.2: Smooth the fluid surface image mapped to the two-dimensional screen space to obtain a smoothed fluid surface image; Step 3: Render the fluid realistically based on the smooth fluid surface image and the scene's frame buffer; Step 3.1: Color the fluid surface based on depth buffer and color buffer; Step 3.2: Render the effect of bubbles floating on the fluid; Step 3.3: Rendering the caustic effect.
3. The GPU fluid simulation method for real-time interactive applications according to claim 1, characterized in that: The effect of gravity on particles in step 1.2 is shown in the following formula: ; in, The positional influence component of gravity. The particle's current velocity. The interval between two updates. It is the acceleration due to gravity; The impact of collisions on particles is determined using the depth field of the virtual scene, specifically: The depth field of the virtual scene is sampled using particle coordinates to obtain the distance from the particle to the nearest surface in the scene. If the particle is inside the surface or the distance from the particle to the surface is less than a pre-defined particle radius, it indicates that the particle has collided and collision calculation is required. In the position-based fluid particle simulation algorithm, the collision calculation does not require calculating the force of the collision, but only needs to analyze different situations: when the particle is inside the surface, the new position of the particle is the collision position plus the direction from the particle to the collision position multiplied by the particle radius; when the distance between the particle and the surface is less than a pre-defined particle radius, the new position of the particle is the collision position plus the direction from the collision position to the particle center multiplied by the particle radius.
4. The GPU fluid simulation method for real-time interactive applications according to claim 3, characterized in that: The specific method for step 1.3 is as follows: First, iterate through all particles within a distance h around the currently computed particle i, and calculate the kernel function based on the distances between the particles. The value of is shown in the following formula: ; in, Here, r is the kernel function, r is the distance vector from other particles to particle i, and h is the preset maximum search distance; Then, iterate through all particles within a distance h around particle i and calculate the density at the location of particle i. As shown in the formula below: ; in, Let the mass of particle j be within a distance h around particle i. To calculate the current position of particle i, Let h be the position of particle j within a distance h around particle i; Because liquids are incompressible, it is necessary to ensure that the density of each particle i is the same as the static density of the fluid; for the current particle i being calculated, the following definition is used: Its density constraint is shown in the following formula: ; in, This represents the position of particle i and the positions of its neighboring particles. This is the density at the current particle location calculated in the previous step. The density of the fluid in a static state; Then calculate the Lagrange multipliers corresponding to particle i. : ; in, It is a relaxation parameter. Density constraint for the i-th particle In position The gradient with respect to position; Then, the displacement vector of particle i after passing through its own density constraints and the density constraints of its neighboring particles is obtained. : ; in, Let be the Lagrange multiplier corresponding to particle j; in, In order to perform density constraints In position The Spiky kernel function used for gradient calculation with respect to position is shown in the following formula: ; right Differentiating with respect to r, we get: ; Assuming all particles in the fluid have the same mass, we can further obtain: ; but Regarding location gradient As shown in the formula below: ; in, ; Depending on the value of k, They are respectively: 。 5. The GPU fluid simulation method for real-time interactive applications according to claim 2, characterized in that: Step 2.1 involves multiplying the perspective projection matrix M of the virtual camera with the homogeneous coordinates of the three-dimensional world space of the fluid particles to obtain the two-dimensional coordinates of the fluid particles in the screen space, thereby obtaining the fluid surface image mapped to the two-dimensional screen space.
6. The GPU fluid simulation method for real-time interactive applications according to claim 2, characterized in that: Step 2.2 first samples the depth image of the particles, then uses bilateral filtering to smooth the regions where the difference in depth values is less than a set threshold, preserving the boundaries between the foreground and background of the fluid image, thereby obtaining a smooth fluid surface image.
7. The GPU fluid simulation method for real-time interactive applications according to claim 2, characterized in that: The specific method for step 3.1 is as follows: First, the fluid thickness is calculated based on the interpolation between the fluid depth image and the original depth buffer of the scene; The basic color of the fluid is obtained by attenuating the incident light color to different degrees according to the fluid thickness. Then, based on the fluid's opacity, the fluid's base color is superimposed with the scene color in the color buffer to obtain the color of the fluid's surface.
8. The GPU fluid simulation method for real-time interactive applications according to claim 7, characterized in that: The specific method for step 3.2 is as follows: During fluid simulation, particles with fewer than a set threshold of neighboring particles are marked as foam particles, and then foam particle images are obtained through screen space mapping; during shading rendering, the foam particle images are sampled, and the fluid surface color is mixed with the foam color based on the sampling results.
9. A GPU fluid simulation method for real-time interactive applications according to claim 8, characterized in that: The specific method for step 3.3 is as follows: When sampling the scene depth buffer, the world coordinates corresponding to the screen space coordinates are obtained through matrix transformation. The x and y components of the world coordinates are used as coordinates in the UV space to sample the pre-baked caustic map. The sampled color is added to the sampling result of the scene color buffer to obtain the caustic effect. Multiple caustic maps are sampled in a loop to make the caustic effect dynamically displayed.
Citation Information
Patent Citations
Method for drawing surface of SPH (smoothed particle hydrodynamics) fluid in real time on basis of screen spaces
CN103679802A
Surface rendering method and system of dynamic particle set
CN107248188A