CN115906703A - GPU fluid simulation method for real-time interactive application - Google Patents

GPU fluid simulation method for real-time interactive application Download PDF

Info

Publication number
CN115906703A
CN115906703A CN202211547040.9A CN202211547040A CN115906703A CN 115906703 A CN115906703 A CN 115906703A CN 202211547040 A CN202211547040 A CN 202211547040A CN 115906703 A CN115906703 A CN 115906703A
Authority
CN
China
Prior art keywords
particle
fluid
particles
gpu
real
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Pending
Application number
CN202211547040.9A
Other languages
Chinese (zh)
Inventor
高天寒
陈鑫
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Northeastern University China
Original Assignee
Northeastern University China
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Northeastern University China filed Critical Northeastern University China
Priority to CN202211547040.9A priority Critical patent/CN115906703A/en
Publication of CN115906703A publication Critical patent/CN115906703A/en
Pending legal-status Critical Current

Links

Images

Landscapes

  • Management, Administration, Business Operations System, And Electronic Commerce (AREA)

Abstract

The invention provides a GPU fluid simulation method for real-time interactive application, and relates to the technical field of fluid simulation. The method comprises the steps of firstly, emitting a large number of particles by using a particle system, calculating the positions of the fluid particles by using a position-based fluid particle simulation algorithm, updating the motion state of the particles, obtaining the surface of a smooth fluid by screen space processing according to the positions of the particles, and finally coloring the surface of the fluid by using a realistic rendering mode to obtain a water body image; since the state updating of a large number of particles and the pixel-level calculation of the screen space are both large-scale parallel calculation and are suitable for GPU processing, all calculation processes related to the method run at the GPU end. The method can be widely applied to various demand scenes in the fields of industrial simulation and electronic games.

Description

