The Blender hair system will get a number of improvements for the Gooseberry project. Especially the hair dynamics have to be improved and integrated better into the set of artistic tools to allow animators to control and tweak the hair system efficiently. We have a number of goals that should make hair modelling and simulation into a more flexible and helpful tool.
Animation tools for hair are quite useless without a stable physical solver. Especially for long hairs a physical solver is a valuable tool for generating believable motion. The solver for the simulation has to be very stable, meaning that it produces correct values (no “explosions”) and does not introduce additional motion due to numerical errors (jiggling).
The current solver for the hair dynamics has a number of issues, resulting from conflicts in the mixed cloth/hair model, questionable assumptions in the force model and plain bugs. To avoid these issues the numerical solver implementation will be replaced by a modified Eigen-based solver. Eigen is a library for linear algebra that is already used in Blender and provides a lot of optimizations that would be hard to introduce otherwise.
Numerical Solver Overview (since this is a code blog)
The physical model for hair systems defines each hair as a series of points, connected by “springs”. In addition there are a couple of external influences that have to be accounted for. The physical equations boil down to calculating changes in positions and velocities of these points.
Our solver then has the task of calculating these Δx and Δv so that the result is as close as possible to the actual value. As a first-order approximation and using sensible force models the differential equations can be expressed as a linear system A·Δv = b (See the References section for in-depth information). The algorithm of choice for solving this system is the Conjugate Gradient method. The Eigen library provides a nice set of CG algorithms already.
Unfortunately, for a constrained system such as a hair structure with “pinned” hair root points as well as collision contacts (see below) the basic CG solver is not enough. We need to extend the method somewhat to take constraints into account and limit the degrees-of-freedom in the solution selectively. The paper by Baraff/Witkin describes this modification in detail.
Hair Volume and Friction
Hair and fur coats need a number of features that notoriously difficult to model in a hair simulation: Volume and Friction. “Volume” is the phenomenon where a lot of hairs closely together will push each other away and leave empty space between them (especially curly hair). “Friction” is what makes entangled hair so difficult to comb, because hairs stick together and have lots of surface area.
Both these effects could be naively modeled by hair-hair collisions, but this is prohibitively expensive due to the potential number of collision pairs. A more economical approach is to model the cumulative effect of hairs using a voxel grid. This feature has already been implemented.
Collisions are essential for believable simulation results, but so far don”t exist in for hair simulation in Blender (only a volume-based friction model which is a poor replacement).
The first stage in collision handling is to actually detect intersection of hair segments with meshes. This is done in two distinct phases to speed up the process:
- Broadphase: The hair segment is tested against the bounding boxes of eligible colliders to narrow down the number of pairs. Acceleration structures can speed up the process of finding overlapping pairs.
- Nearphase: The potential intersection pairs are tested for actual intersection of the detailed geometry.
The detection of collision pairs is currently handled by a BVH tree based structure. In the future it may become advisable to use the Bullet collision detection for finding such pairs, since it has a lot better optimizations for complicated intersection tests and broadphase filtering.
The second stage is to actually make a hair particle react to a collision, so that the hair is prevented from entering the mesh object. A simple approach is to generate a repulsion force which pushes outward from the mesh. However, this force can cause a lot of unwanted motion. The effect is that a hair particle can not stably come to rest on a surface or even the simulation can “explode” when a particle gets trapped in a collider cavity and it”s velocity increases exponentially from repeated collision responses.
A much more elegant and stable approach to handling collision response is to define the contact between a hair and a mesh as a “constraint”: When the hair collides with a surface it”s motion becomes restricted in the direction of the surface normal (while moving tangentially is still possible and desired to relax internal spring forces). An implicit solver can be modified so that collision constraints are taken into account and jittering effects as well as spring instability is largely avoided.
Settings in the hair dynamics panel need reorganization to be more intuitive and allow easier tweaking. Naming there is currently misleading and as a consequence artists seem to tend to overconstrain the hair system by steadily increasing forces, until eventually the solver gives up and the simulation “explodes”.
The suggested changes would group the dynamics settings into four categories:
- Internal Forces: Structural features of the hairs in general (Bending, Stretching, Damping)
- Interaction: Friction and Volume Pressure settings, caused by concentrations of hair in the same space
- Collision: Bounciness (restitution) and friction of the hair
- External Forces: Effect of various force field types on the hair system
To avoid the problem of counterbalancing forces this ordering should suggest a sensible workflow. Starting with the internal forces results in natural behavior of individual hairs. Setting up friction and damping effects secondarily should help avoid the problem of masking extreme forces by equally strong damping, which creates an “explosive” setup that is hard to control.
Each of the categories can be disabled on its own. This also helps to fix issues with either of the influences in case something goes wrong. Otherwise the only way to test the hair dynamics settings is to reset them to zero individually.
Presets could be another simple but effective way to facilitate tweaking. A fine-tuned group of settings can then be stored for later use or to generate variants from.
Physical simulation is only one tool among many in 3D animation production. A major goal for the hair system is to improve tools for artists and combine classic keyframe animation with simulation. The current workflow of the particle hairs gives animators very little control over the simulation beyond the initial setup phase (“grooming”). The results of a simulation never turn out exactly as desired, and so it is very important that animators be able to define corrections to simulation results.
An important concept for simulation control is the rest position of hairs, i.e. the “natural” shape and orientation a hair will be attracted to by the internal bending forces and additional (non-physical) goal spring forces. This rest position is currently defined as a single shape. Defining keyframes for particle system/hair is a clumsy process with a lot of overhead and far from a usable tool. After baking the entire simulation artists can also modify the point cache data, treating the motion of each hair point as a curve, but this is also limited and doesn”t scale well to large hair systems.
Guide Hairs would solve the problem of keyframing the hair rest positions. They are the primary data structure that animators work with, using sculpting/grooming tools and keyframes if necessary. They are roughly equivalent to the current base hair system, although for clarity renaming them is a good idea.
Simulation Hairs form the second data layer in the hair system. They are initially generated from the guide hairs (which also form the sim hairs” natural rest position). We have to decide how to display and distinguish these layers in the viewport, but it should be clear to artists that these are separate concepts.
Note that there could actually be more simulation hairs than guide hairs! This is an important feature which allows animators to work on a small set of hairs (easy to set up and control), while having more detail in simulations such as colliding with small objects. Generating simulation hairs can use the same interpolation approach as current child hairs.
Render Hairs are the current “child” hairs. They are not stored as permanent data and don”t carry state information of their own. Their purpose is only to generate sufficient visual detail for renderers. Render hairs can incorporate quite a few shaping features of their own, such as randomness, curling or tapering.
“Large Steps in Cloth Simulation” (Baraff/Witkin 1998): Extensive paper on the use of a modified Conjugate Gradient solver for cloth systems, including useful chapters on force derivations, constraints and collisions.
“Simulating Complex Hair with Robust Collision Handling” (Choe/Choi/Ko 2005): Detailed description of a hair collision response model using the CG solver method
“Artistic Simulation of Curly Hair” (Pixar technical paper, “Brave”): Very sophisticated hair model for long curly hair (collisions are too much for our purposes, but the bending model is very nice)
“Volumetric Methods for Simulation and Rendering of Hair” (Pixar technical paper, “The Incredibles”): Describes in detail the volumetric approach to hair-hair friction modeling