Liquid - Foam
The creation of foam and spray from particle simulations is an often-used approach. RealFlow provides several common approaches to generate this type of fluid, e.g. Python scripting and RealFlow's “Graphs” system. In this example you will learn how to create foam particles from a turbulent fluid with the “Filter” daemon.
The result of the tutorial. The image has been rendered with RealFlow's implementation of Maxwell Render and the "MultiPoint" option to create more foam particles.
Nodes List
All scene elements can be added from RealFlow's "Standard - Particles", "Daemons", and "Objects" shelves:
- 1 “Cube” object
- 1 “Square” emitter
- 1 “Container” emitter
- 1 “Gravity” daemon
- 1 “k Volume” daemon
- 1 “Surface Tension” daemon
- 1 “Filter” daemon
The Setup
Add a cube object and rescale until you get a long basin. This node (“Cube01”) will hold the fluid.
Add a “Square” emitter and place it near one end of the cube.
A “Container” node will be used to store the foam particles.
Place a “k Volume” to delete (eventually) escaping particles.
“Gravity" introduces a force.
With a “Surface Tension” daemon the fluid looks more “liquid”, because it amplifies the particles' tendency to form drops.
Create a “Filter” daemon.
Adjusting the “Square01” Emitter
To get a sufficient amount of randomness and turbulence, some emitter parameters are animated. For this purpose we will use two basic expressions based on sine functions. These simple formulas will help to increase and decrease the parameters' values periodically, creating a randomized look.
Finally, a few more adjustments are necessary:
- Increase the number of emitted particles with Node Params > Particle > Resolution > 75.0
- Scale the emitter to create a rectangular shape (rough values are 0.5 and 2.0 for the horizontal values, and 1.0 for the vertical axes). Move the emitter upwards, but please make sure that it is not outside the “Cube01” object.
- Instead of a constant particle stream, a fixed volume is used in this scene. Enter a value greater than 0 under Node Params > Square > Volume. Click on “Reset” to see the volume. The parameter's value should be set to value so that the particles nearly touch the “Cube01” node's bottom.
- By default, the particles are emitted in a regular pattern. Add some randomness under Node Params > Square > V random (H random) > 1.0 (1.0)
- Node Params > Node > Color > choose a blue color
Adjusting the “Container01” Node
The “Container” node is not an emitter in a traditional sense. It is simply a place where particles can be added. With these particle-shifting methods you always have to make sure that the source emitter (here: “Circle01”) and the container have exactly the same “Resolution” values, because otherwise you will see exploding particles. Here are the settings:
- Node Params > Particles > Resolution > 75.0
- To make the foam float, change its density: Node Params > Particles > Density > 900.0
- Keep the foam particles closer together with Node Params > Particles > Int Pressure > 0.5
- Node Params > Node > Color > choose white
The decreased “Density” will make the foam float on top of the fluid, and the colours help to separate the foam from the fluid visually.
Adjusting the “k Volume” and "Surface Tension" Daemons
The “k Volume” daemon is just a box that can be rescaled and adjusted to enclose a certain volume. In this case, the daemon's box will be slightly smaller than the “Cube01” node. Note the “Scale” settings from “Cube01”, add 0.01 to each value, and transfer them to the “Scale” parameters of the daemon, e.g.:
Cube01 > Scale > 6.0, 3.0, 3.0
k Volume01 > Scale > 6.01, 3.01, 3.01
This tight fit is necessary, because in this scene, new foam particles will be created and they will most probably leave the cube. To delete them immediately, the “k Volume” daemon must be very close to the cube's borders.
"Surface Tension" acts globally on all of the scene's emitters. This means that it will affect both the “Square01” emitter and the particles in the “Container01” node. To get nicely shaped drops and strings, use the following settings:
Surface_Tension01 > Node_Params > Surface Tension > Strength > 100
Balanced > Yes
Adjusting the “Filter” Daemon
When a particle collides with the cube object it is transferred from “Square01” to “Container01”, and removed from the source emitter simultaneously. With the “Split” option, the filter creates 3 additional particles per filtered foam particles. This way it is possible to increase the amount of foam and get a denser look.
- Source Emitters > Square01
- Target Emitter (True) > Container01
- Condition > On Particle Collision (try other conditions as well, for example velocity or pressure)
- Split > Yes
- # child > 3
The Simulation
Click on “Simulate” to see the results. Play with the “Volume” settings of the “Square” emitter to get splashes of varying strength. You can also also add a second “Filter” daemon and filter against the particles' “Pressure” value to introduce a second criteria for the creation of foam.
Another idea is to work with a second “Filter” and another “Container” emitter to transfer foam back into water, for example after a certain age or when a particle's speed falls below a speed threshold.