GPU fluid simulation method for real-time interactive application
Technical Field
The invention relates to the technical field of fluid simulation, in particular to a GPU fluid simulation method for real-time interactive application.
Background
With the development of fluid simulation technology, realistic real-time fluid animation simulation has been widely applied to commercial movies, large games and urban disaster prediction systems, wherein stable and accurate numerical solution models and high computational efficiency are always important contents in research.
In real-time applications, since analog simulation is very sensitive to computational power consumption, there are three common fluid analog simulation solutions: the method is characterized in that a two-dimensional image sequence or a three-dimensional model sequence of off-line baking is used, and the change effect of the fluid is realized in a circulating playing mode. This method is typically simulated using a gridless method, with Smooth Particle Hydrodynamics (SPH) being the most popular method for simulating fluids because it is computationally simpler and more efficient than other methods. However, the conversion of the simulated particles into three-dimensional models that can be used for rendering still requires a lot of computation, and at present, screen space technology is mainly used to generate polygonal meshes or Marching cubes (Marching Cube) from the particle data. Since no one instance of a mesh generation method is computationally expensive.
Secondly, a particle system is used for emitting a large number of particles, and the approximate fluid effect is realized by adjusting the speed and the size of the particles and calculating the external forces such as gravity, collision and the like. In recent years, with the improvement of computer computing power, especially the popularization of general-purpose computing technology of the GPU, the GPU which is originally only used for image rendering and is skilled in large-scale parallel computing can participate in particle computing, the particle number and the complexity of particle motion rules which can be maintained by a particle system are greatly expanded, and a foundation is provided for real-time fluid particle simulation.
And thirdly, real-time plane fluid simulation based on a two-dimensional grid. The simulation mode based on the grid can better simulate the fluid motion in a two-dimensional plane. Because the two-dimensional space and the three-dimensional space have dimension difference, the calculation scale of the method is obviously reduced compared with that of three-dimensional space simulation, so that real-time fluid settlement can be realized, and the interaction requirement is met. The two-dimensional density image obtained by settlement can also be rendered by using a ray stepping (RayMarching) method to obtain a pseudo three-dimensional visual effect.
Although the off-line baking-based method can achieve a fluid effect with higher accuracy, a large amount of pre-baking data is required, and the fluid cannot interact with dynamic objects in the scene; the fluid effect can be efficiently realized by using a simple particle emitter, but no physical simulation exists and the visual effect is poor; the two-dimensional fluid real-time calculation method based on the grid can realize an interactive fluid effect, but is limited to planar fluid scenes such as water surface and ground, and fluid in a three-dimensional space cannot be simulated.
Disclosure of Invention
The technical problem to be solved by the present invention is to provide a GPU fluid simulation method for real-time interactive application to realize animation simulation of fluid, aiming at the deficiencies of the prior art.
In order to solve the technical problems, the technical scheme adopted by the invention is as follows: a GPU fluid simulation method for real-time interactive application is characterized in that calculation processes are all operated at a GPU end, a particle system is used for emitting a large number of particles, the positions of the fluid particles are calculated by using a position-based fluid particle simulation algorithm, the motion states of the particles are updated, the smooth fluid surface is obtained through screen space processing according to the positions of the particles, and finally the fluid surface is colored in a realistic rendering mode to obtain a water body image; the method specifically comprises the following steps:
step 1, a particle system is used for emitting a large number of particles, and then a fluid particle simulation algorithm based on positions is used for updating the positions of the fluid particles so as to finish the updating of the motion state of the particles;
step 1.1, using a particle system to emit a large number of particles in a fluid simulation space, uniformly dividing the fluid simulation space into a plurality of three-dimensional grid areas, and constructing a near particle search grid;
when the positions of the fluid particles are updated, writing the indexes of the particles into the corresponding grids; when a particle adjacent to a certain particle needs to be inquired, a grid where the particle is located can be obtained in linear time according to the particle coordinates, and then all the particles in a certain range can be obtained only by traversing the particles in the grid;
step 1.2, calculating the influence of two external forces of gravity and collision on the particles; wherein, the influence of gravity on the particles is shown as the following formula:
Figure BDA0003980473090000021
wherein, Δ p g For the position-influencing component of gravity, v 0 The current speed of the particles is delta t, the interval time between two updates is delta t, and g is the gravity acceleration;
the impact of the collision on the particle is determined by a depth field of the virtual scene, specifically:
sampling a depth field of a virtual scene by using particle coordinates to obtain the distance from a particle to the nearest surface in the scene; if the particle is in the surface or the distance between the particle and the surface is less than the preset particle radius, the particle is collided, and collision calculation is needed; in the position-based fluid particle simulation algorithm, the calculation of the collision does not need to calculate the stress condition of the collision, and only needs to analyze for different conditions: when the particle is within the surface, the new position of the particle is the collision position plus the direction of the particle to the collision position multiplied by the particle radius; when the distance between the particle and the surface is smaller than the preset particle radius, the new position of the particle is the collision position plus the product of the direction from the collision position to the center of the particle and the particle radius;
step 1.3, calculating the interaction among particles in the fluid, and calculating the displacement vector delta p of the particles according to incompressible constraint;
firstly, traversing all particles in the h distance around the current calculation particle i, and calculating a kernel function W based on the distance between the particles Poly6 The value of (c) is shown in the following formula:
Figure BDA0003980473090000022
wherein, W Poly6 (r, h) is a kernel function, r is a distance vector from other particles to the particle i, and h is a preset maximum search distance;
traversing all the particles in the distance h around the particle i, and calculating the density rho of the position of the particle i i The following formula shows:
Figure BDA0003980473090000031
wherein m is j Is the mass of particle j within a distance h around particle i; p is a radical of formula i For the current calculation of the position, p, of the particle i j Is the position of particle j within a distance h around particle i;
since the liquid is 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 calculation particle i, define C i For its density constraint, the following equation is shown:
Figure BDA0003980473090000032
wherein p is 1 ,…,p n Denotes the position of the particle i and the positions of its neighbors, ρ i The density, rho, of the current particle position calculated for the previous step 0 Is the density of the fluid at rest;
then calculating corresponding Lagrange multiplier lambda of the particle i i
Figure BDA0003980473090000033
Wherein e is a relaxation parameter,
Figure BDA0003980473090000034
constraining C for the density of the ith particle i At position p k A gradient with respect to position;
further, the displacement vector delta p obtained after the particle i is subjected to self density constraint and neighbor particle density constraint is solved i
Figure BDA0003980473090000035
Wherein λ is j A Lagrange multiplier corresponding to the particle j;
wherein, W Spiky (r, h) is under density constraint C i At position p k The Spiky kernel function used in the calculation of the gradient with respect to position is shown in the following formula:
Figure BDA0003980473090000041
to W Spiky (r, h) deriving r as:
Figure BDA0003980473090000042
setting the mass of all particles in the fluid to be the same, further:
Figure BDA0003980473090000043
then C is i With respect to position p k Gradient of gradient
Figure BDA0003980473090000044
As shown in the following equation: />
Figure BDA0003980473090000045
Wherein k belongs to 1, …, n;
aiming at the difference of the values of k,
Figure BDA0003980473090000046
respectively as follows:
Figure BDA0003980473090000047
step 1.4, adding the displacement generated by the particles influenced by the external force and obtained in the step 1.2 and the displacement generated by the interaction between the particles obtained in the step 1.3 to obtain the position variation delta p of the particles; adding the position variation delta p of the particles and the original positions of the particles to obtain new positions of the particles; meanwhile, the speed of the particles at the moment is obtained by dividing the position variation delta p of the particles by the unit time delta t, and the speed is used for calculating the influence of the external force on the particles during the next round of particle position updating;
step 2, after the updating of the particle motion state is completed, adopting a screen space to reconstruct the surface of the fluid;
step 2.1, mapping all fluid particles from a three-dimensional world space to a two-dimensional screen space;
multiplying a perspective projection matrix M of the virtual camera with the three-dimensional world space homogeneous coordinates of the fluid particles to obtain two-dimensional coordinates of the fluid particles in a screen space, and obtaining a fluid surface image mapped to the two-dimensional screen space;
step 2.2, smoothing the fluid surface image mapped to the two-dimensional screen space to obtain a smooth fluid surface image;
firstly, sampling a depth image of particles, and smoothing an area with a difference value of depth values smaller than a set threshold value by using bilateral filtering, so as to keep a boundary of a foreground background of a fluid image;
step 3, performing realistic rendering of the fluid according to the smooth fluid surface image and the frame buffer of the scene;
step 3.1, coloring the surface of the fluid based on depth buffering and color buffering;
firstly, calculating the thickness of the fluid according to the depth image of the fluid and the interpolation value of the original depth buffer of the scene;
then, attenuating the incident light color to different degrees according to different thicknesses of the fluid to obtain the basic color of the fluid;
then, according to the opacity of the fluid, the basic color of the fluid is superposed with the scene color in the color buffer to obtain the color of the surface of the fluid;
step 3.2, rendering the effect of floating foam on the fluid; marking the particles with the quantity of the adjacent particles less than a set threshold value as foam particles during fluid simulation, and obtaining a foam particle image through screen space mapping; sampling the foam particle image during coloring and rendering, and mixing the fluid surface color with the foam color according to the sampling result;
step 3.3, rendering the caustic effect; when the scene depth buffering sampling is carried out, a world coordinate corresponding to a screen space coordinate is obtained through matrix transformation, x and y direction components of the coordinate of the world coordinate are taken as coordinates of a UV space, the prebaked caustic mapping is sampled, and the sampled color is added with the sampling result of the scene color buffering to obtain a caustic effect; and circularly sampling the multiple scorching and scattering maps to dynamically display the scorching and scattering effects.
Adopt the produced beneficial effect of above-mentioned technical scheme to lie in: the GPU fluid simulation method for real-time interactive application, provided by the invention, comprises the steps of using a fluid simulation algorithm based on positions, and compared with the traditional simulation algorithm, the fluid simulation method has the advantages of high simulation efficiency, strong stability and the like; by using a screen space fluid surface reconstruction method, a smooth fluid surface image can be efficiently obtained; the frame buffer memory is used for realizing water body effects such as refraction and reflection, and the like, and fluid effects such as foam caustic are used for enhancing the reality of rendering. The method provided by the invention is used as an efficient physical simulation real-time fluid simulation method, and can be widely applied to various demand scenes in the fields of industrial simulation and electronic games.
Drawings
FIG. 1 is a flowchart of a GPU fluid simulation method for real-time interactive applications according to an embodiment of the present invention;
FIG. 2 is a flow chart of a position-based fluid particle simulation algorithm for updating fluid particle positions according to an embodiment of the present invention;
FIG. 3 is a schematic diagram of a deep collision based approach provided by an embodiment of the present invention in which (a) the particles are within the surface and (b) the particles are near the surface but still outside the surface;
FIG. 4 is a diagram illustrating a screen mapping according to an embodiment of the present invention;
FIG. 5 is a depth image of fluid particles provided by an embodiment of the present invention;
FIG. 6 is a diagram illustrating an implementation of a particle simulation algorithm according to an embodiment of the present invention
FIG. 7 is a realistic rendering water effect diagram provided by an embodiment of the invention;
fig. 8 is a diagram of a reconstructed smooth fluid surface provided by an embodiment of the invention.
Detailed Description
The following detailed description of embodiments of the present invention is provided in connection with the accompanying drawings and examples. The following examples are intended to illustrate the invention but are not intended to limit the scope of the invention.
In the embodiment, all calculation processes are operated at a GPU end, a particle system is used for emitting a large number of particles, the positions of the fluid particles are calculated by using a position-based fluid particle simulation algorithm, the motion states of the particles are updated, the smooth fluid surface is obtained through screen space processing according to the positions of the particles, and finally the fluid surface is colored in a realistic rendering mode to obtain a fluid image; since the state updating of a large number of particles and the pixel-level calculation of the screen space are both large-scale parallel calculation and are very suitable for GPU processing, all the calculation processes involved in the method are operated at the GPU end.
As shown in fig. 1, the method specifically includes the following steps:
step 1, emitting a large number of particles by using a particle system, and updating positions of fluid particles by using a Position based fluid particle simulation (PBF) algorithm to complete updating of motion states of the particles, as shown in fig. 2, specifically including the following steps:
step 1.1, a particle system is used for emitting a large number of particles in a fluid simulation space, the fluid simulation space is uniformly divided into a plurality of three-dimensional grid areas, and a near particle search grid is constructed;
when the particle constraint is calculated, the positions of all particles within a certain distance around the particle constraint need to be acquired, if all the particles are traversed for searching, a large amount of computing resources need to be consumed, and the real-time performance cannot be guaranteed, so that the acceleration needs to be performed by using a uniform grid hash structure. When the positions of the fluid particles are updated, writing the indexes of the particles into the corresponding grids; when the adjacent particles of a certain particle need to be inquired, the grids are uniformly divided, so that the grids where the particles are located can be obtained in linear time according to the particle coordinates, and then most particles in a certain range can be obtained only by traversing the particles in the grids; although the method can not ensure that all the adjacent particles are obtained, the method can rapidly complete the search work of the adjacent particles because the calculation amount is obviously reduced and the method is very suitable for GPU parallel calculation.
Step 1.2, calculating the influence of two external forces of gravity and collision on the particles; wherein, the influence of gravity on the particles is shown as the following formula:
Figure BDA0003980473090000061
wherein, Δ p g For the position-influencing component of gravity, v 0 Setting the current speed of the particles, setting delta t as the interval time between two updates, and setting g as the gravity acceleration;
in the traditional fluid simulation field, collision of fluid and scene objects relates to a large amount of intersection calculation, so that the efficiency is low, and the method is not suitable for real-time simulation. In modern real-time game engines, a depth field is typically maintained. The depth field is obtained by pre-calculation, in which the distance of each location in space to the nearest surface is preserved. The collision calculation can be conveniently completed by utilizing the depth field.
The impact of the collision on the particle is determined by a depth field of the virtual scene, specifically:
sampling a depth field of a virtual scene (namely the environment where the fluid is located) by using the particle coordinates to obtain the distance from the particle to the nearest surface in the scene; if the particle is in the surface or the distance between the particle and the surface is less than the preset particle radius, the particle is collided, and collision calculation is needed; in the position-based fluid particle simulation algorithm, the calculation of the collision does not need to calculate the stress condition of the collision, and only needs to be analyzed for different conditions, as shown in fig. 3: when the particle is within the surface, the new position of the particle is the collision position plus the direction of the particle to the collision position times the particle radius; when the distance between the particle and the surface is smaller than the given particle radius (namely, the distance is close to the surface but still outside the surface), the new position of the particle is the collision position plus the direction from the collision position to the center of the particle multiplied by the particle radius; in this way it is ensured that the new positions of the particles do not collide.
Step 1.3, calculating interaction among particles in the fluid, and calculating a displacement vector delta p of the particles according to incompressible constraint;
firstly, traversing all particles in the h distance around the current calculation particle i, and calculating a kernel function W based on the distance between the particles Poly6 The value of (c) is shown by the following formula:
Figure BDA0003980473090000071
wherein, W Poly6 (r, h) is a kernel function, r is a distance vector from other particles to the particle i, and h is a preset maximum search distance;
traversing all the particles in the distance h around the particle i, and calculating the density rho of the position of the particle i i The following formula shows:
Figure BDA0003980473090000073
wherein m is j Is the mass of particle j within a distance h around particle i; p is a radical of i For the current calculation of the position, p, of the particle i j Is the position of particle j within a distance h around particle i;
since the liquid is 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 calculation particle i, define C i For its density constraint, the following equation is shown:
Figure BDA0003980473090000074
wherein p is 1 ,…,p n Denotes the position of the particle i and the positions of its neighbors, ρ i The density, rho, of the current particle position calculated for the previous step 0 The density in a static state of the fluid is a constant set by a user;
then calculating corresponding Lagrange multiplier lambda of the particle i i
Figure BDA0003980473090000075
Wherein, the epsilon is a relaxation parameter for avoiding the introduction of the zero-removing problem and is set by a user;
Figure BDA0003980473090000076
constraining C for the density of the ith particle i At position p k A gradient with respect to position;
further, the displacement vector delta p obtained after the particle i is subjected to self density constraint and neighbor particle density constraint is solved i
Figure BDA0003980473090000081
Wherein λ is j A Lagrange multiplier corresponding to the particle j;
wherein, W Spiky (r, h) is under density constraint C i At position p k The Spiky kernel function used in the calculation of the gradient with respect to position is shown in the following formula:
Figure BDA0003980473090000082
to W Spiky (r, h) deriving r as:
Figure BDA0003980473090000083
setting the mass of all particles in the fluid to be the same, further obtaining:
Figure BDA0003980473090000084
then C is i With respect to position p k Gradient of gradient
Figure BDA0003980473090000085
As shown in the following equation:
Figure BDA0003980473090000086
wherein k belongs to 1, …, n;
aiming at the difference of the values of k,
Figure BDA0003980473090000087
respectively as follows:
Figure BDA0003980473090000088
step 1.4, adding the displacement generated by the particles affected by the external force obtained in the step 1.2 and the displacement generated by the interaction between the particles obtained in the step 1.3 to obtain the position variation delta p of the particles; adding the position variation delta p of the particles and the original positions of the particles to obtain new positions of the particles; meanwhile, the speed of the particles at the moment is obtained by dividing the position variation quantity delta p of the particles by the unit time delta t, and the speed is used for calculating the influence of the external force on the particles during the next round of particle position updating;
step 2, after the updating of the particle motion state is finished, adopting a screen space to rebuild the surface of the fluid; since constructing a three-dimensional model from particles requires a lot of computational effort, it is difficult to implement in real-time applications, so screen space is used for fluid surface reconstruction. The method comprises the following two steps:
step 2.1, mapping all fluid particles from a three-dimensional world space to a two-dimensional screen space, as shown in fig. 4; particles in a three-dimensional space cannot be directly filtered to obtain a fluid surface, so that the particles need to be mapped to a two-dimensional screen space; firstly, a camera perspective projection matrix M is calculated according to the virtual camera parameters:
Figure BDA0003980473090000091
wherein aspect is the aspect ratio of the clipping plane of the camera, α is the Field angle (Field of view) of the camera, nerz is the distance from the camera to the clipping plane, and FarZ is the distance from the camera to the far clipping plane;
then multiplying a perspective projection matrix M of the virtual camera with the three-dimensional world space homogeneous coordinates of the fluid particles to obtain two-dimensional coordinates of the fluid particles in a screen space, and obtaining a fluid surface image mapped to the two-dimensional screen space;
step 2.2, smoothing the fluid surface image mapped to the two-dimensional screen space to obtain a smooth fluid surface image;
since the fluid surface image mapped from world space to screen space is granular, it cannot be directly used for rendering. Smoothing by filtering is therefore required. Depth images of fluid particles the light and dark of each pixel in the image represents a depth value, i.e. the distance of the position from the camera, as shown in fig. 5. In order to ensure that the fluid foreground background has a definite boundary, firstly sampling the depth image of the particles, then smoothing the region of which the difference value of the depth values is smaller than a set threshold value by using bilateral filtering, and thus reserving the boundary of the fluid image foreground background;
step 3, performing realistic rendering of the fluid according to the smooth fluid surface image and the frame buffer of the scene;
step 3.1, coloring the surface of the fluid based on depth buffering and color buffering;
firstly, calculating the thickness of the fluid according to the depth image of the fluid and the interpolation value of the original depth buffer of the scene;
because light is gradually absorbed by fluid during propagation, the incident light color needs to be attenuated to different degrees according to different thicknesses of the fluid to obtain the basic color of the fluid;
then, according to the opacity of the fluid, superposing the basic color of the fluid and the scene color in the color buffer to obtain the color of the surface of the fluid;
step 3.2, in order to enhance the reality of the fluid, the effect of floating foam on the fluid is required to be rendered; when fluid simulation is carried out, marking the particles with the quantity of the adjacent particles less than a set threshold value as foam particles, and then obtaining a foam particle image through screen space mapping; sampling the foam particle image during coloring and rendering, and mixing the surface color of the fluid with the foam color according to the sampling result;
step 3.3, rendering the caustic effect; the caustic phenomenon is that when strong light is irradiated to a transparent object, light is condensed by refraction. When the scene depth buffering sampling is carried out, a world coordinate corresponding to a screen space coordinate is obtained through matrix transformation, x and y direction components of the coordinate of the world coordinate are taken as coordinates of a UV space, the prebaked caustic mapping is sampled, and the sampled color is added with the sampling result of the scene color buffering to obtain an approximate caustic effect; and circularly sampling a plurality of caustic patches along with the running time of the system, so that the caustic effect is dynamically displayed.
In this embodiment, the fluid simulation is implemented in a Unity high precision rendering pipeline (HDRP) based on the method of the present invention, and the specific implementation result is as follows:
1) Implementation of computer Shader-based PBF particle simulation
In this embodiment, a general-purpose compute shader is used to implement PBF fluid simulation on a GPU, and the simulation result is shown in fig. 6.
The large-scale parallel computing capability of the GPU is far stronger than that of the CPU, so in the embodiment, the PBF fluid simulation computation can be completed on the GPU with very high efficiency. In this embodiment, the motion of seventy thousand fluid particles is simulated simultaneously, yet the calculations can be done at a rate of 60 frames per second.
2) Implementation of screen space fluid surface reconstruction
Based on the characteristics of the Unity programmable pipeline, by adding additional rendering batches, information of the position, the normal line and the like of the fluid particle can be acquired. Smoothing by a bi-directional filtering algorithm can obtain a smooth fluid surface, and the implementation effect is shown in fig. 7.
3) Realisation of realistic fluid rendering
In this embodiment, based on the fluid information in the screen space and the light information in the scene, a customized shader is used to perform photorealistic rendering, and the final obtained water body effect is as shown in fig. 8.
Finally, it should be noted that: the above examples are only intended to illustrate the technical solution of the present invention, but not to limit it; although the present invention has been described in detail with reference to the foregoing embodiments, it should be understood by those of ordinary skill in the art that: the technical solutions described in the foregoing embodiments may still be modified, or some or all of the technical features may be equivalently replaced; such modifications and substitutions do not depart from the spirit of the corresponding technical solutions and scope of the present invention as defined in the appended claims.

