Skip to content

Commit 414f735

Browse files
[Backport 7.x.x] Fix NaN cause when a 0-length normal is generated and then normalized (#485)
* Backport changes * changelog Co-authored-by: sebastienlagarde <[email protected]>
1 parent 0758f7c commit 414f735

File tree

4 files changed

+5
-4
lines changed

4 files changed

+5
-4
lines changed

com.unity.render-pipelines.high-definition/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
8585
- Fixed transparent motion vectors not working when in MSAA.
8686
- VFX: Removed irrelevant queues in render queue selection from HDRP outputs
8787
- VFX: Motion Vector are correctly renderered with MSAA [Case 1240754](https://issuetracker.unity3d.com/product/unity/issues/guid/1240754/)
88+
- Fixed a cause of NaN when a normal of 0-length is generated (usually via shadergraph).
8889

8990
### Changed
9091
- Rejecting history for ray traced reflections based on a threshold evaluated on the neighborhood of the sampled history.

com.unity.render-pipelines.high-definition/Runtime/Material/MaterialUtilities.hlsl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@ void GetNormalWS(FragInputs input, float3 normalTS, out float3 normalWS, float3
3232
normalTS.xy *= flipSign;
3333
#endif // _DOUBLESIDED_ON
3434

35-
// We need to normalize as we use mikkt tangent space and this is expected (tangent space is not normalize)
36-
normalWS = normalize(TransformTangentToWorld(normalTS, input.tangentToWorld));
35+
// We need to normalize as we use mikkt tangent space and this is expected (tangent space is not normalized)
36+
normalWS = SafeNormalize(TransformTangentToWorld(normalTS, input.tangentToWorld));
3737

3838
#endif // SURFACE_GRADIENT
3939
}

com.unity.shadergraph/Editor/Data/Nodes/Artistic/Normal/NormalBlendNode.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ static string Unity_NormalBlend(
5858

5959
return @"
6060
{
61-
Out = normalize($precision3(A.rg + B.rg, A.b * B.b));
61+
Out = SafeNormalize($precision3(A.rg + B.rg, A.b * B.b));
6262
}
6363
";
6464
}

com.unity.shadergraph/Editor/Data/Nodes/Artistic/Normal/NormalFromHeightNode.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ public void GenerateNodeFunction(FunctionRegistry registry, GenerationMode gener
9191
s.AppendLine("$precision3 inToNormal = ((((In + ddx(In)) - In) * crossY) + (((In + ddy(In)) - In) * crossX)) * sign(d);");
9292
s.AppendLine("inToNormal.y *= -1.0;");
9393
s.AppendNewLine();
94-
s.AppendLine("Out = normalize((d * TangentMatrix[2].xyz) - inToNormal);");
94+
s.AppendLine("Out = SafeNormalize((d * TangentMatrix[2].xyz) - inToNormal);");
9595

9696
if(outputSpace == OutputSpace.Tangent)
9797
s.AppendLine("Out = TransformWorldToTangent(Out, TangentMatrix);");

0 commit comments

Comments
 (0)