Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

GodotHair

A real-time physically-based hair lighting experiment in the Godot Engine based primarily on the paper “An Energy-Conserving Hair Reflectance Model”.

hair_carousel

Introduction

Hair Rendering

Approaches for high-fidelity hair rendering typically utilize strand-based modeling. With this technique, each individual hair strand is represented as a curve primitive. Hundreds of thousands of these strands are then combined to form the hair volume. Because this approach accurately represents the macrogeometry of real hair, physics and lighting can be accurately simulated—especially with path tracing.

The visual accuracy of strand-based rendering comes with considerations for use in real-time settings. For one, the sheer complexity of the combined geometry has a considerable performance cost. Effective implementations also typically require specialized rendering pipelines, as strand-based hair rendering does not fit neatly into a conventional rasterization workflow. Despite this, strand-based hair has been successfully implemented in multiple real-time settings (e.g., Unreal Engine 5 and REDEngine).

Given the constraints of strand-based hair, a popular alternative approach is to render hair via hair cards. A hair card is a flat quad that represents a clump of hair strands. Textures are applied on each card to depict individual strands. By layering multiple cards on top of one another, the illusion of voluminous hair can be achieved at a relatively low performance cost.

However, hair cards come with their own set of notable trade-offs. Because physics are simulated per card rather than per strand, convincing hair motion becomes difficult. Additionally, the flat geometry of cards makes accurate self-shadowing and multiple scattering difficult. Ultimately, hair cards were chosen as the rendering technique this project as they provided a good balance between visual quality and ease of implementation.

Note

Hair card geometry rendering implementation can be found in /assets/hair/materials/shaders/hair.gdshader.

Hair Dataset

The hair card meshes featured in this project originated from dataset included in the CT2Hair project. Strand data was first converted from CT2Hair’s proprietary file format to the Alembic strand file format (.abc). Using Unreal Engine 5’s Hair Card Generator plugin, accurate hair card meshes could then be generated and imported into the Godot engine.

Note

Hair card meshes are located in /assets/hair/models. These models should not be considered production-ready but are available free for users to adapt under the CC BY-NC 4.0 license.

Lighting Model

Scattering Function

The lighting model implementation is primarily based on the models described in Marschner et al. (2003), d’Eon et al. (2011), and d’Eon et al. (2014). Hair cuticle microgeometry is approximated as a “dielectric cylinder[s] covered with tilted scales” (Marschner et al., 2003)—a shape analogous to a stack of cups.

cuticle

Adapted from d'Eon et al. (2011)

Upon hitting a strand, light can take several distinct paths (lobes) which are categorized according to the sequence of reflections (R) off or transmissions (T) through the surface of the strand. The most important lobes along with distinctive visual characteristics are listed below:

  • R lobe — Paths where light reflect (R) off the front surface of the strand.
    • Appears as a bright, sharp, uncolored highlight (i.e., taking on the color of the light source).

  • TT lobe — Paths where light transmit (T) through the strand, then transmit again (T) out the back.
    • Appears as a bright, diffuse highlight most apparent when the hair is backlit. Because the light traverses the pigmented interior, this highlight is colored and saturated.

  • TRT lobe — Paths where light transmit (T), reflect (R) off the back, then transmit (T) back out the front.
    • Appears as a dim, softer highlight. Because the light traverses the pigmented interior twice, the highlight appears darker and more saturated than the TT lobe.
    • This lobe is also primarily responsible for the ‘glints’ caused by caustics that can be visible on hair (Marschner et al., 2003).

  • TRRT, TRRRT, …etc. lobes — Paths where light internally reflect more than once.
    • Appears as an increasingly dim, diffuse, and saturated highlight.
    • The combination of these remaining lobes can be approximated as a single isotropic lobe using a geometric series (Chiang et al., 2016). However, because these lobes typically contribute very little to overall luminance, the provided implementation omits them entirely.

One defining characteristic of hair lighting is that lobe highlights tend to appear visually shifted from one another (as opposed to overlapping perfectly). This phenomenan is caused by the tilted scales of the cuticle (Marschner et al., 2003). The implemented lighting model utilizes the physically-based cuticle tilt-angles from d’Eon et al. (2014) to simulate this offset.

Additionally, the sharpness of lobe highlights differ in the direction along versus around hair strands—they are anisotropic. To freely model this anisotropy, each lobe is separated into the product of a longitudinal distribution (i.e., along the strand) and an azimuthal distribution (i.e., around the strand)—a consequence of Bravais law and cuticle microgeometry model symmetries (Marschner et al., 2003). The implemented lighting model utilizes the energy-conserving longitudinal scattering distribution and logistic azimuthal scattering distribution from d’Eon et al. (2011) and Chiang et al. (2016) respectively.

Color

Hair color is determined by the relative concentrations of two pigments—eumelanin (a brown-black pigment) and pheomelanin (a yellow-red pigment). d’Eon et al. (2011) uses a linear combination of the two concentrations to calculate a spectral absorption coefficient. While physically-accurate, this approach is unintuitive for artistic control. The provided implementation instead uses the albedo to absorption coefficient reparameterization proposed in Chiang et al. (2016) which allows a standard albedo uniform to be exposed.

Multiple Scattering

The lighting model discussed so far handles only single scattering—light that scatters from a single strand once before reaching the camera, with no interaction with neighboring strands. With single scattering alone, hair would appear mostly black, with color being present only within lobe highlights. To achieve convincing hair shading, multiple scattering simulation is required.

Unlike single scattering, accurate multiple scattering requires modeling highly complex light paths that vary with hairstyle shape and occlusive objects (e.g., a person's head). The provided implementation, however, forgoes these complexities and instead uses the non-physically-based multiple scattering approximation from Karis (2016). A more accurate approximation would be a strong area for future improvement.

Note

Lighting model implementation can be found in /assets/hair/materials/shaders/hair.gdshaderinc. While the default implementation is too expensive for real-time production environments, it should be adaptable for lower performance targets (see Karis (2016) and Tafuri (2019) for potential term approximations). Some optimization toggles are implemented for experimentation purposes.

Results

hair_demo.mp4

References

d’Eon, Eugene., et al. An Energy-Conserving Hair Reflectance Model. EGSR. (2011).
d’Eon, Eugene., et al. A Fiber Scattering Model with Non-Separable Lobes. SIGGRAPH. (2014).
Karis, Brian. Physically Based Hair Shading in Unreal. SIGGRAPH. (2016).
Marschner, Stephen R., et al. Light Scattering from Human Hair Fibers. SIGGRAPH. (2003).
Tafuri, Sebastian. Strand-based Hair Rendering in Frostbite. SIGGRAPH. (2019).
Chiang, Matt Jen-Yuan., et al. A Practical and Controllable Hair and Fur Model for Production Path Tracing. EG. (2016).

Attributions

CT2Hair by Meta Research is modified and used under the CC BY-NC 4.0 license.

About

Physically-based hair lighting implemented in Godot

Topics

Resources

Stars

28 stars

Watchers

3 watching

Forks

Contributors

Languages