Skip to content

Commit 9b13da8

Browse files
authored
Use SafeNormalize for normals sampled from XYZ (non-DXT5nm/ASTCnm) no… (#5356)
* Use SafeNormalize for normals sampled from XYZ (non-DXT5nm/ASTCnm) normal maps * Update changelog Co-authored-by: Florian Penzkofer <florian@unity3d.com>
1 parent 09d5620 commit 9b13da8

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

com.unity.render-pipelines.universal/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
167167
- Fixed an issue where TerrainLit was rendering color lighter than Lit [case 1340751] (https://issuetracker.unity3d.com/product/unity/issues/guid/1340751/)
168168
- Fixed Camera rendering when capture action and post processing present. [case 1350313]
169169
- Fixed artifacts in Speed Tree 8 billboard LODs due to SpeedTree LOD smoothing/crossfading [case 1348407]
170+
- Fix sporadic NaN when using normal maps with XYZ-encoding [case 1351020](https://issuetracker.unity3d.com/issues/android-urp-vulkan-nan-pixels-and-bloom-post-processing-generates-visual-artifacts)
170171
- Support undo of URP Global Settings asset assignation (case 1342987).
171172
- Removed unsupported fields from Presets of Light and Camera [case 1335979].
172173
- Fixed graphical artefact when terrain height map is used with rendering layer mask for lighting.

com.unity.render-pipelines.universal/ShaderLibrary/ShaderVariablesFunctions.hlsl

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,12 +196,21 @@ float3 NormalizeNormalPerVertex(float3 normalWS)
196196

197197
half3 NormalizeNormalPerPixel(half3 normalWS)
198198
{
199+
// With XYZ normal map encoding we sporadically sample normals with near-zero-length causing Inf/NaN
200+
#if defined(UNITY_NO_DXT5nm) && defined(_NORMALMAP)
201+
return SafeNormalize(normalWS);
202+
#else
199203
return normalize(normalWS);
204+
#endif
200205
}
201206

202207
float3 NormalizeNormalPerPixel(float3 normalWS)
203208
{
209+
#if defined(UNITY_NO_DXT5nm) && defined(_NORMALMAP)
210+
return SafeNormalize(normalWS);
211+
#else
204212
return normalize(normalWS);
213+
#endif
205214
}
206215

207216

0 commit comments

Comments
 (0)