Skip to content

Commit 90022e8

Browse files
Fix NaN cause when a 0-length normal is generated and then normalized (#437)
* Avoid to normalize 0-length normals * changelog Co-authored-by: sebastienlagarde <[email protected]>
1 parent 902e579 commit 90022e8

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
@@ -573,6 +573,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
573573
- Fixed SceneView Draw Modes not being properly updated after opening new scene view panels or changing the editor layout.
574574
- VFX: Removed irrelevant queues in render queue selection from HDRP outputs
575575
- VFX: Motion Vector are correctly renderered with MSAA [Case 1240754](https://issuetracker.unity3d.com/product/unity/issues/guid/1240754/)
576+
- Fixed a cause of NaN when a normal of 0-length is generated (usually via shadergraph).
576577

577578
### Changed
578579
- Improve MIP selection for decals on Transparents

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
@@ -99,7 +99,7 @@ public void GenerateNodeFunction(FunctionRegistry registry, GenerationMode gener
9999
s.AppendLine("$precision dHdx = ddx(In);");
100100
s.AppendLine("$precision dHdy = ddy(In);");
101101
s.AppendLine("$precision3 surfGrad = surface * (dHdx*crossY + dHdy*crossX);");
102-
s.AppendLine("Out = normalize(TangentMatrix[2].xyz - (Strength * surfGrad));");
102+
s.AppendLine("Out = SafeNormalize(TangentMatrix[2].xyz - (Strength * surfGrad));");
103103

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

0 commit comments

Comments
 (0)