Thursday, May 7, 2015

H14 PBD Grain Solver Guide

In Houdini 14, SideFX released a Grain Solver based on the Position Based Dynamics (PBD) approach. This solver proved to be very applicable to my research interest and so I decided to delve into it as much as possible. SideFX lives up to expectations on the documentation released with each node and so it provided a fantastic starting point, but what I hope to summarize here is what I learn about the Sand Solver that isn't very clear from the outset. Hopefully this will help you as you get started with it as well.

Practice:

The new Grains Tool Shelf is where SideFX provides several default networks for their Sand Solver, much like their Pyro FX Tool Shelf has done along with many others.

New Grains Tool Shelf
To setup a network, I would recommend you start with a geometry to convert to "grain" as well as at least one static object to catch the grain after it is affected by gravity. You can use a Solid Geometry, a Houdini Fog Volume, or a VDB Volume as the geometry to convert.

Initial Scene
Initial DOP Network
From here, select the geometry object you wish to convert to grain and select any tool other than "RBD Grains" and Houdini will build a default network. In this example, I'll be using the "Dry Sand" tool. When you use a shelf tool, the node network should look something like this in the SOP context:


And the DOP context should then look something like this:


As with the Pyro FX Tool Shelf, Houdini will drop down a lot of helpful nodes, but there are only a few nodes that actually contribute to the simulation. In this case there are only two:

1. Grain Source SOP: Generates particles from a source geometry for the DOP network
2. POP Grains DOP: Actually advects the particles

The default network that the shelf tools will lay down also include several other nodes that do not contribute to the simulation, but are still important for meeting the requirements of the DOP network and shading the particles later on:

1. POP Object DOP: Sets up the required data for the DOP Network
2. POP Source DOP: Imports the particles generated in the Grain Source SOP
3. POP Solver DOP: Normally moves the particles through the simulation, but each particle that passes through the POP Grains DOP is ignored because it has the "ispbd" attribute set to 1.
4. POP Sprite DOP: Generates cards on each particle and applies images to them
5. POP Color DOP: Modifies the "Alpha" and "Cd" attirbutes



Theory:

Now, I want to cover just a brief overview on how Position Based Dynamics differs from other methods that Houdini has used in their simulations in the past.

The concept of Position Based Dynamics was introduced in a paper published in 2006 by the same name. Basically, the idea is that by focusing on changing position directly without manipulating velocity or acceleration, one can achieve better control over the simulation. While it does allow better control, it is not intended to be physically accurate, but rather just a stable, fast, robust system that produces plausible results.

As the SideFX documentation states, "The main advantages of Position Based Dynamics (PBD) are its simplicity and controllability: unlike sophisticated solvers such as FLIP and FEM, PBD uses only positional constraints to determine the movement of the points in the system. It resolves penetrations by projecting points to valid locations. This completely avoids the overshooting problems common in force based solvers. It handles collision constraints easily, and is useful for simulating sand and snow."

So, basically the PBD solver allows the simulation to easily solve collisions without blowing up because it doesn't use intense forces to solve the collisions.

Most Physically Accurate Simulations: Penetrations --> Forces --> Velocity --> Position
Position Based Dynamics: Penetrations --> Velocity --> Positions

So, how does it do this? Instead of treating stress, pressure, etc. as forces, it converts all of these forces in to position constraints. Then, it simply iterates over these contraints and projects the points according to these constraints, giving us an algorithm something like this:

Given a set of points (N) and a set of constraints (M):

1. For every frame
2.         Compute collision constraints for all N and add to M
3.         For every solver iteration
4.                 Project all N along M

So, the settings that will increase the time the solver takes are:

1. Number of Points
2. Number of Iterations
3. Number of Constraints

The settings that affect these are:

1. Number of Points
        -Grain Source: Point Separation
        -Grain Source: Packing Density
        -Grain Source: Source Offset
        -POP Grains: Particle Separation
2. Number of Iterations
        -POP Grains: Constraint Iterations
3. Number of Constraints
        -Amount of collisions in the scene
        -Grain Source: Explicit Constraints
        -POP Grains: Accurate Friction
        -POP Grains: Explicit Constraints
        -POP Grains: Max Neighbors
        -POP Grains: Neighbor Query Scale
        -POP Grains: Update Collisions During Iterations
        -POP Grains: Update Neighbors During Iterations


The PBD solver is not intended to be as physically accurate as FEM, but it will produce sufficient results in most situations.



SideFX Tutorials:

Grains Documentation