Skip to content

Commit 681a834

Browse files
Sample distortion mip chain with different safe guard to avoid NaNs (#4105)
* Fix * Actual fix * changelog Co-authored-by: sebastienlagarde <[email protected]>
1 parent 473ded1 commit 681a834

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
147147
- Fixed issue with history buffers when using multiple AOVs (case 1323684).
148148
- Fixed camera preview with multi selection (case 1324126).
149149
- Fixed a NaN generating in Area light code.
150+
- Fix potential NaN on apply distortion pass.
150151

151152
### Changed
152153
- Changed Window/Render Pipeline/HD Render Pipeline Wizard to Window/Rendering/HDRP Wizard

com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/RenderPass/Distortion/ApplyDistortion.shader

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,9 +92,15 @@ Shader "Hidden/HDRP/ApplyDistortion"
9292
float mip = (_ColorPyramidLodCount - 1) * saturate(distortionBlur) * _RoughDistortion;
9393

9494
uint mipCeiled = ceil(mip);
95-
float texelsToClamp = (1u << mipCeiled);
9695

97-
float2 uv = ClampAndScaleUV(distordedUV, _Size.zw, texelsToClamp);
96+
int2 mipSize = int2(_Size.xy) >> mipCeiled;
97+
// Clamp to the max size that is safe on the lowest mip. Note we recompute the full size this way to account for the
98+
// rounding that can happen to sizes (and that _RTHandleScale won't represent correctly as we descend the mip chain)
99+
float2 maxCoord = (mipSize << mipCeiled) * _Size.zw;
100+
// Take of the half pixel for bilinear
101+
maxCoord -= 0.5 * rcp(mipSize);
102+
103+
float2 uv = min(distordedUV, maxCoord) * _RTHandleScale.xy;
98104
float4 sampled = SAMPLE_TEXTURE2D_X_LOD(_ColorPyramidTexture, s_trilinear_clamp_sampler, uv, mip);
99105
return sampled;
100106
}

0 commit comments

Comments
 (0)