diff --git a/com.unity.render-pipelines.high-definition/CHANGELOG.md b/com.unity.render-pipelines.high-definition/CHANGELOG.md index 66282719aa7..a9bde138bff 100644 --- a/com.unity.render-pipelines.high-definition/CHANGELOG.md +++ b/com.unity.render-pipelines.high-definition/CHANGELOG.md @@ -147,6 +147,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. - Fixed issue with history buffers when using multiple AOVs (case 1323684). - Fixed camera preview with multi selection (case 1324126). - Fixed a NaN generating in Area light code. +- Fix potential NaN on apply distortion pass. ### Changed - Changed Window/Render Pipeline/HD Render Pipeline Wizard to Window/Rendering/HDRP Wizard diff --git a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/RenderPass/Distortion/ApplyDistortion.shader b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/RenderPass/Distortion/ApplyDistortion.shader index bf9b5c4fb26..e9826d586b1 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/RenderPass/Distortion/ApplyDistortion.shader +++ b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/RenderPass/Distortion/ApplyDistortion.shader @@ -92,9 +92,15 @@ Shader "Hidden/HDRP/ApplyDistortion" float mip = (_ColorPyramidLodCount - 1) * saturate(distortionBlur) * _RoughDistortion; uint mipCeiled = ceil(mip); - float texelsToClamp = (1u << mipCeiled); - float2 uv = ClampAndScaleUV(distordedUV, _Size.zw, texelsToClamp); + int2 mipSize = int2(_Size.xy) >> mipCeiled; + // Clamp to the max size that is safe on the lowest mip. Note we recompute the full size this way to account for the + // rounding that can happen to sizes (and that _RTHandleScale won't represent correctly as we descend the mip chain) + float2 maxCoord = (mipSize << mipCeiled) * _Size.zw; + // Take of the half pixel for bilinear + maxCoord -= 0.5 * rcp(mipSize); + + float2 uv = min(distordedUV, maxCoord) * _RTHandleScale.xy; float4 sampled = SAMPLE_TEXTURE2D_X_LOD(_ColorPyramidTexture, s_trilinear_clamp_sampler, uv, mip); return sampled; }