Claims (10)

1. A GPU fluid simulation method for real-time interactive application is characterized by comprising the following steps:
at the GPU end, a particle system is used for emitting a large number of particles, the positions of the fluid particles are calculated by using a fluid particle simulation algorithm based on the positions, and the motion states of the particles are updated;
obtaining a smooth fluid surface through screen space processing according to the positions of the particles;
and coloring the fluid surface by using a realistic rendering mode to obtain a water body image.
2. A GPU fluid simulation method for real-time interactive applications according to claim 1, characterized by: the GPU fluid simulation method for the real-time interactive application comprises the following steps:
step 1, a particle system is used for emitting a large number of particles, and then a fluid particle simulation algorithm based on positions is used for updating the positions of the fluid particles so as to finish the updating of the motion state of the particles;
step 2, after the updating of the particle motion state is completed, adopting a screen space to reconstruct the surface of the fluid;
step 2.1, mapping all fluid particles from a three-dimensional world space to a two-dimensional screen space to obtain a fluid surface image mapped to the two-dimensional screen space;
step 2.2, smoothing the fluid surface image mapped to the two-dimensional screen space to obtain a smooth fluid surface image;
step 3, performing realistic rendering of the fluid according to the smooth fluid surface image and the frame buffer of the scene;
step 3.1, coloring the surface of the fluid based on depth buffering and color buffering;
step 3.2, rendering the effect of floating foam on the fluid;
and 3.3, rendering the caustic effect.
3. A GPU fluid simulation method for real-time interactive applications according to claim 2, characterized by: the specific method of the step 1 comprises the following steps:
step 1.1, a particle system is used for emitting a large number of particles in a fluid simulation space, the fluid simulation space is uniformly divided into a plurality of three-dimensional grid areas, and a near particle search grid is constructed;
when the positions of the fluid particles are updated, writing the indexes of the particles into the corresponding grids; when a particle adjacent to a certain particle needs to be inquired, a grid where the particle is located can be obtained in linear time according to the particle coordinates, and then all the particles in a certain range can be obtained only by traversing the particles in the grid;
step 1.2, calculating the influence of two external forces of gravity and collision on the particles;
step 1.3, calculating the interaction among particles in the fluid, and calculating the displacement vector of the particles according to incompressible constraint;
step 1.4, adding the displacement generated by the particles affected by the external force obtained in the step 1.2 and the displacement generated by the interaction between the particles obtained in the step 1.3 to obtain the position variation of the particles; adding the position variation of the particles and the original positions of the particles to obtain new positions of the particles; and dividing the position variation of the particles by the unit time to obtain the speed of the particles at the moment, and using the speed to calculate the influence of the external force on the particles during the next round of particle position updating.
4. A GPU fluid simulation method for real time interactive applications according to claim 3, characterized by: the influence of gravity on the particles in step 1.2 is shown in the following formula:
Figure FDA0003980473080000021
wherein, Δ p g For the position-influencing component of gravity, v 0 Setting the current speed of the particles, setting delta t as the interval time between two updates, and setting g as the gravity acceleration;
the impact of the collision on the particle is determined by the depth field of the virtual scene, specifically:
sampling the depth field of the virtual scene by using the particle coordinates to obtain the distance from the particle to the nearest surface in the scene; if the particle is in the surface or the distance between the particle and the surface is less than the preset particle radius, the particle is collided, and collision calculation is needed; in the position-based fluid particle simulation algorithm, the calculation of the collision does not need to calculate the stress condition of the collision, and only needs to analyze for different conditions: when the particle is within the surface, the new position of the particle is the collision position plus the direction of the particle to the collision position times the particle radius; when the distance between the particle and the surface is smaller than the predetermined particle radius, the new position of the particle is the collision position plus the direction from the collision position to the center of the particle multiplied by the particle radius.
5. A GPU fluid simulation method for real-time interactive applications according to claim 4, characterized in that: the specific method of the step 1.3 comprises the following steps:
firstly, traversing all particles in the distance h around the current calculation particle i, and calculating a kernel function W based on the distance between the particles Poly6 The value of (A) is as followsThe following steps:
Figure FDA0003980473080000022
wherein, W Poly6 (r, h) is a kernel function, r is a distance vector from other particles to the particle i, and h is a preset maximum search distance;
traversing all the particles in the distance h around the particle i, and calculating the density rho of the position of the particle i i The following formula shows:
Figure FDA0003980473080000023
wherein m is j Is the mass of particle j within a distance h around particle i; p is a radical of i For the current calculation of the position, p, of the particle i j Is the position of particle j within a distance h around particle i;
since the liquid is 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 calculation particle i, define C i For its density constraint, the following equation is shown:
Figure FDA0003980473080000024
wherein p is 1 ,…,p n Denotes the position of the particle i and the positions of its neighbors, ρ i The density, rho, of the current particle position calculated in the previous step 0 Is the density of the fluid at rest;
then, the corresponding Lagrange multiplier lambda of the particle i is calculated i
Figure FDA0003980473080000031
Wherein e is a relaxation parameter,
Figure FDA0003980473080000032
constraining C for the density of the ith particle i At position p k A gradient with respect to position;
further, the displacement vector delta p obtained after the particle i is subjected to self density constraint and neighbor particle density constraint is solved i
Figure FDA0003980473080000033
Wherein λ is j A Lagrange multiplier corresponding to the particle j;
wherein, W Spiky (r, h) is in the process of density constraint C i At position p k The Spiky kernel used in the gradient calculation with respect to position is shown in the following equation:
Figure FDA0003980473080000034
to W Spiky (r, h) deriving r as:
Figure FDA0003980473080000035
setting the mass of all particles in the fluid to be the same, further:
Figure FDA0003980473080000036
then C is i With respect to position p k Gradient of gradient
Figure FDA0003980473080000037
As shown in the following equation:
Figure FDA0003980473080000038
wherein k belongs to 1, …, n;
the values for k are different from each other,
Figure FDA0003980473080000041
respectively as follows:
Figure FDA0003980473080000042
6. a GPU fluid simulation method for real-time interactive applications according to claim 2, characterized by: and 2.1, multiplying the perspective projection matrix M of the virtual camera with the three-dimensional world space homogeneous coordinates of the fluid particles to obtain two-dimensional coordinates of the fluid particles in a screen space, and further obtaining a fluid surface image mapped to the two-dimensional screen space.
7. A GPU fluid simulation method for real-time interactive applications according to claim 2, characterized by: and 2.2, firstly sampling the depth image of the particles, smoothing the region with the depth value difference smaller than a set threshold value by using bilateral filtering, and reserving the boundary of the foreground background of the fluid image so as to obtain a smooth fluid surface image.
8. A GPU fluid simulation method for real-time interactive applications according to claim 2, characterized by: the specific method of the step 3.1 comprises the following steps:
firstly, calculating the thickness of the fluid according to the depth image of the fluid and the interpolation value of the original depth buffer of the scene;
then, attenuating the incident light color to different degrees according to different thicknesses of the fluid to obtain the basic color of the fluid;
and then, according to the opacity of the fluid, the basic color of the fluid is superposed with the scene color in the color buffer to obtain the color of the surface of the fluid.
9. A GPU fluid simulation method for real-time interactive applications according to claim 8, characterized by: the specific method of the step 3.2 comprises the following steps:
marking the particles with the quantity of the adjacent particles less than a set threshold value as foam particles during fluid simulation, and obtaining a foam particle image through screen space mapping; sampling the foam particle image during coloring rendering, and mixing the fluid surface color with the foam color according to the sampling result.
10. A GPU fluid simulation method for real-time interactive applications according to claim 9, characterized by: the specific method of the step 3.3 is as follows:
when the scene depth buffering sampling is carried out, the world coordinate corresponding to the screen space coordinate is obtained through matrix transformation, the x and y direction components of the coordinate of the world coordinate are used as the coordinate of the UV space, the prebaked caustic mapping is sampled, and the sampled color and the sampling result of the scene color buffering are added to obtain the caustic effect; and circularly sampling a plurality of scorching and scattering maps to dynamically display the scorching and scattering effects.
CN202211547040.9A 2022-12-05 2022-12-05 GPU fluid simulation method for real-time interactive application Pending CN115906703A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202211547040.9A CN115906703A (en) 2022-12-05 2022-12-05 GPU fluid simulation method for real-time interactive application

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202211547040.9A CN115906703A (en) 2022-12-05 2022-12-05 GPU fluid simulation method for real-time interactive application

Publications (1)

Publication Number Publication Date
CN115906703A true CN115906703A (en) 2023-04-04

Family

ID=86470829

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202211547040.9A Pending CN115906703A (en) 2022-12-05 2022-12-05 GPU fluid simulation method for real-time interactive application

Country Status (1)

Country Link
CN (1) CN115906703A (en)

Cited By (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN117409127A (en) * 2023-12-15 2024-01-16 中国美术学院 Real-time ink fluid rendering method and device based on artificial intelligence
CN118334224A (en) * 2024-06-13 2024-07-12 山东捷瑞数字科技股份有限公司 Method for realizing dynamic simulation of fluid characteristics in three-dimensional pipeline based on shader

Cited By (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN117409127A (en) * 2023-12-15 2024-01-16 中国美术学院 Real-time ink fluid rendering method and device based on artificial intelligence
CN117409127B (en) * 2023-12-15 2024-04-05 中国美术学院 Real-time ink fluid rendering method and device based on artificial intelligence
CN118334224A (en) * 2024-06-13 2024-07-12 山东捷瑞数字科技股份有限公司 Method for realizing dynamic simulation of fluid characteristics in three-dimensional pipeline based on shader

Similar Documents

Publication Publication Date Title
US7586489B2 (en) Method of generating surface defined by boundary of three-dimensional point cloud
van der Laan et al. Screen space fluid rendering with curvature flow
Lagae et al. A survey of procedural noise functions
CA2506419C (en) Visible surface determination system & methodology in computer graphics using interval analysis
CN115906703A (en) GPU fluid simulation method for real-time interactive application
CN102402791B (en) Three-dimensional fluid simulation method based on graphic processing unit (GPU)
Ernst et al. Early split clipping for bounding volume hierarchies
CN103530907B (en) Complicated three-dimensional model drawing method based on images
CN102402792B (en) Real-time shallow water simulation method
CN102915559A (en) Real-time transparent object GPU (graphic processing unit) parallel generating method based on three-dimensional point cloud
CN109509243B (en) Liquid simulation method, liquid interaction method and device
CN111915710B (en) Building rendering method based on real-time rendering technology
CN110335275A (en) A kind of space-time vectorization method of the flow surface based on ternary biharmonic B-spline
CN106934192A (en) A kind of shallow water equations model water body modeling method of parameter optimization
Creus et al. R4: Realistic rain rendering in realtime
Vyatkin et al. Voxel Volumes volume-oriented visualization system
CN114676616A (en) Fluid wind field map rendering method in three-dimensional scene
CN106408639A (en) Curvature flow-based screen space fluid rendering method
Coutinho et al. Rain scene animation through particle systems and surface flow simulation by SPH
Nilsson 3D Cloud Visualization In Real-Time
Liu et al. Building a Real-Time System on GPUs for Simulation and Rendering of Realistic 3D Liquid in Video Games
Iwasaki et al. GPU-based rendering of point-sampled water surfaces
Klein et al. Simulation, Modelling and Rendering of Incompressible Fluids in Real Time.
Blinn et al. The simulation of natural phenomena (panel session)
Li Differentiable Visual Computing: Challenges and Opportunities

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination