MaterialX icon indicating copy to clipboard operation
MaterialX copied to clipboard

Add Chiang hair BSDF

Open msuzuki-nvidia opened this issue 1 year ago • 8 comments

Add Chiang hair BSDF.

This PR provides Chiang hair BSDF model and related nodes proposed by #1973

The nodes to add are:

  • <hair_chiang_bsdf> : The BSDF
  • <hair_roughness> : User friendly roughness mapping
  • <hair_absorption_from_melanin> : Absorption coefficient mapping from melanin parameters
  • <hair_absorption_from_color> : Absorption coefficient mapping from user input color

It also include simple_hair_default material as a node graph example.

msuzuki-nvidia avatar Aug 12 '24 22:08 msuzuki-nvidia

Just to recap concretely the request made in the TSC meeting - it would be great if this PR could also include updates to the PBR spec document reflecting the new nodes being added here

https://github.com/AcademySoftwareFoundation/MaterialX/blob/main/documents/Specification/MaterialX.PBRSpec.md

ld-kerley avatar Aug 13 '24 17:08 ld-kerley

Thanks for the recap @ld-kerley. I will update this PR including the PBR spec document sometime soon.

msuzuki-nvidia avatar Aug 14 '24 02:08 msuzuki-nvidia

I think the sqrtPiOver8 factor might be an internal BSDF implementation detail, rather than something that should be done externally. For example, MDL already applies this factor internally. https://github.com/NVIDIA/MDL-SDK/blob/master/src/mdl/jit/libbsdf/libbsdf_hair.h#L174

BrianSharpe avatar Aug 15 '24 03:08 BrianSharpe

It can be internal. Although that part in MDL I'm not sure. MDL applies the $\sqrt{\pi/8}$ factor for both longitudinal and azimuthal roughness but the original paper (Appendix A. eq. 12) applies it only for azimuthal roughness, so I followed the paper. Other than that, it works for me.

msuzuki-nvidia avatar Aug 15 '24 03:08 msuzuki-nvidia

MDL applies the π/8 factor for both longitudinal and azimuthal roughness

I don't think it does. The MDL hair_prepare_roughness() function in that github link I posted only applies it to the Y component.

Given the π/8 factor is in the appendix, rather than in equation 8, makes me think it probably should be part of the internal BSDF implementation rather than in <hair_roughness>. But happy to defer to others for that decision.

BrianSharpe avatar Aug 15 '24 04:08 BrianSharpe

The MDL hair_prepare_roughness() function in that github link I posted only applies it to the Y component.

You're right. The factor is applied to only azimuthal!

I also see where your suggestion came from, and I feel the same now. I will include the change in next update.

msuzuki-nvidia avatar Aug 15 '24 04:08 msuzuki-nvidia

I think <hair_roughness> might need some more changes. In its current form, someone can't tweak the TT and TRT scaling factors. So I'm thinking of two potential changes to accommodate this.

possible change 1) <hair_roughness> returns only a single "vec2 roughness" value (corresponding to roughness_R). This means it's only implementing equations 7 and 8, and any TT and TRT scaling should happen externally. or possible change 2) <hair_roughness> takes two additional inputs "tt_scale" and "trt_scale", which default to 0.25 and 4.0 (or should that be 0.5 and 2.0 with them being squared internally?)

Option 1 has less redundancy, but is more work for the user. Option 2 is easier to use, but has redundancy. I'm fine with either option.

BrianSharpe avatar Aug 16 '24 00:08 BrianSharpe

I would prefer the second option with pre-squared defaults, 0.5 and 2.0. Indeed these scaling values are somewhat arbitrary but most implementations follow the Marschner's paper so I think it makes sense that the scaling is built-in and exposed in the parameters.

I will make this change as well. Thank you for the suggestion!

msuzuki-nvidia avatar Aug 16 '24 00:08 msuzuki-nvidia

Great to hear that, and thank you for correcting the spelling issues!

msuzuki-nvidia avatar Sep 18 '24 01:09 msuzuki-nvidia