From 9c60bd008cbda990a237a54eaf71244cca141638 Mon Sep 17 00:00:00 2001 From: Santi Paprika Date: Wed, 2 Feb 2022 18:47:11 +0100 Subject: [PATCH] Enable human skin profile via preprocessor define (https://github.com/o3de/o3de/pull/6428#discussion_r797699927) Signed-off-by: Santi Paprika --- .../Assets/Materials/Types/Skin_Common.azsli | 4 ++++ .../Atom/Features/PBR/BackLighting.azsli | 17 ++++++++++------- 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/Gems/Atom/Feature/Common/Assets/Materials/Types/Skin_Common.azsli b/Gems/Atom/Feature/Common/Assets/Materials/Types/Skin_Common.azsli index cf3bd14d8a..9b3c29e96d 100644 --- a/Gems/Atom/Feature/Common/Assets/Materials/Types/Skin_Common.azsli +++ b/Gems/Atom/Feature/Common/Assets/Materials/Types/Skin_Common.azsli @@ -22,6 +22,10 @@ #include "MaterialInputs/UvSetCount.azsli" #include "MaterialInputs/DetailMapsInput.azsli" +// Use human skin profile for thin object transmission (if enabled) +// Remove this line to use a custom profile based on the scatter color +#define USE_HUMAN_SKIN_PROFILE + ShaderResourceGroup MaterialSrg : SRG_PerMaterial { // Auto-generate material SRG fields for common inputs diff --git a/Gems/Atom/Feature/Common/Assets/ShaderLib/Atom/Features/PBR/BackLighting.azsli b/Gems/Atom/Feature/Common/Assets/ShaderLib/Atom/Features/PBR/BackLighting.azsli index 863315c28c..82a3038054 100644 --- a/Gems/Atom/Feature/Common/Assets/ShaderLib/Atom/Features/PBR/BackLighting.azsli +++ b/Gems/Atom/Feature/Common/Assets/ShaderLib/Atom/Features/PBR/BackLighting.azsli @@ -23,7 +23,7 @@ float3 TransmissionKernel(float t, float3 s) return 0.25 * (1.0 / exp(exponent) + 3.0 / exp(exponent / 3.0)); } -// [specific profile for SKIN (not used ATM, replaced by TransmissionKernel)] +// [specific profile for human skin] // Analytical integation (approximation) of diffusion profile over radius, could be precomputed in a LUT // From d'Eon and Luebke (https://developer.nvidia.com/gpugems/gpugems3/part-iii-rendering/chapter-14-advanced-techniques-realistic-real-time-skin, section 14.4.7) float3 T(float s) @@ -72,6 +72,8 @@ float3 GetBackLighting(Surface surface, LightingData lightingData, float3 lightI } // Irradiance arround surface point. + // Albedo at front (surface point) is used to approximate irradiance at the back of the object + // See observation 4 in [Jimenez J. et al, 2010] // Increase angle of influence (angle(N,L) -> angle(N,L) + acos(transmissionNdLBias)) to smooth transition regions float3 E = surface.albedo * saturate(lightingData.transmissionNdLBias + dot(-surface.normal, dirToLight)); @@ -82,13 +84,14 @@ float3 GetBackLighting(Surface surface, LightingData lightingData, float3 lightI // Use scattering color to weight thin object transmission color const float3 invScattering = rcp(max(surface.transmission.scatterDistance, float(0.00001))); - // Albedo at front (surface point) is used to approximate irradiance at the back of the object - // See observation 4 in [Jimenez J. et al, 2010] +#ifndef USE_HUMAN_SKIN_PROFILE + // Generic profile based on scatter color result = TransmissionKernel(s, invScattering) * lightIntensity * E * transmissionParams.w; - - // Alternative specific to skin translucency - // result = T(s) * lightIntensity * E * transmissionParams.w; - +#else // USE_HUMAN_SKIN_PROFILE + // Profile specific to human skin + result = T(s) * lightIntensity * E * transmissionParams.w; +#endif + // Distance attenuation applied to hide artifacts due to low-res projected areas onto shadowmaps (might need some work in the future) result /= max(1.0, attenuationDistance * attenuationDistance * lightingData.distanceAttenuation); }