Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Create an empty Scene named SSF_Test
Create a ParticleSystem
deactivate its Renderer
function
set its StartColor to red
Emission -> Rate over time to 1000
The Inspector should looks like
Add SSF_LoadParticlesFromParticleSystem
onto the GameObject Particle System
Note that you shall assign the Particle Systems field.
Enter playmode and you shall see
Different from prior version , the principle of this plugin is based on the paper A Narrow-Range Filter for Screen-Space Fluid Rendering.
Fluid simulation is generally based on grids or particles. In consideration of real-time performance, the SPH-based method (a particle-based method) is still used.
Unity does not have a very suitable fluid rendering plugin, which is the main reason for this plugin. I also noticed that there is indeed an very old implementation "Screen Space Fluids Pro"on the Asset Store (last update at year 2016).
In the process of using, I feel that I can do better, no matter from the efficiency or visual effects or ease of use and scalability, thus this plugin was born.
This page will tell you all need to know on the parameters to ajust the visual outlook.
You will notice that there are a set of parameters on the SSF_LoadParticlesFromParticleSystem
inspector:
The meaning of these parameters are as follows:
ParticleBufferUpdateInterval
The interval for updating particle data to GPU, <0 means update every frame. Adjust this value to your preferred visual frame rate
Thickness
The thickness of the liquid. The higher the value, the more precipitated and solid the color will be visually.
Noise
The detail turbulence of the surface. The higher the value, the more turbulence the surface will show. It is implemented by adding perturbation to the surface normal.
Render Params
Fluid surface rendering related parameters are listed separately below and may change with version iterations
IsTransparent
0 for traditional blinn-phong rendering, 1 for fluid rendering, value in-between means blending
Ior
Refractive Index of Fluid (1.33 for water...)
Smoothness
higher value for more smoothness
Fresnel Power
higher value gives more refraction
Min/Max Reflection Ratio
this constraints the amount of reflection, if no reflection is needed, just set them to 0, vice versa, 1 for no refraction
Ambient/Diffuse/Specular Color
Very traditional Blinn-phong model
Q: why my surface is sometimes black?
A:
Bake the scene lighting if you do not see reflection! Because the scripts needs the light reflection data. If not baked, the default reflection data is black.
Or else, you may pass in the particle color as black, or there's no lights in the scene.
Toggle on the "Debug visualize" on the Renderer Feature to check the output.
Switch the DebugTexture type to see different debug informations.
For anyone who wants to modify the shader to tweak the shading functionality, I will explain how the shading process works, though i personally not recommend.
The files used for fluid shading are in Assets/SSF_Particle2Fluid_ShaderUtil/Shaders/FluidRender.shader
The whole process can be divided into the following steps:
Read the surface parameters through the map:
We first filter out the pixels that are not blocked by the fluid particles and return them to the previously rendered color.
Based on the above parameters, you can play with the shader to create different effects.
For example, I first made a blinn-phong rendering
In addition, you can use parameters such as thickness, fluid color, IOR, smoothness, etc. to create water rendering effects that include refraction and reflection:
Of course, we can also implement shadow effects, but since Unity's API is not stable and open enough, we will consider updating it later.
Currently, there are two subclasses in the project that inherit from SSF_ParticleSource
, namely SSF_LoadParticlesFromParticleSystem
and SSF_LoadParticlesFromFile
. SSF_ParticleSource
represents the source of particle data required for rendering and is also the starting point for extension.
Considering that users may have their own source of particle data, such as a particle solution system running in parallel with the GPU, or imported pre-made particle data, here we will explain how to extend the input of particle data.
The structure of particle data in SSF is as follows:
If you modify the particle’s data structure, you need to pay attention to replacing 32 in
particleBuffer = new ComputeBuffer (getParticleNum (), 32);
in SSF_ParticleSource.cs with the number of bytes of particle data. At the same time, corresponding changes should be made inDepthColorThickness.shader
.
SSF_ParticleSource
The input and update of extended data is to create a new class inheriting from SSF_ParticleSource
and implement the corresponding virtual function.
The following two member variables exist in SSF_ParticleSource
:
Where particleBuffer
is used to provide data to generate related textures for rendering.
You can notice that the following member function modifiers in SSF_ParticleSource
are public virtual:
SetupParticleBufferData ()
UpdateParticleBufferData ()
In SetupParticleBufferData
, ParticlesData
needs to be created and assigned, and updated in UpdateParticleBufferData ()
, neither of these operations need to involve particleBuffer
.
UpdateBounds()
, the bounds is used for culling out of view particles, which saves a lot performance.You can also refer to SSF_LoadParticlesFromParticleSystem
, this is a bit complicated and tedious.
This is a Unity shader plugin, not a fluid physics simulation plugin. It is used to render particle data into a smooth liquid surface. Ideal for rendering simulation systems that use particles as simulation units.
Magic happens when the pure unity particle system gains power through this particle shader plugin.
It has huge changes compared to the previous version.
The newly adopted algorithm brings huge performance, performance, and user experience gains:
The number of iterations required for smoothing has been reduced from 150 to 3
The time required to run the algorithm Reduced (from 5.8ms to 0.5ms) nearly 10x times
Higher resolution and finer surface, with clear layers of water droplets and water surface
No param tuning anymore! Plane fitting parameters Reduced from 5 to 0
New Rendering process brings performance improvements in the following aspects
Required Smoothing + rendering Reduced from Per Fluid Surface Per Frame to Once Per Frame
Required RenderTextures Reduced from One Set for all RenderSurfaces to One Set Globally
The RenderTexture used is managed by the Rendergraph, further increasing potential bandwidth savings
Introduce new DebugVisualize functionality helps locate data problems or debug parameter effects
Added down sample option to further reduce bandwidth pressure
A unified rendering shader while supporting custom visual parameters for each ParticleSource.
Getting Started
Step by step
Parameters Tuning