Hair Simulation

Implementation of Hair Simulation Using the Mass-Spring Model in UE4

Period: October 4, 2022 → February 2, 2023
Tools & Language: Blender, C++, Unreal
Status: Done
Description: Implementation of Hair Simulation using a Mass-Spring Model in UE4 (4.26)
Participants: 1

PEARL ABYSS × Kyung Hee University Software Education Program (3rd Round)


Overview

Hair simulation in games enhances realism and dynamic movement by supporting:

  • Physical interaction of hair with the surrounding environment
  • A variety of hair shapes and styles

The goal of this project is to implement a hair simulation using a Mass-Spring Model in Unreal Engine 4.


Mass-Spring System

  • Each hair strand is represented as a set of particles (masses) connected by springs (edges).
  • Hooke’s Law and Newton’s Second Law are used to govern the motion of these particles.
  • External forces (e.g., gravity, wind, collision with body or environment) combine with spring forces to shape the simulation.
  • A point-based representation is relatively cheap computationally and simplifies collision detection.

Internal Forces

  • Stretch Spring
  • Bending Spring
  • Twist Spring

Performance Considerations

  • Time Integration: Calculating hair particle positions each frame can be computationally heavy.
  • CUDA Acceleration: Using a CUDA static library (.lib) for hair initialization and updates can help offload calculations to the GPU.
UE4+CUDA

Hair-Object Collision

  • Signed Distance Field (SDF 3D):
    During simulation, each hair particle checks its position against an SDF to detect collisions.
    When collisions occur, the particle’s velocity is adjusted to prevent intersection with the object mesh.
Example of how Signed Distance Fields are used for collision detection.

Implementation Process

1. Distributing Hair Roots

  • Use vertex paint on the desired mesh region to specify where hair roots should appear.
  • Iterate over mesh vertices, randomly selecting points in each triangle (maintaining a minimum distance between selected points) for even distribution of hair roots.

2. Initializing Hair

  • Create and store hair particles (positions, velocities, etc.) using CUDA.
  • Each particle is associated with parameters like hair length, mass, and spring coefficients.

3. Updating the Hair Model

  • Each simulation step updates particle positions with internal spring forces plus external forces (gravity, wind, collisions).
  • Hair movement depends on the underlying mesh’s motion; rapid or large-angle movements can cause drastic hair displacement.

4. Object Collision

  • Compare each hair particle’s position with the Signed Distance Field of objects in the scene.
  • If collision is detected, adjust velocity to ensure the hair lies naturally on the object surface.

Results


References

  • Li, Lingyan, Rui Li, and Jun Yu. “A mass spring based 3D virtual hair dynamic system for straight and curly hair.” 2016 35th Chinese Control Conference (CCC). IEEE, 2016.
  • Lyu, Yao. “Hair Simulation Based on Mass Spring System.” (2016)
  • Selle, Andrew, Michael Lentine, and Ronald Fedkiw. “A mass spring model for hair simulation.” ACM SIGGRAPH 2008 papers. 2008. 1–11.
  • Jiang, Jianwei, et al. “Real-time hair simulation with heptadiagonal decomposition on mass spring system.” Graphical Models 111 (2020): 101077.