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 dd40b94414..87dd42fd28 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 @@ -75,8 +75,9 @@ float3 GetBackLighting(Surface surface, LightingData lightingData, float3 lightI // 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)); - // Transmission distance modulated by hardcoded constant (could be exposed as a weight of scattering distance for transmission) - float s = transmissionDistance * 100.0; + // Transmission distance modulated by hardcoded constant C (could be exposed as a weight of scattering distance for transmission) + const float C = 100.0f; + float s = transmissionDistance * C; // Use scattering color to weight thin object transmission color const float3 invScattering = rcp(transmissionParams.xyz); diff --git a/Gems/Atom/Feature/Common/Assets/ShaderLib/Atom/Features/PBR/Lights/CapsuleLight.azsli b/Gems/Atom/Feature/Common/Assets/ShaderLib/Atom/Features/PBR/Lights/CapsuleLight.azsli index bb4be45e5a..1921159c03 100644 --- a/Gems/Atom/Feature/Common/Assets/ShaderLib/Atom/Features/PBR/Lights/CapsuleLight.azsli +++ b/Gems/Atom/Feature/Common/Assets/ShaderLib/Atom/Features/PBR/Lights/CapsuleLight.azsli @@ -135,8 +135,15 @@ void ApplyCapsuleLight(ViewSrg::CapsuleLight light, Surface surface, inout Light float3 closestIntersectionPoint = startPoint + closestT * startToEnd; float3 posToLight = closestIntersectionPoint - surface.position; - // Tranmission contribution - lightingData.translucentBackLighting += GetBackLighting(surface, lightingData, lightIntensity, normalize(posToLight), -1.0f, 0.0f); + // Transmission contribution + // We cannot compute the actual transmission distance so we want to: + // - If transmission mode is thick object -> use transmission thickness parameter instead + // - If transmission mode is thin object -> ignore back lighting + // To detect and apply this behavior in the GetBackLighting function, we need to use a negative transmissionDistance + const float transmissionDistance = -1.0f; + // If the transmissionDistance is ignored then the attenuation distance (only used on thin objects) does not have any influence + const float attenuationDistance = 0.0f; + lightingData.translucentBackLighting += GetBackLighting(surface, lightingData, lightIntensity, normalize(posToLight), transmissionDistance, attenuationDistance); // Calculate the offset from the nearest point on the reflection vector to the nearest point on the capsule light float3 posToClosestPointAlongReflection = dot(posToLight, reflectionDir) * reflectionDir; diff --git a/Gems/Atom/Feature/Common/Assets/ShaderLib/Atom/Features/PBR/Lights/DirectionalLight.azsli b/Gems/Atom/Feature/Common/Assets/ShaderLib/Atom/Features/PBR/Lights/DirectionalLight.azsli index 507b226682..92b90b16ea 100644 --- a/Gems/Atom/Feature/Common/Assets/ShaderLib/Atom/Features/PBR/Lights/DirectionalLight.azsli +++ b/Gems/Atom/Feature/Common/Assets/ShaderLib/Atom/Features/PBR/Lights/DirectionalLight.azsli @@ -20,7 +20,9 @@ void ApplyDirectionalLights(Surface surface, inout LightingData lightingData) float litRatio = 1.0f; float camToSurfDist = distance(ViewSrg::m_worldPosition, surface.position); - // Distance travelled by the light inside the object. If not redefined, it will take mode-specific null behaviors (see GetBackLighting()) + // Distance travelled by the light inside the object. If not redefined to a non-negative value, it will take the following behavior: + // - If transmission mode is thick object -> use transmission thickness parameter instead + // - If transmission mode is thin object -> ignore back lighting float transmissionDistance = -1.0f; if (o_enableShadows && shadowIndex < SceneSrg::m_directionalLightCount) diff --git a/Gems/Atom/Feature/Common/Assets/ShaderLib/Atom/Features/PBR/Lights/DiskLight.azsli b/Gems/Atom/Feature/Common/Assets/ShaderLib/Atom/Features/PBR/Lights/DiskLight.azsli index a98b99452b..4f05caa912 100644 --- a/Gems/Atom/Feature/Common/Assets/ShaderLib/Atom/Features/PBR/Lights/DiskLight.azsli +++ b/Gems/Atom/Feature/Common/Assets/ShaderLib/Atom/Features/PBR/Lights/DiskLight.azsli @@ -77,8 +77,9 @@ void ApplyDiskLight(ViewSrg::DiskLight light, Surface surface, inout LightingDat // shadow float litRatio = 1.0; - - // Distance travelled by the light inside the object. If not redefined, it will take mode-specific null behaviors (see GetBackLighting()) + // Distance travelled by the light inside the object. If not redefined to a non-negative value, it will take the following behavior: + // - If transmission mode is thick object -> use transmission thickness parameter instead + // - If transmission mode is thin object -> ignore back lighting float transmissionDistance = -1.0f; if (o_enableShadows) diff --git a/Gems/Atom/Feature/Common/Assets/ShaderLib/Atom/Features/PBR/Lights/LightTypesCommon.azsli b/Gems/Atom/Feature/Common/Assets/ShaderLib/Atom/Features/PBR/Lights/LightTypesCommon.azsli index dee0d63c79..6718c6f385 100644 --- a/Gems/Atom/Feature/Common/Assets/ShaderLib/Atom/Features/PBR/Lights/LightTypesCommon.azsli +++ b/Gems/Atom/Feature/Common/Assets/ShaderLib/Atom/Features/PBR/Lights/LightTypesCommon.azsli @@ -49,6 +49,16 @@ void AddSampleContribution( float3 intensityRgb = float3(intensity, intensity, intensity); diffuseAcc += GetDiffuseLighting(surface, lightingData, intensityRgb, posToLightSampleDir); - translucentAcc += GetBackLighting(surface, lightingData, intensityRgb, posToLightSampleDir, -1.0f, 0.0f); + + // Transmission contribution + // We cannot compute the actual transmission distance so we want to: + // - If transmission mode is thick object -> use transmission thickness parameter instead + // - If transmission mode is thin object -> ignore back lighting + // To detect and apply this behavior in the GetBackLighting function, we need to use a negative transmissionDistance + const float transmissionDistance = -1.0f; + // If the transmissionDistance is ignored then the attenuation distance (only used on thin objects) does not have any influence + const float attenuationDistance = 0.0f; + translucentAcc += GetBackLighting(surface, lightingData, intensityRgb, posToLightSampleDir, transmissionDistance, attenuationDistance); + specularAcc += GetSpecularLighting(surface, lightingData, intensityRgb, posToLightSampleDir); } 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 ecec0af004..02ae82d0f9 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 @@ -85,7 +85,9 @@ void ApplyPointLight(ViewSrg::PointLight light, Surface surface, inout LightingD // shadow float litRatio = 1.0; - // Distance travelled by the light inside the object. If not redefined, it will take mode-specific null behaviors (see GetBackLighting()) + // Distance travelled by the light inside the object. If not redefined to a non-negative value, it will take the following behavior: + // - If transmission mode is thick object -> use transmission thickness parameter instead + // - If transmission mode is thin object -> ignore back lighting float transmissionDistance = -1.0f; if (o_enableShadows) diff --git a/Gems/Atom/Feature/Common/Assets/ShaderLib/Atom/Features/PBR/Lights/QuadLight.azsli b/Gems/Atom/Feature/Common/Assets/ShaderLib/Atom/Features/PBR/Lights/QuadLight.azsli index f5e148f771..e6ac886fb6 100644 --- a/Gems/Atom/Feature/Common/Assets/ShaderLib/Atom/Features/PBR/Lights/QuadLight.azsli +++ b/Gems/Atom/Feature/Common/Assets/ShaderLib/Atom/Features/PBR/Lights/QuadLight.azsli @@ -148,13 +148,21 @@ void ApplyQuadLight(ViewSrg::QuadLight light, Surface surface, inout LightingDat GetDiffuseLighting(surface, lightingData, intensity, dirToLightCenter) ); + // Transmission contribution + // We cannot compute the actual transmission distance so we want to: + // - If transmission mode is thick object -> use transmission thickness parameter instead + // - If transmission mode is thin object -> ignore back lighting + // To detect and apply this behavior in the GetBackLighting function, we need to use a negative transmissionDistance + const float transmissionDistance = -1.0f; + // If the transmissionDistance is ignored then the attenuation distance (only used on thin objects) does not have any influence + const float attenuationDistance = 0.0f; lightingData.translucentBackLighting += ( - GetBackLighting(surface, lightingData, intensity, p0, -1.0f, 0.0f) + - GetBackLighting(surface, lightingData, intensity, p1, -1.0f, 0.0f) + - GetBackLighting(surface, lightingData, intensity, p2, -1.0f, 0.0f) + - GetBackLighting(surface, lightingData, intensity, p3, -1.0f, 0.0f) + - GetBackLighting(surface, lightingData, intensity, dirToLightCenter, -1.0f, 0.0f) + GetBackLighting(surface, lightingData, intensity, p0, transmissionDistance, attenuationDistance) + + GetBackLighting(surface, lightingData, intensity, p1, transmissionDistance, attenuationDistance) + + GetBackLighting(surface, lightingData, intensity, p2, transmissionDistance, attenuationDistance) + + GetBackLighting(surface, lightingData, intensity, p3, transmissionDistance, attenuationDistance) + + GetBackLighting(surface, lightingData, intensity, dirToLightCenter, transmissionDistance, attenuationDistance) ); // Calculate specular by choosing a single representative point on the light's surface based on the reflection ray