Skip to content

Add BCSDF Approximation for Second Hair Material Type #4935

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 47 commits into from
Jul 21, 2021

Conversation

johnpars
Copy link
Contributor

@johnpars johnpars commented Jun 16, 2021

This PR introduces a Marschner-based BSDF (technically, BCSDF, as this is a far-field model which assumes that the fibers are viewed from a distance at which the near-field variations can be ignored) model to the HDRP hair shader (as a second model option, not a replacement). It is a follow up to this PR.

Marschner3

Currently, HDRP’s hair shader already supports a dual-specular lobed Kajiya-Kay model, with an additional specular transmission lobe. It is a phenomenological model, rather than physically based. This creates a challenge for artists, as there are many parameters to tune the model, and it is their responsibility to balance the energy between specular lobes.

This Marschner-based model takes a physically based approach, by analyzing the scattering events that occur within a hair fiber. It offers a much simpler parameterization for artists, with the added benefit of conforming well to HDRP’s physically based lighting by default.

Usage

Users can access the new model through the following steps:

  • Create a new Hair Shader Graph asset and open the graph.
  • Navigate to the Graph Inspector window in the graph.
  • Change the Material Type from Kajiya-Kay to Marschner.

Usage is otherwise very similar to the existing Kajiya-Kay model, and for the most part a user should be able to safely defer to the existing documentation regarding this (namely the usage of hair strand direction, proper use of which is crucial for getting correct results with the model)

Parameterization

The table below specifies the properties of note for controlling the model. This model shares one mutual parameter with the Kajiya model, Hair Strand Direction. It behaves in the exact same way.

Parameter Description
Base Color Defines the fiber’s cortex color, governing the absorption that occurs before the transmission (TT), second specular reflection (TRT), and scattering.
Smoothness Surface smoothness of the fiber, defining the width of the specular highlight.
Radial Smoothness Controls the internal scattering of the light paths and absorption that occurs within the fiber. “Allow Radial Smoothness” must be enabled on the hair target to use this property.
Cuticle Angle The angle in degrees at which the scales on the hair fiber are tilted from the strand direction. (for human hair, typically between 2 to 3 degrees). Use this property to “shift” the highlight.
Primary Reflection Smoothness A multiplier of the primary reflection’s (R) smoothness. Use this parameter to approximate the layer of shiny coating that can be observed on rougher-looking animal fur.

Note, @SebastienLa have organized this hair analysis document that goes in depth on parameterization. This PR does not currently address everything proposed there, but we are discussing on how to improve it.

Performance

Overall, performance is comparable to HDRP’s other forward-based shading models (Kajiya, Fabric, etc.). Performance metrics were captured from a standalone Windows built with an NVIDIA GTX 1070 (Max-Q, Laptop Card), at a 1920x1080 resolution, no MSAA.

Scenario #1: Two screen-aligned quads (Marschner, Kajiya), each taking up 50% of the viewport. Illuminated by one point, one spot, one directional, one environment light.

Model Forward Opaque Time Per-Quad (ms)
Kajiya-Kay 1.54
Marschner 1.36
Marschner (Reference) 22.32

image

Scenario #2: Two hair groom files (7000 strands represented with screen-aligned strips). Illuminated by three spot lights.

NOTE: These metrics were also taken 2X MSAA.

Model Forward Opaque Time Per-Groom (ms)
Kajiya-Kay 4.87
Marschner 4.32
Marschner (Reference) 57.38

image

Light Loop Integration

Light Type
Analytic All analytic lights in HDRP (point, spot, directional) are supported.
Area For now, like Kajiya, we must fall back to GGX for area lights. This is due to an issue with LTC which cannot capture anisotropic lobes well in the table. More research is required to support this. In the nearer term, it probably makes sense to explore a “Most Representative Light” approach to add support for anisotropic BSDFs to area lights in HDRP.
Environment Environment lighting is calculated by re-purposing the probe lighting sample. The sample is treated as a directional light, and the BSDF is invoked with respect to it (with the transmission lobe disabled).

Reference

This PR also includes a reference BSDF, which the approximation is based on. It can also be used by the path tracer, but right now is uniformly sampled.

[TODO IMAGE]

Additional Notes

  • Due to the transmission lobe, this model is extremely dependent on shadows.
  • During the process of adapting the model from reference to real-time, I realized that I would need to remove the Refraction Index (IOR) artist parameter. This is because most of the approximations need to be made with respect to human hair IOR (1.55) for optimal performance.
  • Additionally, the approximated model only evaluates the first three scattering events (R, TT, TRT) for performance reasons. The residual TR*T lobe is not accounted for (resulting in a ~15% energy loss).
  • For now, the model re-uses the Kajiya-Kay diffuse term as a matter of scattering approximation.
  • For roughened azimuthal scattering (enabled with the Allow Radial Smoothness toggle), a LUT is sampled per-BSDF invocation. I created this LUT in python and stored it as an EXR. I will add a Yamato test to confirm that this is okay for the various plaforms.

Testing status

Updated Graphics Test 1401 to also test for the new model. Launching a Yamato to confirm everything checks out on the various platforms.

1401_HairGraph

The original reference implementation was verified by plotting the various distribution curves and referencing them to the original papers I derived this model from. During the approximation process, I used the reference to make informed optimization decisions at the cost of quality / accuracy.

@johnpars johnpars added the HDRP label Jun 16, 2021
@johnpars johnpars requested review from eturquin and slunity June 30, 2021 13:49
@github-actions
Copy link

github-actions bot commented Jul 6, 2021

Hi! This comment will help you figure out which jobs to run before merging your PR. The suggestions are dynamic based on what files you have changed.
Link to Yamato: https://yamato.cds.internal.unity3d.com/jobs/902-Graphics
Search for your PR branch using the sidebar on the left, then add the following segment(s) to the end of the URL (you may need multiple tabs depending on how many packages you change)

HDRP
/.yamato%252Fall-hdrp.yml%2523PR_HDRP_2021.2

Depending on the scope of your PR, you may need to run more jobs than what has been suggested. Please speak to your lead or a Graphics SDET (#devs-graphics-automation) if you are unsure.

Copy link
Contributor

@Vic-Cooper Vic-Cooper left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As noted, it's worth texting to make sure the includes work properly. Added some changes to the docs too.

@sebastienlagarde sebastienlagarde marked this pull request as ready for review July 19, 2021 15:39
@sebastienlagarde
Copy link
Contributor

@johnpars All good. Can you update the documentation as mention by Vic and we are ready to go with this PR (before further improvement)

@sebastienlagarde
Copy link
Contributor

Also be sure to merge master and update screenshots

@sebastienlagarde sebastienlagarde merged commit 8383ca2 into master Jul 21, 2021
@sebastienlagarde sebastienlagarde deleted the HDRP/hair-material-type-2-bsdf branch July 21, 2021 09:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants