From bf27e316c60bd52872a2e173d6b0f20794eae0bc Mon Sep 17 00:00:00 2001 From: FrancescoC-Unity Date: Wed, 13 May 2020 11:42:03 +0200 Subject: [PATCH 1/2] Avoid to normalize 0-length normals --- .../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 4432ea77ca0..97ba705d079 100644 --- a/com.unity.shadergraph/Editor/Data/Nodes/Artistic/Normal/NormalFromHeightNode.cs +++ b/com.unity.shadergraph/Editor/Data/Nodes/Artistic/Normal/NormalFromHeightNode.cs @@ -99,7 +99,7 @@ public void GenerateNodeFunction(FunctionRegistry registry, GenerationMode gener s.AppendLine("$precision dHdx = ddx(In);"); s.AppendLine("$precision dHdy = ddy(In);"); s.AppendLine("$precision3 surfGrad = surface * (dHdx*crossY + dHdy*crossX);"); - s.AppendLine("Out = normalize(TangentMatrix[2].xyz - (Strength * surfGrad));"); + s.AppendLine("Out = SafeNormalize(TangentMatrix[2].xyz - (Strength * surfGrad));"); if(outputSpace == OutputSpace.Tangent) s.AppendLine("Out = TransformWorldToTangent(Out, TangentMatrix);"); From 1da2f106c4f5ca44775ed40511d7f24235c8bffb Mon Sep 17 00:00:00 2001 From: FrancescoC-Unity Date: Wed, 13 May 2020 11:43:34 +0200 Subject: [PATCH 2/2] 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 780473f4aea..c7d8aed762f 100644 --- a/com.unity.render-pipelines.high-definition/CHANGELOG.md +++ b/com.unity.render-pipelines.high-definition/CHANGELOG.md @@ -585,6 +585,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. - Fix error when removing DecalProjector from component contextual menu (case 1243960) - Fixed issue with post process when running in RGBA16 and an object with additive blending is in the scene. - Fixed corrupted values on LayeredLit when using Vertex Color multiply mode to multiply and MSAA is activated. +- Fixed a cause of NaN when a normal of 0-length is generated (usually via shadergraph). ### Changed - Improve MIP selection for decals on Transparents