From 280fe14e490ccd540340a3045b416333642e9acd Mon Sep 17 00:00:00 2001 From: FrancescoC-Unity Date: Tue, 6 Apr 2021 11:34:36 +0200 Subject: [PATCH 1/3] Fix NaN with V1oV2 == -1 --- .../ShaderLibrary/AreaLighting.hlsl | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/com.unity.render-pipelines.core/ShaderLibrary/AreaLighting.hlsl b/com.unity.render-pipelines.core/ShaderLibrary/AreaLighting.hlsl index 368095cdaa1..f1ec8a73326 100644 --- a/com.unity.render-pipelines.core/ShaderLibrary/AreaLighting.hlsl +++ b/com.unity.render-pipelines.core/ShaderLibrary/AreaLighting.hlsl @@ -21,7 +21,8 @@ real3 ComputeEdgeFactor(real3 V1, real3 V2) if (V1oV2 < 0) { // Undo range reduction. - y = PI * rsqrt(saturate(1 - V1oV2 * V1oV2)) - y; + float f = saturate(1 - V1oV2 * V1oV2); + y = PI * (f > 0 ? rsqrt(f) : 0) - y; } return V1xV2 * y; From 23a14b7101531fe131ad9ad875b4fea09f6f56d4 Mon Sep 17 00:00:00 2001 From: FrancescoC-Unity Date: Tue, 6 Apr 2021 11:40:25 +0200 Subject: [PATCH 2/3] Changelog --- com.unity.render-pipelines.high-definition/CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/com.unity.render-pipelines.high-definition/CHANGELOG.md b/com.unity.render-pipelines.high-definition/CHANGELOG.md index 81158c24c67..eb76e2b24df 100644 --- a/com.unity.render-pipelines.high-definition/CHANGELOG.md +++ b/com.unity.render-pipelines.high-definition/CHANGELOG.md @@ -135,6 +135,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. - Fixed a bug with Reflection Probe baking would result in an incorrect baking reusing other's Reflection Probe baking - Fixed volumetric fog being visually chopped or missing when using hardware Dynamic Resolution Scaling. - Fixed generation of the packed depth pyramid when hardware Dynamic Resolution Scaling is enabled. +- Fixed a NaN generating in Area light code. ### Changed - Changed Window/Render Pipeline/HD Render Pipeline Wizard to Window/Rendering/HDRP Wizard From 8c388401091bced875e4b1b208319ce7d7ea9ebb Mon Sep 17 00:00:00 2001 From: FrancescoC-Unity Date: Tue, 6 Apr 2021 18:01:57 +0200 Subject: [PATCH 3/3] Use clamping instead --- .../ShaderLibrary/AreaLighting.hlsl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/com.unity.render-pipelines.core/ShaderLibrary/AreaLighting.hlsl b/com.unity.render-pipelines.core/ShaderLibrary/AreaLighting.hlsl index f1ec8a73326..a936b95de84 100644 --- a/com.unity.render-pipelines.core/ShaderLibrary/AreaLighting.hlsl +++ b/com.unity.render-pipelines.core/ShaderLibrary/AreaLighting.hlsl @@ -21,8 +21,8 @@ real3 ComputeEdgeFactor(real3 V1, real3 V2) if (V1oV2 < 0) { // Undo range reduction. - float f = saturate(1 - V1oV2 * V1oV2); - y = PI * (f > 0 ? rsqrt(f) : 0) - y; + const float epsilon = 1e-5f; + y = PI * (max(epsilon, saturate(1 - V1oV2 * V1oV2))) - y; } return V1xV2 * y;