Temitope FALADE's profile

HOUDINI - FLIP SIMULATION PART 1 (BASICS)

HOUDINI - FLIP SIMULATION PART 1
(BASICS)
INTRODUCTION
This documentation is based on my learning experience with side FX Houdini on FLIP simulation. FLIP involves the simulation of liquid bodies inside Houdini. Examples of liquid can include water, wine, melted chocolate, mud, blood, oil, etc. Basically any matter that exists in their liquid state can be simulated using FLIP. 

The computations behind any type of simulations in Houdini are handled by what is known as a SOLVER. In that respect, the computation of flip simulations are performed by a FLIP SOLVER, and all the particles that make up our liquid body (or flip) are called FLIP PARTICLES.
TYPES OF FLIP SIMULATIONS
There are different types of FLIP simulations that can be performed inside Houdini based on the behaviour we want our flip particles to imitate. They are:

1. Basic Emission
2. Continuous Emission

1. Basic Emission : The basic emission is where all the flip particles emit from a source once. These particles are emitted from the source and fall under the influence of gravity. If they are confined within a container geometry, they fall and settle down inside the geometry. While at rest, they can be disturbed by external influences such as an object falling into the liquid, or a wind force that causes them to move in a certain direction or undulate (such as rivers or oceans).

2. Continuous Emission : The continuous emission is where the flip particles continually emit from a source.
MODULE 1: BASIC EMISSION SETUP IN HOUDINI
In order to create a flip simulation inside Houdini, we will start by creating a DOP network node. This is the node that houses everything that has to do with the flip simulation, including the flip particles themselves, the solver node, the colliders, forces etc. Right click and type "dopnet" in the search box and click on it to create the node.
Now we can double click on this node to enter into it's sublevel. The sublevel is currently empty, and the only thing present is the output node as shown below:
The first thing we need to create is the flip particles themselves, since this is what we want to simulate. So create a new 'flip object' node. The flip object is basically the flip particles themselves. Next, create a 'flip solver' node and connect the output of the flip object to it. This flip solver is what we will use to solve the flip simulation. Next, we will create a 'gravity' node and connect the output of the flip solver to it. Finally, connect the output of the gravity to the 'output' node. The connection should look as follows:
This is the most basic setup of a flip simulation. Everything we will do from this point on is to build upon this basic setup. In the viewport, we should see the flip particles enclosed within a bounding box.
Right now the bounding box is too large, so we can reduce it's size by selecting the flip solver and navigate to the 'volume motion' tab. Under the volume limits subtab, we will see a 'box size' parameter. By punching in a lower number we will be able to reduce the bounding box size.
If we play the simulation now, the flip particles will simply fall under the influence of gravity, and the instance they pass through the bottom of the bounding box, they disappear. This implies that our flip simulation (any simulation basically) can only exist within this bounding box. We can make the flip particles to actually interact with the bounding box as though it is an enclosed container. To do this, select the flip object node and turn on the 'closed boundaries' parameter. Now if we play the simulation, the flip particles will actually collide with the bounding box.
CUSTOM EMISSION GEOMETRY
So far, we have been able to emit our flip particles from the in-built default emission source. This default emitter is found in the SOP path shown below:
However we can reference-in the path to our own custom geometry which will now become the new emission source. To demonstrate this, let us go back to the object level and create a new 'geometry' node and name it "emitter". Enter into the sublevel of this geometry node and create a sphere. Also name the sphere "emitter_geo". 
Now in order to make this sphere an emission source, we need to use points associated with this geometry as the source of the flip particles. This makes sense since we need our particles to come out from a point source. We can either generate these points directly on the surface of the geometry (in this case we will use 'surface SOP' as input type) or within the volume of the geometry (in this case we will use 'particle field' as input type). The latter option is a more preferred method. In order to generate points from within the volume of our emitter geometry, create a 'points from volume' node and connect the output of the emitter to it. As a way to organize things, let us connect a 'null' node and name it "emitter_out".
This should generate some points within the emitter geometry. Right now, the points are arranged uniformly. It's usually a good idea to randomize them by increasing the 'jitter seed' and 'jitter scale' parameters on the points from volume node. This will randomize the generated points for us.
Now let us go back to the dopnet sublevel, and change the input type on the flip object node to 'particle field'. We will also reference-in the path of the emitter_out null into the SOP Path. The generated points within our emitter geometry should now be converted into flip particles, and if we playback, it will fall under gravity like before.
The number of generated points (or particles) is controlled by a parameter called 'particles separation'. We can generate more points (or particles) by lowering the particle separation and generate lesser points (or particles) by increasing the particle separation. Keep in mind that with more particles, we will get a high quality simulation where all the fine details would be present, however the simulation time will take longer; and vice versa. 

The next thing we need to do now is to ensure consistency between the number of generated points within our emitter geometry and the number of generated flip particles in order to avoid any clipping errors. To do this, right click and copy the particle separation parameter on the flipobject, and paste relative reference on the points from volume particle separation parameter. This will now link the two parameters together, so we can control the number of particles directly from the flip object node.

CONTINUOUS EMISSION
Continuous emission happens when the flip particles continually emit from the source. Example of where this type of simulation is used is a flowing faucet (or tap), or a firefighter water jet/spray, or rainfall etc. This simulation works because the flip particles are subjected to a velocity in a certain direction and with a certain magnitude (velocity is a vector quantity).

In order to create this setup in Houdini, we will add a 'volume source' node to our basic flip setup. This node is what will make the flip particles to emit continuously from their source.
The difference in this setup is that while the flip object node represents the actual flip particles themselves which are generated on the first frame of the simulation (and needs to be present in our setup), the volume source is what will make these particles to emit continually. 

To set this up, we will first connect this volume source node to our flip solver and reference-in the emitter_out null into it's SOP Path field. We will also check-on 'source particles' under the particles subtab and delete 'particles' in the group field. Lastly, we will remove the SOP Path of the flip object node.
Now, when we play the simulation, the flip particles should emit continuously as long as 'activation' is set to 1. If activation is set to 0, no flip particles will be emitted. We can switch the emission on and off (like a tap) by simply step-animating the activation from 1 to 0 (or vice versa) over the timeline.  We can use the following VEXpressions on the activation parameter to achieve different results:

1. $F == N : This will emit flip particles only on frame N (subsequent frames will not generate any particles)
2. $F <= N : This will continually emit flip particles up to frame N (beyond this frame, no flip particles are generated)
3.  $F >= N : This will continually emit flip particles after frame N (no flip particles are generated before this frame)
CONTINUOUS EMISSION WITH DIRECTION
Currently our continuous emission only falls down under gravity. We can actually introduce a velocity field which will allow us to emit the flip particles in any direction. We will achieve this with a 'point velocity' node. This node is used for adding velocity to points as the name suggests. Knowing that velocity is a vector quantity, we can give a magnitude and also specify a direction. Since the points are generated from our emitter geometry, it make sense that this point velocity node should only be added in the emitter sublevel. 
Under the basic tab of the point velocity, change the initialization from 'compute from deformation' to 'set to value'. Then you can type in the magnitude of the velocity you want in any of the three axes. You can also play around with the different properties in the other tabs such as 'noise' or 'conical noise' etc. to achieve different results.
EMISSION FROM ANIMATED SOURCE
It is also possible to emit flip particles (either basic or continuous) from an animated emitter geometry. For example, if we want to create a water monster where water particles are constantly emitting from his body as he moves around (continuous emission), or a wine being poured into a glass cup from it's bottle (basic emission from an animated emitter and collider geometry), we can achieve that. The approach is pretty much the same as what we have learnt so far. 

Here are some important tips to note:

1. Animated geometries should first be cached out as an alembic file (if they are to be imported from a different software).
2. Imported alembic geometries need to be unpacked first by connecting an 'unpack'
node before proceeding further.
3. If you're importing an animated collider (such as a wine bottle in a wine pour animation), ensure that the collider has enough thickness on it for proper collision (we will discuss more on this in the collision section).
ADDING COLLIDERS
Without further ado, we're going to discuss the most efficient way to add a collider geometry to our flip simulation. 

We will start by creating a new geometry node named 'collider' and enter into it's sublevel. Let's create a preset pig head geometry and position it under our the emitter geometry with a transform node.
Next we will convert this pig head into a collision geometry by creating a 'collision source' node and connecting it to it (if we are importing an alembic as our collider, we need to first unpack the alembic before converting into a collision source). 

This collision source node has two outputs, the first one is for the actual surface geometrical representation of the collider itself, and the second one is for the volumetric representation of the collider. This means whatever we intend to use as a collider has to be an airtight closed geometry in order for us to use it's volume. The volumetric representation of anything inside Houdini is called 'VDB'. We will connect two null outputs to this node and name them 'collider_geo' and 'collider_vdb' respectively.
We can increase the resolution of the VDB on the collider by reducing the 'voxel size' under the volume tab of the collision source.
Next, inside the dopnet node, we are going to create a 'static object' node and name it 'collider'. We are going to use this static object node to link the collider geometry to our simulation.
Next we will do the following:
1. Reference the collider_geo null to the SOP Path;
2. If our collider is animated, check-on the 'use deforming geometry' parameter;]
3. Change 'Collision Detection' to 'Use volume Collisions';
4. Change 'Mode' to 'Volume Sample';
5. Reference the collider_vdb null to the Proxy Volume path
6. Use a merge node to connect the static object node and the gravity node together (making sure gravity node is on the right side).
The flip particles should now collide with the collider geometry.
CACHING THE SIMULATION
We will start by creating a new geometry node named 'cache' and go inside the sublevel of this node. Then we will create a 'dopI/O' node. This node is used for bringing a dopnet simulation from the object level into the sublevel (otherwise known as SOP level).
On the dop import field node, we will reference-in the dopnet into the 'DOP Network' path. In the presets, we will choose 'FLIP Fluid'. This will create three attribute fields for us.
Next, let us add a 'Fluid Compress' node before the file cache node. This node will help us to compress the size of our flip simulation. You can use relative referencing to link the particle separation from our flip object to the particle separation of this fluid compress node. 
Next, on the file cache node, change the 'file path' to 'explicit', and create a path where you want to cache out the simulation to. It is very important to use the following convention for naming your cache:
                                         "FileName"_$F4.bgeo.sc
The $F4 sign will ensure the numbering of the caches are in 4 significant figures which is more preferred, and the 'bgeo.sc' is the native format for saving Houdini caches. When you're done, click on 'save to disk' to write out the caches. Depending on the complexity of your simulation, this is going to take sometime to complete.
MESHING THE FLIP PARTICLES
We will now convert the flip particles into polygon mesh. We will do this by connecting a 'particle fluid surface' node to our file cache.
We can tweak the following settings under the 'surfacing' tab to improve the look of the fluid mesh:

1. Particle Separation: Smaller values reduces the distance between the particles and gives more details to the fluid mesh.
2. Influence Scale: Reducing the influence scale will reduce the surface area of the mesh and the surface will will start to separate from each other.
3. Droplet Scale: Reducing this value will reduce the size of the droplets generated in the simulation

We will go further on this later on.
EXPORTING TO ALEMBIC
To export the flip mesh as alembic, we will connect a 'rop alembic export' node right after the particle fluid surface node. Then we will change the valid frame range to 'render frame range' based on the simulation timeline, and also specify the output directory. Click on 'save to disk' once done and the flip mesh will be exported to alembic.
The alembic can then be imported into another software such as Maya, blender, or unreal engine for shading and rendering.
HOUDINI - FLIP SIMULATION PART 1 (BASICS)
Published:

Owner

HOUDINI - FLIP SIMULATION PART 1 (BASICS)

Published: