From d1b19a51d5d078eb13f575591d92fdac9cc6b6a3 Mon Sep 17 00:00:00 2001 From: Santi Paprika Date: Thu, 2 Dec 2021 18:36:55 +0100 Subject: [PATCH] Add point light thin transmission support Signed-off-by: Santi Paprika --- .../Atom/Features/PBR/Lights/PointLight.azsli | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/Gems/Atom/Feature/Common/Assets/ShaderLib/Atom/Features/PBR/Lights/PointLight.azsli b/Gems/Atom/Feature/Common/Assets/ShaderLib/Atom/Features/PBR/Lights/PointLight.azsli index 92f4065931..7f4cd46749 100644 --- a/Gems/Atom/Feature/Common/Assets/ShaderLib/Atom/Features/PBR/Lights/PointLight.azsli +++ b/Gems/Atom/Feature/Common/Assets/ShaderLib/Atom/Features/PBR/Lights/PointLight.azsli @@ -84,8 +84,9 @@ void ApplyPointLight(ViewSrg::PointLight light, Surface surface, inout LightingD // shadow float litRatio = 1.0; - // How much is back face shadowed, it's set to the reverse of litRatio to share the same default value with thickness, which should be 0 if no shadow map available - float backShadowRatio = 0.0; + // Transmission distance from current light inside object (default non-influential values) + // o_transmission_mode == NONE is not taken into account because GetBackLighting already ignores this case + float transmissionDistance = (o_transmission_mode == TransmissionMode::ThickObject) ? 0.0f : 9999.0f; if (o_enableShadows) { const float3 lightDir = normalize(light.m_position - surface.position); @@ -97,13 +98,13 @@ void ApplyPointLight(ViewSrg::PointLight light, Surface surface, inout LightingD lightDir, surface.vertexNormal); - // Use backShadowRatio to carry thickness from shadow map for thick mode - backShadowRatio = 1.0 - litRatio; if (o_transmission_mode == TransmissionMode::ThickObject) { - backShadowRatio = ProjectedShadow::GetThickness( - shadowIndex, - surface.position); + transmissionDistance = ProjectedShadow::GetThickness(shadowIndex, surface.position); + } + else if (o_transmission_mode == TransmissionMode::ThinObject) + { + transmissionDistance = ProjectedShadow::GetThickness(shadowIndex, surface.position - lightingData.shrinkFactor * surface.normal); } } @@ -111,7 +112,7 @@ void ApplyPointLight(ViewSrg::PointLight light, Surface surface, inout LightingD lightingData.diffuseLighting += GetDiffuseLighting(surface, lightingData, lightIntensity, normalize(posToLight)) * litRatio; // Transmission contribution - lightingData.translucentBackLighting += GetBackLighting(surface, lightingData, lightIntensity, normalize(posToLight), backShadowRatio); + lightingData.translucentBackLighting += GetBackLighting(surface, lightingData, lightIntensity, normalize(posToLight), transmissionDistance); // Adjust the light direcion for specular based on bulb size