diff --git a/com.unity.render-pipelines.core/CHANGELOG.md b/com.unity.render-pipelines.core/CHANGELOG.md index 839d2922a75..a134bbe919b 100644 --- a/com.unity.render-pipelines.core/CHANGELOG.md +++ b/com.unity.render-pipelines.core/CHANGELOG.md @@ -9,6 +9,10 @@ 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. +### 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.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 ca3bce10cc0..7c335fd512d 100644 --- a/com.unity.render-pipelines.core/Runtime/Textures/RTHandleSystem.cs +++ b/com.unity.render-pipelines.core/Runtime/Textures/RTHandleSystem.cs @@ -195,7 +195,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)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 { @@ -212,10 +214,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 +236,6 @@ public void SetHardwareDynamicResolutionState(bool enableHWDynamicRes) // Create the render texture renderTexture.Create(); } - } } } diff --git a/com.unity.render-pipelines.high-definition/CHANGELOG.md b/com.unity.render-pipelines.high-definition/CHANGELOG.md index 03b3fc863db..a053203cd66 100644 --- a/com.unity.render-pipelines.high-definition/CHANGELOG.md +++ b/com.unity.render-pipelines.high-definition/CHANGELOG.md @@ -24,6 +24,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. ### Fixed - Fixed 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 - Fixed Amplitude -> Min/Max parametrization conversion - Fixed CoatMask block appearing when creating lit master node (case 1264632) - Fixed issue with SceneEV100 debug mode indicator when rescaling the window. 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; 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..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) { 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 75fb6f7f754..171dd1fe5be 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(); }