From 2f6e32f53c0ed99003edd0eb1f7be978d40fa152 Mon Sep 17 00:00:00 2001 From: Jeannette Yu Date: Thu, 13 Aug 2020 04:29:39 -0700 Subject: [PATCH 1/6] RTHandleSystem changes to ensure useDynamicScale is updated on SceneView, and uses RTHandleScale to scale to fullres viewport to fix banding issues on game view resize --- .../Runtime/Textures/RTHandleSystem.cs | 23 ++++++++++++++++--- .../Runtime/Textures/RTHandles.cs | 21 +++++++++++++++++ .../Runtime/RenderPipeline/Camera/HDCamera.cs | 2 +- 3 files changed, 42 insertions(+), 4 deletions(-) diff --git a/com.unity.render-pipelines.core/Runtime/Textures/RTHandleSystem.cs b/com.unity.render-pipelines.core/Runtime/Textures/RTHandleSystem.cs index ca3bce10cc0..09756428ae9 100644 --- a/com.unity.render-pipelines.core/Runtime/Textures/RTHandleSystem.cs +++ b/com.unity.render-pipelines.core/Runtime/Textures/RTHandleSystem.cs @@ -164,6 +164,20 @@ public void SetReferenceSize(int width, int height, MSAASamples msaaSamples) /// Number of MSAA samples for multisampled textures for subsequent rendering. /// If set to true, the new width and height will override the old values even if they are not bigger. public void SetReferenceSize(int width, int height, MSAASamples msaaSamples, bool reset) + { + SetReferenceSize(width, height, msaaSamples, false, m_MaxWidths, m_MaxHeights); + } + + /// + /// Sets the reference rendering size for subsequent rendering for the RTHandle System + /// + /// Reference rendering width for subsequent rendering. + /// Reference rendering height for subsequent rendering. + /// Number of MSAA samples for multisampled textures for subsequent rendering. + /// If set to true, the new width and height will override the old values even if they are not bigger. + /// Full resolution width for upscaling to final viewport. + /// Full resolution height for upscaling to final viewport. + public void SetReferenceSize(int width, int height, MSAASamples msaaSamples, bool reset, int finalWidth, int finalHeight) { m_RTHandleProperties.previousViewportSize = m_RTHandleProperties.currentViewportSize; m_RTHandleProperties.previousRenderTargetSize = m_RTHandleProperties.currentRenderTargetSize; @@ -195,7 +209,9 @@ public void SetReferenceSize(int width, int height, MSAASamples msaaSamples, boo if (DynamicResolutionHandler.instance.HardwareDynamicResIsEnabled()) { - m_RTHandleProperties.rtHandleScale = new Vector4(1.0f, 1.0f, 1.0f, 1.0f); + float xScale = (float)finalWidth / GetMaxWidth(); + float yScale = (float)finalHeight / GetMaxHeight(); + m_RTHandleProperties.rtHandleScale = new Vector4(xScale, yScale, m_RTHandleProperties.rtHandleScale.x, m_RTHandleProperties.rtHandleScale.y); } else { @@ -212,10 +228,12 @@ public void SetReferenceSize(int width, int height, MSAASamples msaaSamples, boo /// State of hardware dynamic resolution. public void SetHardwareDynamicResolutionState(bool enableHWDynamicRes) { - if(enableHWDynamicRes != m_HardwareDynamicResRequested && m_AutoSizedRTsArray != null) + if(enableHWDynamicRes != m_HardwareDynamicResRequested) { m_HardwareDynamicResRequested = enableHWDynamicRes; + Array.Resize(ref m_AutoSizedRTsArray, m_AutoSizedRTs.Count); + m_AutoSizedRTs.CopyTo(m_AutoSizedRTsArray); for (int i = 0, c = m_AutoSizedRTsArray.Length; i < c; ++i) { var rth = m_AutoSizedRTsArray[i]; @@ -232,7 +250,6 @@ public void SetHardwareDynamicResolutionState(bool enableHWDynamicRes) // Create the render texture renderTexture.Create(); } - } } } diff --git a/com.unity.render-pipelines.core/Runtime/Textures/RTHandles.cs b/com.unity.render-pipelines.core/Runtime/Textures/RTHandles.cs index e9d669e3aed..9bc5cab9152 100644 --- a/com.unity.render-pipelines.core/Runtime/Textures/RTHandles.cs +++ b/com.unity.render-pipelines.core/Runtime/Textures/RTHandles.cs @@ -315,6 +315,27 @@ MSAASamples msaaSamples ); } + /// + /// Sets the reference rendering size for subsequent rendering for the RTHandle System + /// + /// Reference rendering width for subsequent rendering. + /// Reference rendering height for subsequent rendering. + /// Number of MSAA samples for multisampled textures for subsequent rendering. + /// If set to true, the new width and height will override the old values even if they are not bigger. + /// Full resolution width for upscaling to final viewport. + /// Full resolution height for upscaling to final viewport. + public static void SetReferenceSize(int width, int height, MSAASamples msaaSamples, bool reset, int finalWidth, int finalHeight) + { + s_DefaultInstance.SetReferenceSize( + width, + height, + msaaSamples, + reset, + finalWidth, + finalHeight + ); + } + /// /// Reset the reference size of the system and reallocate all textures. /// diff --git a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Camera/HDCamera.cs b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Camera/HDCamera.cs index 6b6ac873486..b2d6b0d19c7 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Camera/HDCamera.cs +++ b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Camera/HDCamera.cs @@ -524,7 +524,7 @@ internal void Update(FrameSettings currentFrameSettings, HDRenderPipeline hdrp, /// Set the RTHandle scale to the actual camera size (can be scaled) internal void SetReferenceSize() { - RTHandles.SetReferenceSize(actualWidth, actualHeight, msaaSamples); + RTHandles.SetReferenceSize(actualWidth, actualHeight, msaaSamples, false, (int)finalViewport.width, (int)finalViewport.height); m_HistoryRTSystem.SwapAndSetReferenceSize(actualWidth, actualHeight, msaaSamples); } From a193eef04bd83d6dd2dbdc3b22952091d0f7b469 Mon Sep 17 00:00:00 2001 From: Jeannette Yu Date: Wed, 19 Aug 2020 14:45:28 -0700 Subject: [PATCH 2/6] Fixed black bars in Lanczos upsampling by adding epsilon in divde by 0 cases --- .../Runtime/PostProcessing/Shaders/RTUpscale.hlsl | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/com.unity.render-pipelines.high-definition/Runtime/PostProcessing/Shaders/RTUpscale.hlsl b/com.unity.render-pipelines.high-definition/Runtime/PostProcessing/Shaders/RTUpscale.hlsl index d38bd169851..1f23bd85f94 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/PostProcessing/Shaders/RTUpscale.hlsl +++ b/com.unity.render-pipelines.high-definition/Runtime/PostProcessing/Shaders/RTUpscale.hlsl @@ -43,8 +43,8 @@ void WeightedAcc(CTYPE value, float weight, inout CTYPE accumulated, inout float // TODO: Revisit derivation. CTYPE Lanczos(TEXTURE2D_X(_InputTexture), float2 inUV) { - // Lanczos 3 - const float a = 3.0; + const float epsilon = 0.0000000001; + const float a = 3.0; // Lanczos 3 float2 TexSize = _ScreenSize.xy * (_RTHandleScale.xy); float2 TexelSize = rcp(TexSize); @@ -67,7 +67,6 @@ CTYPE Lanczos(TEXTURE2D_X(_InputTexture), float2 inUV) cosXPIOverA *= sqrtA; float2 sinXCosXOverA = cosXPIOverA * sinXPI; - // Find UVs float2 UV_2 = (center - 2) * TexelSize; float2 UV_1 = (center - 1) * TexelSize; @@ -82,9 +81,13 @@ CTYPE Lanczos(TEXTURE2D_X(_InputTexture), float2 inUV) float2 xMin4 = x - 4.0; float2 xMin5 = x - 5.0; + // By the definition of x, only xMin2 should possibly = 0 + xMin2 = (xMin2 == 0) * epsilon + xMin2; // if (xMin2 == 0), then xMin2 = epsilon + float2 w14 = -sinLancz + sinXCosXOverA; float2 w25 = -sinLancz - sinXCosXOverA; + float2 weight0 = sinLancz / (x * x); float2 weight1 = w14 / (xMin1 * xMin1); float2 weight2 = w25 / (xMin2 * xMin2); @@ -93,13 +96,14 @@ CTYPE Lanczos(TEXTURE2D_X(_InputTexture), float2 inUV) float2 weight5 = w25 / (xMin5 * xMin5); float2 weight23 = weight2 + weight3; // Readapt since we are leveraging bilinear. - + weight23 = (weight23 == 0) * epsilon + weight23; // if (weight23 == 0), then weight23 = epsilon // Correct UV to account for bilinear adjustment UV0 += (weight3 / weight23) * TexelSize; #ifndef ENABLE_ALPHA float4 accumulation = 0; + // Corners are dropped (similarly to what Jimenez suggested for Bicubic) accumulation += float4(Bilinear(_InputTexture, float2(UV_2.x, UV0.y)), 1) * weight0.x * weight23.y; accumulation += float4(Bilinear(_InputTexture, float2(UV_1.x, UV_1.y)), 1) * weight1.x * weight1.y; From e5dca7a2f8e191b7b75871c349988c90dcd6ea96 Mon Sep 17 00:00:00 2001 From: Jeannette Yu Date: Thu, 20 Aug 2020 01:08:00 -0700 Subject: [PATCH 3/6] Updated changelogs --- com.unity.render-pipelines.core/CHANGELOG.md | 7 +++++++ com.unity.render-pipelines.high-definition/CHANGELOG.md | 2 ++ 2 files changed, 9 insertions(+) diff --git a/com.unity.render-pipelines.core/CHANGELOG.md b/com.unity.render-pipelines.core/CHANGELOG.md index 839d2922a75..9ad89a9784a 100644 --- a/com.unity.render-pipelines.core/CHANGELOG.md +++ b/com.unity.render-pipelines.core/CHANGELOG.md @@ -9,6 +9,13 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. Version Updated The version number for this package has increased due to a version update of a related graphics package. +### Added +- Add new overload of SetReferenceSize for RTHandles and RTHandleSystem. + +### Fixed +- Fixed the scene view to scale correctly when hardware dynamic resolution is enabled (case 1158661) +- Fixed game view artifacts on resizing when hardware dynamic resolution was enabled + ## [10.0.0] - 2019-06-10 ### Added diff --git a/com.unity.render-pipelines.high-definition/CHANGELOG.md b/com.unity.render-pipelines.high-definition/CHANGELOG.md index c92c1629f89..c0cbd189d07 100644 --- a/com.unity.render-pipelines.high-definition/CHANGELOG.md +++ b/com.unity.render-pipelines.high-definition/CHANGELOG.md @@ -12,6 +12,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. ### Fixed - Fix several issues with physically-based DoF (TAA ghosting of the CoC buffer, smooth layer transitions, etc) - Fixed GPU hang on D3D12 on xbox. +- Fixed game view artifacts on resizing when hardware dynamic resolution was enabled +- Fixed black line artifacts occurring when Lanczos upsampling was set for dynamic resolution ### Changed - Preparation pass for RTSSShadows to be supported by render graph. From fca2b71ccfb1c3b54db3660a995d3cfc4ace759a Mon Sep 17 00:00:00 2001 From: Jeannette Yu Date: Thu, 20 Aug 2020 02:42:12 -0700 Subject: [PATCH 4/6] Re-enable hardware dynamic resolution for Metal --- .../Runtime/RenderPipeline/HDRenderPipeline.cs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/HDRenderPipeline.cs b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/HDRenderPipeline.cs index cb10ee72371..58c2e0b4e48 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/HDRenderPipeline.cs +++ b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/HDRenderPipeline.cs @@ -1613,8 +1613,7 @@ protected override void Render(ScriptableRenderContext renderContext, Camera[] c // We are in a case where the platform does not support hw dynamic resolution, so we force the software fallback. // TODO: Expose the graphics caps info on whether the platform supports hw dynamic resolution or not. // Temporarily disable HW Dynamic resolution on metal until the problems we have with it are fixed - bool isMetal = (SystemInfo.graphicsDeviceType == GraphicsDeviceType.Metal); - if (isMetal || (dynResHandler.RequestsHardwareDynamicResolution() && cameraRequestedDynamicRes && !camera.allowDynamicResolution)) + if (dynResHandler.RequestsHardwareDynamicResolution() && cameraRequestedDynamicRes && !camera.allowDynamicResolution) { dynResHandler.ForceSoftwareFallback(); } From 294205792fd23f1a731ba11d21710832fdb05518 Mon Sep 17 00:00:00 2001 From: FrancescoC-Unity Date: Fri, 4 Sep 2020 12:54:25 +0200 Subject: [PATCH 5/6] A bit of change to the API --- .../Common/DynamicResolutionHandler.cs | 6 ++++++ .../Runtime/Textures/RTHandleSystem.cs | 18 ++-------------- .../Runtime/Textures/RTHandles.cs | 21 ------------------- .../Runtime/RenderPipeline/Camera/HDCamera.cs | 4 +++- 4 files changed, 11 insertions(+), 38 deletions(-) diff --git a/com.unity.render-pipelines.core/Runtime/Common/DynamicResolutionHandler.cs b/com.unity.render-pipelines.core/Runtime/Common/DynamicResolutionHandler.cs index 3746fe009a6..964f85edeed 100644 --- a/com.unity.render-pipelines.core/Runtime/Common/DynamicResolutionHandler.cs +++ b/com.unity.render-pipelines.core/Runtime/Common/DynamicResolutionHandler.cs @@ -53,6 +53,12 @@ public class DynamicResolutionHandler /// public DynamicResUpscaleFilter filter { get; set; } + /// + /// The viewport of the final buffer. This is likely the resolution the dynamic resolution starts from before any scaling. Note this is NOT the target resolution the rendering will happen in + /// but the resolution the scaled rendered result will be upscaled to. + /// + public Vector2Int finalViewport { get; set; } + private DynamicResolutionType type; diff --git a/com.unity.render-pipelines.core/Runtime/Textures/RTHandleSystem.cs b/com.unity.render-pipelines.core/Runtime/Textures/RTHandleSystem.cs index 09756428ae9..7c335fd512d 100644 --- a/com.unity.render-pipelines.core/Runtime/Textures/RTHandleSystem.cs +++ b/com.unity.render-pipelines.core/Runtime/Textures/RTHandleSystem.cs @@ -164,20 +164,6 @@ public void SetReferenceSize(int width, int height, MSAASamples msaaSamples) /// Number of MSAA samples for multisampled textures for subsequent rendering. /// If set to true, the new width and height will override the old values even if they are not bigger. public void SetReferenceSize(int width, int height, MSAASamples msaaSamples, bool reset) - { - SetReferenceSize(width, height, msaaSamples, false, m_MaxWidths, m_MaxHeights); - } - - /// - /// Sets the reference rendering size for subsequent rendering for the RTHandle System - /// - /// Reference rendering width for subsequent rendering. - /// Reference rendering height for subsequent rendering. - /// Number of MSAA samples for multisampled textures for subsequent rendering. - /// If set to true, the new width and height will override the old values even if they are not bigger. - /// Full resolution width for upscaling to final viewport. - /// Full resolution height for upscaling to final viewport. - public void SetReferenceSize(int width, int height, MSAASamples msaaSamples, bool reset, int finalWidth, int finalHeight) { m_RTHandleProperties.previousViewportSize = m_RTHandleProperties.currentViewportSize; m_RTHandleProperties.previousRenderTargetSize = m_RTHandleProperties.currentRenderTargetSize; @@ -209,8 +195,8 @@ public void SetReferenceSize(int width, int height, MSAASamples msaaSamples, boo if (DynamicResolutionHandler.instance.HardwareDynamicResIsEnabled()) { - float xScale = (float)finalWidth / GetMaxWidth(); - float yScale = (float)finalHeight / GetMaxHeight(); + float xScale = (float)DynamicResolutionHandler.instance.finalViewport.x / GetMaxWidth(); + float yScale = (float)DynamicResolutionHandler.instance.finalViewport.y / GetMaxHeight(); m_RTHandleProperties.rtHandleScale = new Vector4(xScale, yScale, m_RTHandleProperties.rtHandleScale.x, m_RTHandleProperties.rtHandleScale.y); } else diff --git a/com.unity.render-pipelines.core/Runtime/Textures/RTHandles.cs b/com.unity.render-pipelines.core/Runtime/Textures/RTHandles.cs index 9bc5cab9152..e9d669e3aed 100644 --- a/com.unity.render-pipelines.core/Runtime/Textures/RTHandles.cs +++ b/com.unity.render-pipelines.core/Runtime/Textures/RTHandles.cs @@ -315,27 +315,6 @@ MSAASamples msaaSamples ); } - /// - /// Sets the reference rendering size for subsequent rendering for the RTHandle System - /// - /// Reference rendering width for subsequent rendering. - /// Reference rendering height for subsequent rendering. - /// Number of MSAA samples for multisampled textures for subsequent rendering. - /// If set to true, the new width and height will override the old values even if they are not bigger. - /// Full resolution width for upscaling to final viewport. - /// Full resolution height for upscaling to final viewport. - public static void SetReferenceSize(int width, int height, MSAASamples msaaSamples, bool reset, int finalWidth, int finalHeight) - { - s_DefaultInstance.SetReferenceSize( - width, - height, - msaaSamples, - reset, - finalWidth, - finalHeight - ); - } - /// /// Reset the reference size of the system and reallocate all textures. /// diff --git a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Camera/HDCamera.cs b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Camera/HDCamera.cs index b2d6b0d19c7..9feab8438fb 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Camera/HDCamera.cs +++ b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Camera/HDCamera.cs @@ -493,6 +493,8 @@ internal void Update(FrameSettings currentFrameSettings, HDRenderPipeline hdrp, actualHeight = Math.Max((int)finalViewport.size.y, 1); } + DynamicResolutionHandler.instance.finalViewport = new Vector2Int((int)finalViewport.width, (int)finalViewport.height); + Vector2Int nonScaledViewport = new Vector2Int(actualWidth, actualHeight); if (isMainGameView) { @@ -524,7 +526,7 @@ internal void Update(FrameSettings currentFrameSettings, HDRenderPipeline hdrp, /// Set the RTHandle scale to the actual camera size (can be scaled) internal void SetReferenceSize() { - RTHandles.SetReferenceSize(actualWidth, actualHeight, msaaSamples, false, (int)finalViewport.width, (int)finalViewport.height); + RTHandles.SetReferenceSize(actualWidth, actualHeight, msaaSamples); m_HistoryRTSystem.SwapAndSetReferenceSize(actualWidth, actualHeight, msaaSamples); } From 58b716cabeb163c609afb469edfe98e67d8cb4d7 Mon Sep 17 00:00:00 2001 From: FrancescoC-Unity Date: Fri, 4 Sep 2020 12:55:40 +0200 Subject: [PATCH 6/6] changelog update --- com.unity.render-pipelines.core/CHANGELOG.md | 3 --- 1 file changed, 3 deletions(-) diff --git a/com.unity.render-pipelines.core/CHANGELOG.md b/com.unity.render-pipelines.core/CHANGELOG.md index 9ad89a9784a..a134bbe919b 100644 --- a/com.unity.render-pipelines.core/CHANGELOG.md +++ b/com.unity.render-pipelines.core/CHANGELOG.md @@ -9,9 +9,6 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. Version Updated The version number for this package has increased due to a version update of a related graphics package. -### Added -- Add new overload of SetReferenceSize for RTHandles and RTHandleSystem. - ### Fixed - Fixed the scene view to scale correctly when hardware dynamic resolution is enabled (case 1158661) - Fixed game view artifacts on resizing when hardware dynamic resolution was enabled