From 88fdae35744398d3ded402480fb0e595769ea099 Mon Sep 17 00:00:00 2001 From: Pavlos Mavridis Date: Fri, 15 Jan 2021 13:51:45 +0100 Subject: [PATCH 1/2] Fix error in Depth Of Field near radius blur calculation --- com.unity.render-pipelines.high-definition/CHANGELOG.md | 1 + .../PostProcessing/PostProcessSystem.RenderGraph.cs | 5 ++++- .../Runtime/PostProcessing/PostProcessSystem.cs | 9 +++++++-- 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/com.unity.render-pipelines.high-definition/CHANGELOG.md b/com.unity.render-pipelines.high-definition/CHANGELOG.md index d8ffdbf0a79..10f3d56e7ca 100644 --- a/com.unity.render-pipelines.high-definition/CHANGELOG.md +++ b/com.unity.render-pipelines.high-definition/CHANGELOG.md @@ -18,6 +18,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. - Fixed size and spacing of compositor info boxes (case 1305652). - Fixed spacing of UI widgets in the Graphics Compositor (case 1305638). - Fixed undo-redo on layered lit editor. +- Fixed error in Depth Of Field near radius blur calculation (case 1306228). ### Changed - Change the source value for the ray tracing frame index iterator from m_FrameCount to the camera frame count (case 1301356). diff --git a/com.unity.render-pipelines.high-definition/Runtime/PostProcessing/PostProcessSystem.RenderGraph.cs b/com.unity.render-pipelines.high-definition/Runtime/PostProcessing/PostProcessSystem.RenderGraph.cs index bf1869b7ef9..c2b5e7f05cd 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/PostProcessing/PostProcessSystem.RenderGraph.cs +++ b/com.unity.render-pipelines.high-definition/Runtime/PostProcessing/PostProcessSystem.RenderGraph.cs @@ -507,7 +507,10 @@ TextureHandle DepthOfFieldPass(RenderGraph renderGraph, HDCamera hdCamera, Textu passData.fullresCoC = builder.CreateTransientTexture(new TextureDesc(Vector2.one, true, true) { colorFormat = k_CoCFormat, enableRandomWrite = true, name = "Full res CoC" }); - int passCount = Mathf.CeilToInt((passData.parameters.nearMaxBlur + 2f) / 4f); + GetDoResolutionScale(passData.parameters, out float unused, out float resolutionScale); + float actualNearMaxBlur = passData.parameters.nearMaxBlur * resolutionScale; + int passCount = Mathf.CeilToInt((actualNearMaxBlur + 2f) / 4f); + passData.dilationPingPongRT = TextureHandle.nullHandle; if (passCount > 1) { diff --git a/com.unity.render-pipelines.high-definition/Runtime/PostProcessing/PostProcessSystem.cs b/com.unity.render-pipelines.high-definition/Runtime/PostProcessing/PostProcessSystem.cs index 6d6f68999d4..c177bd22a1d 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/PostProcessing/PostProcessSystem.cs +++ b/com.unity.render-pipelines.high-definition/Runtime/PostProcessing/PostProcessSystem.cs @@ -1498,6 +1498,12 @@ DepthOfFieldParameters PrepareDoFParameters(HDCamera camera) return parameters; } + static void GetDoResolutionScale(in DepthOfFieldParameters dofParameters, out float scale, out float resolutionScale) + { + scale = 1f / (float)dofParameters.resolution; + resolutionScale = (dofParameters.camera.actualHeight / 1080f) * (scale * 2f); + } + // // Reference used: // "A Lens and Aperture Camera Model for Synthetic Image Generation" [Potmesil81] @@ -1551,14 +1557,13 @@ static void DoDepthOfField(in DepthOfFieldParameters dofParameters, CommandBuffe float anamorphism = dofParameters.physicalCameraAnamorphism / 4f; float barrelClipping = dofParameters.physicalCameraBarrelClipping / 3f; - float scale = 1f / (float)dofParameters.resolution; + GetDoResolutionScale(dofParameters, out float scale, out float resolutionScale); var screenScale = new Vector2(scale, scale); int targetWidth = Mathf.RoundToInt(dofParameters.camera.actualWidth * scale); int targetHeight = Mathf.RoundToInt(dofParameters.camera.actualHeight * scale); cmd.SetGlobalVector(HDShaderIDs._TargetScale, new Vector4((float)dofParameters.resolution, scale, 0f, 0f)); - float resolutionScale = (dofParameters.camera.actualHeight / 1080f) * (scale * 2f); int farSamples = dofParameters.farSampleCount; int nearSamples = dofParameters.nearSampleCount; From beaee5b697afd04a38cd2529d82eafd094455984 Mon Sep 17 00:00:00 2001 From: Pavlos Mavridis Date: Fri, 15 Jan 2021 13:58:37 +0100 Subject: [PATCH 2/2] Fix typo --- .../Runtime/PostProcessing/PostProcessSystem.RenderGraph.cs | 2 +- .../Runtime/PostProcessing/PostProcessSystem.cs | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/com.unity.render-pipelines.high-definition/Runtime/PostProcessing/PostProcessSystem.RenderGraph.cs b/com.unity.render-pipelines.high-definition/Runtime/PostProcessing/PostProcessSystem.RenderGraph.cs index c2b5e7f05cd..52848d3862b 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/PostProcessing/PostProcessSystem.RenderGraph.cs +++ b/com.unity.render-pipelines.high-definition/Runtime/PostProcessing/PostProcessSystem.RenderGraph.cs @@ -507,7 +507,7 @@ TextureHandle DepthOfFieldPass(RenderGraph renderGraph, HDCamera hdCamera, Textu passData.fullresCoC = builder.CreateTransientTexture(new TextureDesc(Vector2.one, true, true) { colorFormat = k_CoCFormat, enableRandomWrite = true, name = "Full res CoC" }); - GetDoResolutionScale(passData.parameters, out float unused, out float resolutionScale); + GetDoFResolutionScale(passData.parameters, out float unused, out float resolutionScale); float actualNearMaxBlur = passData.parameters.nearMaxBlur * resolutionScale; int passCount = Mathf.CeilToInt((actualNearMaxBlur + 2f) / 4f); diff --git a/com.unity.render-pipelines.high-definition/Runtime/PostProcessing/PostProcessSystem.cs b/com.unity.render-pipelines.high-definition/Runtime/PostProcessing/PostProcessSystem.cs index c177bd22a1d..d1a37c0f329 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/PostProcessing/PostProcessSystem.cs +++ b/com.unity.render-pipelines.high-definition/Runtime/PostProcessing/PostProcessSystem.cs @@ -1498,7 +1498,7 @@ DepthOfFieldParameters PrepareDoFParameters(HDCamera camera) return parameters; } - static void GetDoResolutionScale(in DepthOfFieldParameters dofParameters, out float scale, out float resolutionScale) + static void GetDoFResolutionScale(in DepthOfFieldParameters dofParameters, out float scale, out float resolutionScale) { scale = 1f / (float)dofParameters.resolution; resolutionScale = (dofParameters.camera.actualHeight / 1080f) * (scale * 2f); @@ -1557,7 +1557,7 @@ static void DoDepthOfField(in DepthOfFieldParameters dofParameters, CommandBuffe float anamorphism = dofParameters.physicalCameraAnamorphism / 4f; float barrelClipping = dofParameters.physicalCameraBarrelClipping / 3f; - GetDoResolutionScale(dofParameters, out float scale, out float resolutionScale); + GetDoFResolutionScale(dofParameters, out float scale, out float resolutionScale); var screenScale = new Vector2(scale, scale); int targetWidth = Mathf.RoundToInt(dofParameters.camera.actualWidth * scale); int targetHeight = Mathf.RoundToInt(dofParameters.camera.actualHeight * scale);