From bbc3a14a9a09ed17304d64a5c4d49218010c563c Mon Sep 17 00:00:00 2001 From: FrancescoC-Unity Date: Thu, 14 May 2020 17:09:56 +0200 Subject: [PATCH 1/2] Backport changes --- .../Runtime/Material/MaterialUtilities.hlsl | 4 ++-- .../Editor/Data/Nodes/Artistic/Normal/NormalBlendNode.cs | 2 +- .../Editor/Data/Nodes/Artistic/Normal/NormalFromHeightNode.cs | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/com.unity.render-pipelines.high-definition/Runtime/Material/MaterialUtilities.hlsl b/com.unity.render-pipelines.high-definition/Runtime/Material/MaterialUtilities.hlsl index 6f51ff97467..70846c45962 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/Material/MaterialUtilities.hlsl +++ b/com.unity.render-pipelines.high-definition/Runtime/Material/MaterialUtilities.hlsl @@ -32,8 +32,8 @@ void GetNormalWS(FragInputs input, float3 normalTS, out float3 normalWS, float3 normalTS.xy *= flipSign; #endif // _DOUBLESIDED_ON - // We need to normalize as we use mikkt tangent space and this is expected (tangent space is not normalize) - normalWS = normalize(TransformTangentToWorld(normalTS, input.tangentToWorld)); + // We need to normalize as we use mikkt tangent space and this is expected (tangent space is not normalized) + normalWS = SafeNormalize(TransformTangentToWorld(normalTS, input.tangentToWorld)); #endif // SURFACE_GRADIENT } diff --git a/com.unity.shadergraph/Editor/Data/Nodes/Artistic/Normal/NormalBlendNode.cs b/com.unity.shadergraph/Editor/Data/Nodes/Artistic/Normal/NormalBlendNode.cs index 2dc08edb4c1..ce95710c356 100644 --- a/com.unity.shadergraph/Editor/Data/Nodes/Artistic/Normal/NormalBlendNode.cs +++ b/com.unity.shadergraph/Editor/Data/Nodes/Artistic/Normal/NormalBlendNode.cs @@ -58,7 +58,7 @@ static string Unity_NormalBlend( return @" { - Out = normalize($precision3(A.rg + B.rg, A.b * B.b)); + Out = SafeNormalize($precision3(A.rg + B.rg, A.b * B.b)); } "; } diff --git a/com.unity.shadergraph/Editor/Data/Nodes/Artistic/Normal/NormalFromHeightNode.cs b/com.unity.shadergraph/Editor/Data/Nodes/Artistic/Normal/NormalFromHeightNode.cs index 68f58b1e864..302e6e9abb1 100644 --- a/com.unity.shadergraph/Editor/Data/Nodes/Artistic/Normal/NormalFromHeightNode.cs +++ b/com.unity.shadergraph/Editor/Data/Nodes/Artistic/Normal/NormalFromHeightNode.cs @@ -91,7 +91,7 @@ public void GenerateNodeFunction(FunctionRegistry registry, GenerationMode gener s.AppendLine("$precision3 inToNormal = ((((In + ddx(In)) - In) * crossY) + (((In + ddy(In)) - In) * crossX)) * sign(d);"); s.AppendLine("inToNormal.y *= -1.0;"); s.AppendNewLine(); - s.AppendLine("Out = normalize((d * TangentMatrix[2].xyz) - inToNormal);"); + s.AppendLine("Out = SafeNormalize((d * TangentMatrix[2].xyz) - inToNormal);"); if(outputSpace == OutputSpace.Tangent) s.AppendLine("Out = TransformWorldToTangent(Out, TangentMatrix);"); From fd06d844103a844740fac922dbbdab716185dd9b Mon Sep 17 00:00:00 2001 From: FrancescoC-Unity Date: Thu, 14 May 2020 17:12:01 +0200 Subject: [PATCH 2/2] changelog --- com.unity.render-pipelines.high-definition/CHANGELOG.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/com.unity.render-pipelines.high-definition/CHANGELOG.md b/com.unity.render-pipelines.high-definition/CHANGELOG.md index 6b53290ab98..fb8f8ce55f4 100644 --- a/com.unity.render-pipelines.high-definition/CHANGELOG.md +++ b/com.unity.render-pipelines.high-definition/CHANGELOG.md @@ -9,6 +9,9 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. Version Updated The version number for this package has increased due to a version update of a related graphics package. +### Fixed +- Fixed a cause of NaN when a normal of 0-length is generated (usually via shadergraph). + ## [8.1.0] - 2020-04-21 ### Added