Reuse albedo functions in principled hair BSDF
This commit is contained in:
parent
9e5c1787a5
commit
935f500501
|
@ -1397,32 +1397,10 @@ ccl_device void bsdf_microfacet_hair_blur(ccl_private ShaderClosure *sc, float r
|
|||
|
||||
/* Hair Albedo */
|
||||
|
||||
ccl_device_inline float bsdf_microfacet_hair_albedo_roughness_scale(
|
||||
const float azimuthal_roughness)
|
||||
{
|
||||
const float x = azimuthal_roughness;
|
||||
return (((((0.245f * x) + 5.574f) * x - 10.73f) * x + 2.532f) * x - 0.215f) * x + 5.969f;
|
||||
}
|
||||
|
||||
ccl_device float3 bsdf_microfacet_hair_albedo(ccl_private const ShaderClosure *sc)
|
||||
{
|
||||
ccl_private MicrofacetHairBSDF *bsdf = (ccl_private MicrofacetHairBSDF *)sc;
|
||||
return exp(-sqrt(bsdf->sigma) * bsdf_microfacet_hair_albedo_roughness_scale(bsdf->roughness));
|
||||
}
|
||||
|
||||
ccl_device_inline float3
|
||||
bsdf_microfacet_hair_sigma_from_reflectance(const float3 color, const float azimuthal_roughness)
|
||||
{
|
||||
const float3 sigma = log(color) /
|
||||
bsdf_microfacet_hair_albedo_roughness_scale(azimuthal_roughness);
|
||||
return sigma * sigma;
|
||||
}
|
||||
|
||||
ccl_device_inline float3 bsdf_microfacet_hair_sigma_from_concentration(const float eumelanin,
|
||||
const float pheomelanin)
|
||||
{
|
||||
return eumelanin * make_float3(0.506f, 0.841f, 1.653f) +
|
||||
pheomelanin * make_float3(0.343f, 0.733f, 1.924f);
|
||||
return exp(-sqrt(bsdf->sigma) * bsdf_hair_albedo_roughness_scale(bsdf->roughness));
|
||||
}
|
||||
|
||||
CCL_NAMESPACE_END
|
||||
|
|
|
@ -473,10 +473,9 @@ ccl_device void bsdf_principled_hair_blur(ccl_private ShaderClosure *sc, float r
|
|||
bsdf->m0_roughness = fmaxf(roughness, bsdf->m0_roughness);
|
||||
}
|
||||
|
||||
/* Hair Albedo */
|
||||
/* Hair Albedo. Also used by `bsdf_hair_microfacet.h` */
|
||||
|
||||
ccl_device_inline float bsdf_principled_hair_albedo_roughness_scale(
|
||||
const float azimuthal_roughness)
|
||||
ccl_device_inline float bsdf_hair_albedo_roughness_scale(const float azimuthal_roughness)
|
||||
{
|
||||
const float x = azimuthal_roughness;
|
||||
return (((((0.245f * x) + 5.574f) * x - 10.73f) * x + 2.532f) * x - 0.215f) * x + 5.969f;
|
||||
|
@ -485,19 +484,18 @@ ccl_device_inline float bsdf_principled_hair_albedo_roughness_scale(
|
|||
ccl_device Spectrum bsdf_principled_hair_albedo(ccl_private const ShaderClosure *sc)
|
||||
{
|
||||
ccl_private PrincipledHairBSDF *bsdf = (ccl_private PrincipledHairBSDF *)sc;
|
||||
return exp(-sqrt(bsdf->sigma) * bsdf_principled_hair_albedo_roughness_scale(bsdf->v));
|
||||
return exp(-sqrt(bsdf->sigma) * bsdf_hair_albedo_roughness_scale(bsdf->v));
|
||||
}
|
||||
|
||||
ccl_device_inline Spectrum
|
||||
bsdf_principled_hair_sigma_from_reflectance(const Spectrum color, const float azimuthal_roughness)
|
||||
ccl_device_inline Spectrum bsdf_hair_sigma_from_reflectance(const Spectrum color,
|
||||
const float azimuthal_roughness)
|
||||
{
|
||||
const Spectrum sigma = log(color) /
|
||||
bsdf_principled_hair_albedo_roughness_scale(azimuthal_roughness);
|
||||
const Spectrum sigma = log(color) / bsdf_hair_albedo_roughness_scale(azimuthal_roughness);
|
||||
return sigma * sigma;
|
||||
}
|
||||
|
||||
ccl_device_inline Spectrum bsdf_principled_hair_sigma_from_concentration(const float eumelanin,
|
||||
const float pheomelanin)
|
||||
ccl_device_inline Spectrum bsdf_hair_sigma_from_concentration(const float eumelanin,
|
||||
const float pheomelanin)
|
||||
{
|
||||
const float3 eumelanin_color = make_float3(0.506f, 0.841f, 1.653f);
|
||||
const float3 pheomelanin_color = make_float3(0.343f, 0.733f, 1.924f);
|
||||
|
|
|
@ -850,27 +850,26 @@ ccl_device_noinline int svm_node_closure_bsdf(KernelGlobals kg,
|
|||
/* Benedikt Bitterli's melanin ratio remapping. */
|
||||
float eumelanin = melanin * (1.0f - melanin_redness);
|
||||
float pheomelanin = melanin * melanin_redness;
|
||||
Spectrum melanin_sigma = bsdf_principled_hair_sigma_from_concentration(eumelanin,
|
||||
pheomelanin);
|
||||
Spectrum melanin_sigma = bsdf_hair_sigma_from_concentration(eumelanin, pheomelanin);
|
||||
|
||||
/* Optional tint. */
|
||||
float3 tint = stack_load_float3(stack, tint_ofs);
|
||||
Spectrum tint_sigma = bsdf_principled_hair_sigma_from_reflectance(
|
||||
rgb_to_spectrum(tint), radial_roughness);
|
||||
Spectrum tint_sigma = bsdf_hair_sigma_from_reflectance(rgb_to_spectrum(tint),
|
||||
radial_roughness);
|
||||
|
||||
bsdf->sigma = melanin_sigma + tint_sigma;
|
||||
break;
|
||||
}
|
||||
case NODE_PRINCIPLED_HAIR_REFLECTANCE: {
|
||||
float3 color = stack_load_float3(stack, color_ofs);
|
||||
bsdf->sigma = bsdf_principled_hair_sigma_from_reflectance(rgb_to_spectrum(color),
|
||||
radial_roughness);
|
||||
bsdf->sigma = bsdf_hair_sigma_from_reflectance(rgb_to_spectrum(color),
|
||||
radial_roughness);
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
/* Fallback to brownish hair, same as defaults for melanin. */
|
||||
kernel_assert(!"Invalid Principled Hair parametrization!");
|
||||
bsdf->sigma = bsdf_principled_hair_sigma_from_concentration(0.0f, 0.8054375f);
|
||||
bsdf->sigma = bsdf_hair_sigma_from_concentration(0.0f, 0.8054375f);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -968,27 +967,25 @@ ccl_device_noinline int svm_node_closure_bsdf(KernelGlobals kg,
|
|||
/* Benedikt Bitterli's melanin ratio remapping. */
|
||||
float eumelanin = melanin * (1.0f - melanin_redness);
|
||||
float pheomelanin = melanin * melanin_redness;
|
||||
Spectrum melanin_sigma = bsdf_microfacet_hair_sigma_from_concentration(eumelanin,
|
||||
pheomelanin);
|
||||
Spectrum melanin_sigma = bsdf_hair_sigma_from_concentration(eumelanin, pheomelanin);
|
||||
|
||||
/* Optional tint. */
|
||||
float3 tint = stack_load_float3(stack, tint_ofs);
|
||||
Spectrum tint_sigma = bsdf_microfacet_hair_sigma_from_reflectance(
|
||||
rgb_to_spectrum(tint), roughness);
|
||||
Spectrum tint_sigma = bsdf_hair_sigma_from_reflectance(rgb_to_spectrum(tint),
|
||||
roughness);
|
||||
|
||||
bsdf->sigma = melanin_sigma + tint_sigma;
|
||||
break;
|
||||
}
|
||||
case NODE_MICROFACET_HAIR_REFLECTANCE: {
|
||||
float3 color = stack_load_float3(stack, color_ofs);
|
||||
bsdf->sigma = bsdf_microfacet_hair_sigma_from_reflectance(rgb_to_spectrum(color),
|
||||
roughness);
|
||||
bsdf->sigma = bsdf_hair_sigma_from_reflectance(rgb_to_spectrum(color), roughness);
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
/* Fallback to brownish hair, same as defaults for melanin. */
|
||||
kernel_assert(!"Invalid Microfacet Hair parametrization!");
|
||||
bsdf->sigma = bsdf_microfacet_hair_sigma_from_concentration(0.0f, 0.8054375f);
|
||||
bsdf->sigma = bsdf_hair_sigma_from_concentration(0.0f, 0.8054375f);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue