diff --git a/com.unity.render-pipelines.universal/CHANGELOG.md b/com.unity.render-pipelines.universal/CHANGELOG.md index 86e80922276..5a63c88d639 100644 --- a/com.unity.render-pipelines.universal/CHANGELOG.md +++ b/com.unity.render-pipelines.universal/CHANGELOG.md @@ -36,6 +36,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. - Fixed wrong shader / properties assignement to materials created from 3DsMax 2021 Physical Material. (case 1293576) - Normalized the view direction in Shader Graph to be consistent across Scriptable Render Pieplines. - 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) - Fixed an issue in shaderGraph target where the ShaderPass.hlsl was being included after SHADERPASS was defined - Fixed an issue where Particle Lit shader had an incorrect fallback shader [case 1312459] - Fixed an issue with backbuffer MSAA on Vulkan desktop platforms. diff --git a/com.unity.render-pipelines.universal/Runtime/Passes/CopyDepthPass.cs b/com.unity.render-pipelines.universal/Runtime/Passes/CopyDepthPass.cs index 80c07c0c721..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; @@ -129,7 +138,10 @@ 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; + // 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 = (cameraData.IsCameraProjectionMatrixFlipped()) && !isGameViewFinalTarget; + 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: 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 } diff --git a/com.unity.render-pipelines.universal/Runtime/UniversalRenderer.cs b/com.unity.render-pipelines.universal/Runtime/UniversalRenderer.cs index fe997c3f811..616fc0bef14 100644 --- a/com.unity.render-pipelines.universal/Runtime/UniversalRenderer.cs +++ b/com.unity.render-pipelines.universal/Runtime/UniversalRenderer.cs @@ -60,7 +60,7 @@ private static class Profiling CopyDepthPass m_XRCopyDepthPass; #endif #if UNITY_EDITOR - SceneViewDepthCopyPass m_SceneViewDepthCopyPass; + CopyDepthPass m_FinalDepthCopyPass; #endif RenderTargetHandle m_ActiveCameraColorAttachment; @@ -184,7 +184,7 @@ public UniversalRenderer(UniversalRendererData 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_FinalDepthCopyPass = new CopyDepthPass(RenderPassEvent.AfterRendering + 9, m_CopyDepthMaterial); #endif // RenderTexture format depends on camera and pipeline (HDR, non HDR, etc) @@ -304,6 +304,12 @@ public override void Setup(ScriptableRenderContext context, ref RenderingData re bool isSceneViewCamera = cameraData.isSceneViewCamera; bool requiresDepthTexture = cameraData.requiresDepthTexture || renderPassInputs.requiresDepthTexture || this.actualRenderingMode == RenderingMode.Deferred; +#if UNITY_EDITOR + bool isGizmosEnabled = UnityEditor.Handles.ShouldRenderGizmos(); +#else + bool isGizmosEnabled = false; +#endif + bool mainLightShadows = m_MainLightShadowCasterPass.Setup(ref renderingData); bool additionalLightShadows = m_AdditionalLightsShadowCasterPass.Setup(ref renderingData); bool transparentsNeedSettingsPass = m_TransparentSettingsPass.Setup(ref renderingData); @@ -314,6 +320,7 @@ 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; @@ -329,7 +336,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; @@ -584,12 +591,13 @@ 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); - EnqueuePass(m_SceneViewDepthCopyPass); + m_FinalDepthCopyPass.Setup(m_DepthTexture, RenderTargetHandle.CameraTarget); + m_FinalDepthCopyPass.MssaSamples = 0; + EnqueuePass(m_FinalDepthCopyPass); } #endif }