From 3986113edbc3b53f2d5e5b1faf8fbc149a211eb0 Mon Sep 17 00:00:00 2001 From: lukasc Date: Wed, 27 Jan 2021 10:17:36 +0200 Subject: [PATCH 1/9] (1302504) Fixed gizmos drawing in game view. Game view now also copies depth buffer when gizmos enabled. --- .../CHANGELOG.md | 1 + .../Runtime/Passes/CopyDepthPass.cs | 7 +- .../Runtime/Passes/SceneViewDepthCopy.cs | 65 ------------------- .../Runtime/Passes/SceneViewDepthCopy.cs.meta | 11 ---- 4 files changed, 7 insertions(+), 77 deletions(-) delete mode 100644 com.unity.render-pipelines.universal/Runtime/Passes/SceneViewDepthCopy.cs delete mode 100644 com.unity.render-pipelines.universal/Runtime/Passes/SceneViewDepthCopy.cs.meta diff --git a/com.unity.render-pipelines.universal/CHANGELOG.md b/com.unity.render-pipelines.universal/CHANGELOG.md index 9b05a898984..5f39d91973c 100644 --- a/com.unity.render-pipelines.universal/CHANGELOG.md +++ b/com.unity.render-pipelines.universal/CHANGELOG.md @@ -19,6 +19,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. - Fixed an issue where soft particles did not work with orthographic projection. [case 1294607](https://issuetracker.unity3d.com/product/unity/issues/guid/1294607/) - Fixed wrong shader / properties assignement to materials created from 3DsMax 2021 Physical Material. (case 1293576) - Fixed material upgrader to run in batch mode [case 1305402] +- Fixed gizmos drawing in game view. [case 1302504](https://issuetracker.unity3d.com/issues/urp-handles-with-set-ztest-do-not-respect-depth-sorting-in-the-game-view) ## [11.0.0] - 2020-10-21 ### Added diff --git a/com.unity.render-pipelines.universal/Runtime/Passes/CopyDepthPass.cs b/com.unity.render-pipelines.universal/Runtime/Passes/CopyDepthPass.cs index 80c07c0c721..6f26b349ec2 100644 --- a/com.unity.render-pipelines.universal/Runtime/Passes/CopyDepthPass.cs +++ b/com.unity.render-pipelines.universal/Runtime/Passes/CopyDepthPass.cs @@ -129,7 +129,12 @@ public override void Execute(ScriptableRenderContext context, ref RenderingData // scaleBias.y = scale // scaleBias.z = bias // scaleBias.w = unused - float flipSign = (cameraData.IsCameraProjectionMatrixFlipped()) ? -1.0f : 1.0f; + bool renderingToBackBufferTarget = ScriptableRenderer.current.cameraColorTarget == BuiltinRenderTextureType.CameraTarget; + bool renderingToTexture = !renderingToBackBufferTarget || cameraData.camera.targetTexture != null; + // In game view final target acts as back buffer were target is not flipped + bool isGameViewFinalTarget = (cameraData.cameraType == CameraType.Game && destination == RenderTargetHandle.CameraTarget); + bool yflip = (renderingToTexture && !isGameViewFinalTarget) && SystemInfo.graphicsUVStartsAtTop; + float flipSign = yflip ? -1.0f : 1.0f; Vector4 scaleBiasRt = (flipSign < 0.0f) ? new Vector4(flipSign, 1.0f, -1.0f, 1.0f) : new Vector4(flipSign, 0.0f, 1.0f, 1.0f); diff --git a/com.unity.render-pipelines.universal/Runtime/Passes/SceneViewDepthCopy.cs b/com.unity.render-pipelines.universal/Runtime/Passes/SceneViewDepthCopy.cs deleted file mode 100644 index f85bfba5bf2..00000000000 --- a/com.unity.render-pipelines.universal/Runtime/Passes/SceneViewDepthCopy.cs +++ /dev/null @@ -1,65 +0,0 @@ -namespace UnityEngine.Rendering.Universal -{ - internal class SceneViewDepthCopyPass : ScriptableRenderPass - { - private RenderTargetHandle source { get; set; } - - Material m_CopyDepthMaterial; - const string m_ProfilerTag = "Copy Depth for Scene View"; - private static readonly ProfilingSampler m_ProfilingSampler = new ProfilingSampler(m_ProfilerTag); - - public SceneViewDepthCopyPass(RenderPassEvent evt, Material copyDepthMaterial) - { - base.profilingSampler = new ProfilingSampler(nameof(SceneViewDepthCopyPass)); - m_CopyDepthMaterial = copyDepthMaterial; - renderPassEvent = evt; - } - - public void Setup(RenderTargetHandle source) - { - this.source = source; - } - - /// - public override void Execute(ScriptableRenderContext context, ref RenderingData renderingData) - { - if (m_CopyDepthMaterial == null) - { - Debug.LogErrorFormat("Missing {0}. {1} render pass will not execute. Check for missing reference in the renderer resources.", m_CopyDepthMaterial, GetType().Name); - return; - } - - // Restore Render target for additional editor rendering. - // Note: Scene view camera always perform depth prepass - CommandBuffer cmd = CommandBufferPool.Get(); - using (new ProfilingScope(cmd, m_ProfilingSampler)) - { - CoreUtils.SetRenderTarget(cmd, BuiltinRenderTextureType.CameraTarget); - cmd.SetGlobalTexture("_CameraDepthAttachment", source.Identifier()); - cmd.EnableShaderKeyword(ShaderKeywordStrings.DepthNoMsaa); - cmd.DisableShaderKeyword(ShaderKeywordStrings.DepthMsaa2); - cmd.DisableShaderKeyword(ShaderKeywordStrings.DepthMsaa4); - cmd.DisableShaderKeyword(ShaderKeywordStrings.DepthMsaa8); - // Blit has logic to flip projection matrix when rendering to render texture. - // Currently the y-flip is handled in CopyDepthPass.hlsl by checking _ProjectionParams.x - // If you replace this Blit with a Draw* that sets projection matrix double check - // to also update shader. - // scaleBias.x = flipSign - // scaleBias.y = scale - // scaleBias.z = bias - // scaleBias.w = unused - ref CameraData cameraData = ref renderingData.cameraData; - float flipSign = (cameraData.IsCameraProjectionMatrixFlipped()) ? -1.0f : 1.0f; - Vector4 scaleBiasRt = (flipSign < 0.0f) - ? new Vector4(flipSign, 1.0f, -1.0f, 1.0f) - : new Vector4(flipSign, 0.0f, 1.0f, 1.0f); - cmd.SetGlobalVector(ShaderPropertyId.scaleBiasRt, scaleBiasRt); - - cmd.DrawMesh(RenderingUtils.fullscreenMesh, Matrix4x4.identity, m_CopyDepthMaterial); - } - - context.ExecuteCommandBuffer(cmd); - CommandBufferPool.Release(cmd); - } - } -} diff --git a/com.unity.render-pipelines.universal/Runtime/Passes/SceneViewDepthCopy.cs.meta b/com.unity.render-pipelines.universal/Runtime/Passes/SceneViewDepthCopy.cs.meta deleted file mode 100644 index a6be8de38ad..00000000000 --- a/com.unity.render-pipelines.universal/Runtime/Passes/SceneViewDepthCopy.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: b83946bd07350434993ad588e9c521af -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: From bd3235ad1e376341d49e8733e3666839f9d20ed7 Mon Sep 17 00:00:00 2001 From: lukasc Date: Wed, 27 Jan 2021 10:40:10 +0200 Subject: [PATCH 2/9] (1302504) Fixed gizmos drawing in game view v2 --- .../Runtime/ForwardRenderer.cs | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/com.unity.render-pipelines.universal/Runtime/ForwardRenderer.cs b/com.unity.render-pipelines.universal/Runtime/ForwardRenderer.cs index ea8e5156f70..ccf9f52481c 100644 --- a/com.unity.render-pipelines.universal/Runtime/ForwardRenderer.cs +++ b/com.unity.render-pipelines.universal/Runtime/ForwardRenderer.cs @@ -60,7 +60,7 @@ private static class Profiling CopyDepthPass m_XRCopyDepthPass; #endif #if UNITY_EDITOR - SceneViewDepthCopyPass m_SceneViewDepthCopyPass; + CopyDepthPass m_SceneViewDepthCopyPass; #endif RenderTargetHandle m_ActiveCameraColorAttachment; @@ -184,7 +184,7 @@ public ForwardRenderer(ForwardRendererData data) : base(data) m_FinalBlitPass = new FinalBlitPass(RenderPassEvent.AfterRendering + 1, m_BlitMaterial); #if UNITY_EDITOR - m_SceneViewDepthCopyPass = new SceneViewDepthCopyPass(RenderPassEvent.AfterRendering + 9, m_CopyDepthMaterial); + m_SceneViewDepthCopyPass = new CopyDepthPass(RenderPassEvent.AfterRendering + 9, m_CopyDepthMaterial); #endif // RenderTexture format depends on camera and pipeline (HDR, non HDR, etc) @@ -299,6 +299,7 @@ public override void Setup(ScriptableRenderContext context, ref RenderingData re // TODO: We could cache and generate the LUT before rendering the stack bool generateColorGradingLUT = cameraData.postProcessEnabled && m_PostProcessPasses.isCreated; bool isSceneViewCamera = cameraData.isSceneViewCamera; + bool isGizmosEnabled = UnityEditor.Handles.ShouldRenderGizmos(); bool requiresDepthTexture = cameraData.requiresDepthTexture || renderPassInputs.requiresDepthTexture || this.actualRenderingMode == RenderingMode.Deferred; bool mainLightShadows = m_MainLightShadowCasterPass.Setup(ref renderingData); @@ -311,9 +312,11 @@ public override void Setup(ScriptableRenderContext context, ref RenderingData re // - Render passes require it bool requiresDepthPrepass = requiresDepthTexture && !CanCopyDepth(ref renderingData.cameraData); requiresDepthPrepass |= isSceneViewCamera; + requiresDepthPrepass |= isGizmosEnabled; requiresDepthPrepass |= isPreviewCamera; requiresDepthPrepass |= renderPassInputs.requiresDepthPrepass; requiresDepthPrepass |= renderPassInputs.requiresNormalsTexture; + //requiresDepthPrepass = false; // Current aim of depth prepass is to generate a copy of depth buffer, it is NOT to prime depth buffer and reduce overdraw on non-mobile platforms. // When deferred renderer is enabled, depth buffer is already accessible so depth prepass is not needed. @@ -326,7 +329,7 @@ public override void Setup(ScriptableRenderContext context, ref RenderingData re // The copying of depth should normally happen after rendering opaques. // But if we only require it for post processing or the scene camera then we do it after rendering transparent objects - m_CopyDepthPass.renderPassEvent = (!requiresDepthTexture && (applyPostProcessing || isSceneViewCamera)) ? RenderPassEvent.AfterRenderingTransparents : RenderPassEvent.AfterRenderingOpaques; + m_CopyDepthPass.renderPassEvent = (!requiresDepthTexture && (applyPostProcessing || isSceneViewCamera || isGizmosEnabled)) ? RenderPassEvent.AfterRenderingTransparents : RenderPassEvent.AfterRenderingOpaques; createColorTexture |= RequiresIntermediateColorTexture(ref cameraData); createColorTexture |= renderPassInputs.requiresColorTexture; createColorTexture &= !isPreviewCamera; @@ -581,11 +584,11 @@ public override void Setup(ScriptableRenderContext context, ref RenderingData re } #if UNITY_EDITOR - if (isSceneViewCamera) + if (isSceneViewCamera || isGizmosEnabled) { // Scene view camera should always resolve target (not stacked) Assertions.Assert.IsTrue(lastCameraInTheStack, "Editor camera must resolve target upon finish rendering."); - m_SceneViewDepthCopyPass.Setup(m_DepthTexture); + m_SceneViewDepthCopyPass.Setup(m_DepthTexture, RenderTargetHandle.CameraTarget); EnqueuePass(m_SceneViewDepthCopyPass); } #endif From 3b00bb0c1309c2d4e773a3425be0e6cb760dbbab Mon Sep 17 00:00:00 2001 From: lukasc Date: Wed, 27 Jan 2021 10:40:40 +0200 Subject: [PATCH 3/9] Removing leftover --- com.unity.render-pipelines.universal/Runtime/ForwardRenderer.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/com.unity.render-pipelines.universal/Runtime/ForwardRenderer.cs b/com.unity.render-pipelines.universal/Runtime/ForwardRenderer.cs index ccf9f52481c..046d672e018 100644 --- a/com.unity.render-pipelines.universal/Runtime/ForwardRenderer.cs +++ b/com.unity.render-pipelines.universal/Runtime/ForwardRenderer.cs @@ -316,7 +316,6 @@ public override void Setup(ScriptableRenderContext context, ref RenderingData re requiresDepthPrepass |= isPreviewCamera; requiresDepthPrepass |= renderPassInputs.requiresDepthPrepass; requiresDepthPrepass |= renderPassInputs.requiresNormalsTexture; - //requiresDepthPrepass = false; // Current aim of depth prepass is to generate a copy of depth buffer, it is NOT to prime depth buffer and reduce overdraw on non-mobile platforms. // When deferred renderer is enabled, depth buffer is already accessible so depth prepass is not needed. From bf34c2526fe65aea48d69d2e794e12753bde7218 Mon Sep 17 00:00:00 2001 From: lukasc Date: Wed, 27 Jan 2021 10:41:16 +0200 Subject: [PATCH 4/9] Adding sampler to gizmos drawing --- .../Runtime/ScriptableRenderer.cs | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/com.unity.render-pipelines.universal/Runtime/ScriptableRenderer.cs b/com.unity.render-pipelines.universal/Runtime/ScriptableRenderer.cs index 790390bf3a5..49bd326e593 100644 --- a/com.unity.render-pipelines.universal/Runtime/ScriptableRenderer.cs +++ b/com.unity.render-pipelines.universal/Runtime/ScriptableRenderer.cs @@ -32,6 +32,7 @@ private static class Profiling public static readonly ProfilingSampler clearRenderingState = new ProfilingSampler($"{k_Name}.{nameof(ClearRenderingState)}"); public static readonly ProfilingSampler internalStartRendering = new ProfilingSampler($"{k_Name}.{nameof(InternalStartRendering)}"); public static readonly ProfilingSampler internalFinishRendering = new ProfilingSampler($"{k_Name}.{nameof(InternalFinishRendering)}"); + public static readonly ProfilingSampler drawGizmos = new ProfilingSampler($"{nameof(DrawGizmos)}"); public static class RenderBlock { @@ -1005,8 +1006,20 @@ static void SetRenderTarget(CommandBuffer cmd, RenderTargetIdentifier[] colorAtt void DrawGizmos(ScriptableRenderContext context, Camera camera, GizmoSubset gizmoSubset) { #if UNITY_EDITOR - if (UnityEditor.Handles.ShouldRenderGizmos()) + if (!UnityEditor.Handles.ShouldRenderGizmos()) + return; + + CommandBuffer cmd = CommandBufferPool.Get(); + using (new ProfilingScope(cmd, Profiling.drawGizmos)) + { + context.ExecuteCommandBuffer(cmd); + cmd.Clear(); + context.DrawGizmos(camera, gizmoSubset); + } + + context.ExecuteCommandBuffer(cmd); + CommandBufferPool.Release(cmd); #endif } From fa0a5684b472b47ce08c61eaeaf463dbcbbf1361 Mon Sep 17 00:00:00 2001 From: lukasc Date: Wed, 27 Jan 2021 10:45:09 +0200 Subject: [PATCH 5/9] Renaming property from m_SceneViewDepthCopyPass to m_FinalDepthCopyPass --- .../Runtime/ForwardRenderer.cs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/com.unity.render-pipelines.universal/Runtime/ForwardRenderer.cs b/com.unity.render-pipelines.universal/Runtime/ForwardRenderer.cs index 046d672e018..6dd8c1b4c88 100644 --- a/com.unity.render-pipelines.universal/Runtime/ForwardRenderer.cs +++ b/com.unity.render-pipelines.universal/Runtime/ForwardRenderer.cs @@ -60,7 +60,7 @@ private static class Profiling CopyDepthPass m_XRCopyDepthPass; #endif #if UNITY_EDITOR - CopyDepthPass m_SceneViewDepthCopyPass; + CopyDepthPass m_FinalDepthCopyPass; #endif RenderTargetHandle m_ActiveCameraColorAttachment; @@ -184,7 +184,7 @@ public ForwardRenderer(ForwardRendererData data) : base(data) m_FinalBlitPass = new FinalBlitPass(RenderPassEvent.AfterRendering + 1, m_BlitMaterial); #if UNITY_EDITOR - m_SceneViewDepthCopyPass = new CopyDepthPass(RenderPassEvent.AfterRendering + 9, m_CopyDepthMaterial); + m_FinalDepthCopyPass = new CopyDepthPass(RenderPassEvent.AfterRendering + 9, m_CopyDepthMaterial); #endif // RenderTexture format depends on camera and pipeline (HDR, non HDR, etc) @@ -587,8 +587,8 @@ public override void Setup(ScriptableRenderContext context, ref RenderingData re { // Scene view camera should always resolve target (not stacked) Assertions.Assert.IsTrue(lastCameraInTheStack, "Editor camera must resolve target upon finish rendering."); - m_SceneViewDepthCopyPass.Setup(m_DepthTexture, RenderTargetHandle.CameraTarget); - EnqueuePass(m_SceneViewDepthCopyPass); + m_FinalDepthCopyPass.Setup(m_DepthTexture, RenderTargetHandle.CameraTarget); + EnqueuePass(m_FinalDepthCopyPass); } #endif } From 9af61632370810ca420dcfbdc2f1d50e1c84d702 Mon Sep 17 00:00:00 2001 From: lukasc Date: Wed, 27 Jan 2021 11:33:07 +0200 Subject: [PATCH 6/9] Changing back to IsCameraProjectionMatrixFlipped for simplicity --- .../Runtime/Passes/CopyDepthPass.cs | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/com.unity.render-pipelines.universal/Runtime/Passes/CopyDepthPass.cs b/com.unity.render-pipelines.universal/Runtime/Passes/CopyDepthPass.cs index 6f26b349ec2..456e27fbf3e 100644 --- a/com.unity.render-pipelines.universal/Runtime/Passes/CopyDepthPass.cs +++ b/com.unity.render-pipelines.universal/Runtime/Passes/CopyDepthPass.cs @@ -129,11 +129,9 @@ public override void Execute(ScriptableRenderContext context, ref RenderingData // scaleBias.y = scale // scaleBias.z = bias // scaleBias.w = unused - bool renderingToBackBufferTarget = ScriptableRenderer.current.cameraColorTarget == BuiltinRenderTextureType.CameraTarget; - bool renderingToTexture = !renderingToBackBufferTarget || cameraData.camera.targetTexture != null; // In game view final target acts as back buffer were target is not flipped bool isGameViewFinalTarget = (cameraData.cameraType == CameraType.Game && destination == RenderTargetHandle.CameraTarget); - bool yflip = (renderingToTexture && !isGameViewFinalTarget) && SystemInfo.graphicsUVStartsAtTop; + bool yflip = (cameraData.IsCameraProjectionMatrixFlipped()) && !isGameViewFinalTarget; float flipSign = yflip ? -1.0f : 1.0f; Vector4 scaleBiasRt = (flipSign < 0.0f) ? new Vector4(flipSign, 1.0f, -1.0f, 1.0f) From 5e9eec8c4abccb661122972aaf99fb6e3f6e4fd1 Mon Sep 17 00:00:00 2001 From: lukasc Date: Wed, 27 Jan 2021 15:40:28 +0200 Subject: [PATCH 7/9] Adding guards for editor only code --- .../Runtime/ForwardRenderer.cs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/com.unity.render-pipelines.universal/Runtime/ForwardRenderer.cs b/com.unity.render-pipelines.universal/Runtime/ForwardRenderer.cs index 6dd8c1b4c88..65e451da723 100644 --- a/com.unity.render-pipelines.universal/Runtime/ForwardRenderer.cs +++ b/com.unity.render-pipelines.universal/Runtime/ForwardRenderer.cs @@ -299,9 +299,13 @@ public override void Setup(ScriptableRenderContext context, ref RenderingData re // TODO: We could cache and generate the LUT before rendering the stack bool generateColorGradingLUT = cameraData.postProcessEnabled && m_PostProcessPasses.isCreated; bool isSceneViewCamera = cameraData.isSceneViewCamera; - bool isGizmosEnabled = UnityEditor.Handles.ShouldRenderGizmos(); bool requiresDepthTexture = cameraData.requiresDepthTexture || renderPassInputs.requiresDepthTexture || this.actualRenderingMode == RenderingMode.Deferred; + bool isGizmosEnabled = false; +#if UNITY_EDITOR + UnityEditor.Handles.ShouldRenderGizmos(); +#endif + bool mainLightShadows = m_MainLightShadowCasterPass.Setup(ref renderingData); bool additionalLightShadows = m_AdditionalLightsShadowCasterPass.Setup(ref renderingData); bool transparentsNeedSettingsPass = m_TransparentSettingsPass.Setup(ref renderingData); From 6739d03bf25dffc0fa2494d672baaef7e7030053 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lukas=20Chodosevi=C4=8Dius?= Date: Thu, 4 Feb 2021 16:35:34 +0200 Subject: [PATCH 8/9] Fixing isGizmosEnabled to check ShouldRenderGizmos in editor --- .../Runtime/ForwardRenderer.cs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/com.unity.render-pipelines.universal/Runtime/ForwardRenderer.cs b/com.unity.render-pipelines.universal/Runtime/ForwardRenderer.cs index 65e451da723..65cd58f73c8 100644 --- a/com.unity.render-pipelines.universal/Runtime/ForwardRenderer.cs +++ b/com.unity.render-pipelines.universal/Runtime/ForwardRenderer.cs @@ -300,10 +300,11 @@ public override void Setup(ScriptableRenderContext context, ref RenderingData re bool generateColorGradingLUT = cameraData.postProcessEnabled && m_PostProcessPasses.isCreated; bool isSceneViewCamera = cameraData.isSceneViewCamera; bool requiresDepthTexture = cameraData.requiresDepthTexture || renderPassInputs.requiresDepthTexture || this.actualRenderingMode == RenderingMode.Deferred; - - bool isGizmosEnabled = false; + #if UNITY_EDITOR - UnityEditor.Handles.ShouldRenderGizmos(); + bool isGizmosEnabled = UnityEditor.Handles.ShouldRenderGizmos(); +#else + bool isGizmosEnabled = false; #endif bool mainLightShadows = m_MainLightShadowCasterPass.Setup(ref renderingData); From 29f5ab31fd5ac7e8e5bbba7ec348e15d0ce16210 Mon Sep 17 00:00:00 2001 From: lukasc Date: Thu, 4 Feb 2021 17:32:25 +0200 Subject: [PATCH 9/9] Mixing depth copy for gizmos to work with mssa --- .../Runtime/ForwardRenderer.cs | 1 + .../Runtime/Passes/CopyDepthPass.cs | 13 +++++++++++-- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/com.unity.render-pipelines.universal/Runtime/ForwardRenderer.cs b/com.unity.render-pipelines.universal/Runtime/ForwardRenderer.cs index 528c280c4e9..9e4dad5ce75 100644 --- a/com.unity.render-pipelines.universal/Runtime/ForwardRenderer.cs +++ b/com.unity.render-pipelines.universal/Runtime/ForwardRenderer.cs @@ -596,6 +596,7 @@ public override void Setup(ScriptableRenderContext context, ref RenderingData re // Scene view camera should always resolve target (not stacked) Assertions.Assert.IsTrue(lastCameraInTheStack, "Editor camera must resolve target upon finish rendering."); m_FinalDepthCopyPass.Setup(m_DepthTexture, RenderTargetHandle.CameraTarget); + m_FinalDepthCopyPass.MssaSamples = 0; EnqueuePass(m_FinalDepthCopyPass); } #endif diff --git a/com.unity.render-pipelines.universal/Runtime/Passes/CopyDepthPass.cs b/com.unity.render-pipelines.universal/Runtime/Passes/CopyDepthPass.cs index 456e27fbf3e..ee2442f1842 100644 --- a/com.unity.render-pipelines.universal/Runtime/Passes/CopyDepthPass.cs +++ b/com.unity.render-pipelines.universal/Runtime/Passes/CopyDepthPass.cs @@ -16,6 +16,7 @@ public class CopyDepthPass : ScriptableRenderPass private RenderTargetHandle source { get; set; } private RenderTargetHandle destination { get; set; } internal bool AllocateRT { get; set; } + internal int MssaSamples { get; set; } Material m_CopyDepthMaterial; public CopyDepthPass(RenderPassEvent evt, Material copyDepthMaterial) { @@ -35,6 +36,7 @@ public void Setup(RenderTargetHandle source, RenderTargetHandle destination) this.source = source; this.destination = destination; this.AllocateRT = !destination.HasInternalRenderTargetId(); + this.MssaSamples = -1; } public override void OnCameraSetup(CommandBuffer cmd, ref RenderingData renderingData) @@ -62,8 +64,15 @@ public override void Execute(ScriptableRenderContext context, ref RenderingData CommandBuffer cmd = CommandBufferPool.Get(); using (new ProfilingScope(cmd, ProfilingSampler.Get(URPProfileId.CopyDepth))) { - RenderTextureDescriptor descriptor = renderingData.cameraData.cameraTargetDescriptor; - int cameraSamples = descriptor.msaaSamples; + int cameraSamples = 0; + + if (MssaSamples == -1) + { + RenderTextureDescriptor descriptor = renderingData.cameraData.cameraTargetDescriptor; + cameraSamples = descriptor.msaaSamples; + } + else + cameraSamples = MssaSamples; CameraData cameraData = renderingData.cameraData;