From 6df732d96b5ec0ea72a2cd03ae4f130bafa52084 Mon Sep 17 00:00:00 2001 From: Kenny Tan Date: Tue, 16 Nov 2021 11:30:29 +0800 Subject: [PATCH 1/7] Add override button for users that want to use pixel perfect cam with other renderers --- .../Editor/2D/PixelPerfectCameraEditor.cs | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/com.unity.render-pipelines.universal/Editor/2D/PixelPerfectCameraEditor.cs b/com.unity.render-pipelines.universal/Editor/2D/PixelPerfectCameraEditor.cs index b86157b2a55..b9dbcb1ca02 100644 --- a/com.unity.render-pipelines.universal/Editor/2D/PixelPerfectCameraEditor.cs +++ b/com.unity.render-pipelines.universal/Editor/2D/PixelPerfectCameraEditor.cs @@ -21,7 +21,8 @@ private class Style public GUIContent currentPixelRatio = new GUIContent("Current Pixel Ratio", "Ratio of the rendered Sprites compared to their original size."); public GUIContent runInEditMode = new GUIContent("Run In Edit Mode", "Enable this to preview Camera setting changes in Edit Mode. This will cause constant changes to the Scene while active."); public const string cameraStackingWarning = "Pixel Perfect Camera won't function properly if stacked with another camera."; - public const string nonRenderer2DError = "Pixel Perfect Camera requires a camera using a 2D Renderer."; + public const string nonRenderer2DWarning = "Pixel Perfect Camera requires a camera using a 2D Renderer. Some features, such as Upscale Render Texture, are not supported with other Renderers."; + public static GUIContent overrideUsage = EditorGUIUtility.TrTextContent("Override and Use"); public GUIStyle centeredLabel; @@ -47,6 +48,7 @@ public Style() private Vector2 m_GameViewSize = Vector2.zero; private GUIContent m_CurrentPixelRatioValue; bool m_CameraStacking; + static bool m_OverrideUsage = false; private void LazyInit() { @@ -124,9 +126,14 @@ public override void OnInspectorGUI() { LazyInit(); - if (!UsingRenderer2D()) + if (!UsingRenderer2D() && !m_OverrideUsage) { - EditorGUILayout.HelpBox(Style.nonRenderer2DError, MessageType.Error); + EditorGUILayout.HelpBox(Style.nonRenderer2DWarning, MessageType.Warning); + EditorGUILayout.Space(); + + if (GUILayout.Button(Style.overrideUsage)) + m_OverrideUsage = true; + return; } From d7565d91bb1938ead8e98626e3eb64e1e1fb9e13 Mon Sep 17 00:00:00 2001 From: Kenny Tan Date: Tue, 16 Nov 2021 20:21:59 +0800 Subject: [PATCH 2/7] Only allow override if using SRP --- .../Editor/2D/PixelPerfectCameraEditor.cs | 32 +++++++++++++------ 1 file changed, 23 insertions(+), 9 deletions(-) diff --git a/com.unity.render-pipelines.universal/Editor/2D/PixelPerfectCameraEditor.cs b/com.unity.render-pipelines.universal/Editor/2D/PixelPerfectCameraEditor.cs index b9dbcb1ca02..d7acbb43ee5 100644 --- a/com.unity.render-pipelines.universal/Editor/2D/PixelPerfectCameraEditor.cs +++ b/com.unity.render-pipelines.universal/Editor/2D/PixelPerfectCameraEditor.cs @@ -59,11 +59,23 @@ private void LazyInit() m_CurrentPixelRatioValue = new GUIContent(); } - bool UsingRenderer2D() + UniversalAdditionalCameraData GetCameraData() { PixelPerfectCamera obj = target as PixelPerfectCamera; UniversalAdditionalCameraData cameraData = null; obj?.TryGetComponent(out cameraData); + return cameraData; + } + + bool UsingSRP() + { + var cameraData = GetCameraData(); + return cameraData?.scriptableRenderer != null; + } + + bool UsingRenderer2D() + { + var cameraData = GetCameraData(); if (cameraData != null) { @@ -79,11 +91,8 @@ void CheckForCameraStacking() { m_CameraStacking = false; - PixelPerfectCamera obj = target as PixelPerfectCamera; - UniversalAdditionalCameraData cameraData = null; - obj?.TryGetComponent(out cameraData); - - if (cameraData == null) + var cameraData = GetCameraData(); + if (cameraData == null || cameraData.scriptableRenderer == null) return; if (cameraData.renderType == CameraRenderType.Base) @@ -129,10 +138,15 @@ public override void OnInspectorGUI() if (!UsingRenderer2D() && !m_OverrideUsage) { EditorGUILayout.HelpBox(Style.nonRenderer2DWarning, MessageType.Warning); - EditorGUILayout.Space(); - if (GUILayout.Button(Style.overrideUsage)) - m_OverrideUsage = true; + // Allow override usage if using SRP + if(UsingSRP()) + { + EditorGUILayout.Space(); + if (GUILayout.Button(Style.overrideUsage)) + m_OverrideUsage = true; + + } return; } From 1aa78935214be78e8bde02273a91c12c412cedbb Mon Sep 17 00:00:00 2001 From: Kenny Tan Date: Tue, 16 Nov 2021 22:02:21 +0800 Subject: [PATCH 3/7] Remove Experimental namespace + add assembly for converter --- .../Editor/2D/GameObjectCreation.cs | 2 +- .../Editor/2D/PixelPerfectCameraEditor.cs | 2 +- .../Editor/Camera/UniversalRenderPipelineCameraUI.Drawers.cs | 2 +- .../Editor/Converter/RenderPipelineConverter.cs | 1 + .../Runtime/2D/PixelPerfectCamera.cs | 2 +- 5 files changed, 5 insertions(+), 4 deletions(-) diff --git a/com.unity.render-pipelines.universal/Editor/2D/GameObjectCreation.cs b/com.unity.render-pipelines.universal/Editor/2D/GameObjectCreation.cs index 61491ba7da6..99ef9ba6fee 100644 --- a/com.unity.render-pipelines.universal/Editor/2D/GameObjectCreation.cs +++ b/com.unity.render-pipelines.universal/Editor/2D/GameObjectCreation.cs @@ -1,7 +1,7 @@ using System; using UnityEditor.SceneManagement; using UnityEngine; -using UnityEngine.Experimental.Rendering.Universal; +using UnityEngine.Rendering.Universal; namespace UnityEditor.Rendering.Universal { diff --git a/com.unity.render-pipelines.universal/Editor/2D/PixelPerfectCameraEditor.cs b/com.unity.render-pipelines.universal/Editor/2D/PixelPerfectCameraEditor.cs index d7acbb43ee5..fdb86217c6d 100644 --- a/com.unity.render-pipelines.universal/Editor/2D/PixelPerfectCameraEditor.cs +++ b/com.unity.render-pipelines.universal/Editor/2D/PixelPerfectCameraEditor.cs @@ -21,7 +21,7 @@ private class Style public GUIContent currentPixelRatio = new GUIContent("Current Pixel Ratio", "Ratio of the rendered Sprites compared to their original size."); public GUIContent runInEditMode = new GUIContent("Run In Edit Mode", "Enable this to preview Camera setting changes in Edit Mode. This will cause constant changes to the Scene while active."); public const string cameraStackingWarning = "Pixel Perfect Camera won't function properly if stacked with another camera."; - public const string nonRenderer2DWarning = "Pixel Perfect Camera requires a camera using a 2D Renderer. Some features, such as Upscale Render Texture, are not supported with other Renderers."; + public const string nonRenderer2DWarning = "URP Pixel Perfect Camera requires a camera using a 2D Renderer. Some features, such as Upscale Render Texture, are not supported with other Renderers."; public static GUIContent overrideUsage = EditorGUIUtility.TrTextContent("Override and Use"); public GUIStyle centeredLabel; diff --git a/com.unity.render-pipelines.universal/Editor/Camera/UniversalRenderPipelineCameraUI.Drawers.cs b/com.unity.render-pipelines.universal/Editor/Camera/UniversalRenderPipelineCameraUI.Drawers.cs index 094e2cb5ad6..b6dc165b747 100644 --- a/com.unity.render-pipelines.universal/Editor/Camera/UniversalRenderPipelineCameraUI.Drawers.cs +++ b/com.unity.render-pipelines.universal/Editor/Camera/UniversalRenderPipelineCameraUI.Drawers.cs @@ -61,7 +61,7 @@ public enum Expandable static void DrawerProjection(UniversalRenderPipelineSerializedCamera p, Editor owner) { var camera = p.serializedObject.targetObject as Camera; - bool pixelPerfectEnabled = camera.TryGetComponent(out var pixelPerfectCamera) && pixelPerfectCamera.enabled; + bool pixelPerfectEnabled = camera.TryGetComponent(out var pixelPerfectCamera) && pixelPerfectCamera.enabled; if (pixelPerfectEnabled) EditorGUILayout.HelpBox(Styles.pixelPerfectInfo, MessageType.Info); diff --git a/com.unity.render-pipelines.universal/Editor/Converter/RenderPipelineConverter.cs b/com.unity.render-pipelines.universal/Editor/Converter/RenderPipelineConverter.cs index 445fbbeaeeb..3ce8d64089f 100644 --- a/com.unity.render-pipelines.universal/Editor/Converter/RenderPipelineConverter.cs +++ b/com.unity.render-pipelines.universal/Editor/Converter/RenderPipelineConverter.cs @@ -2,6 +2,7 @@ using System.Runtime.CompilerServices; [assembly: InternalsVisibleTo("PPv2URPConverters")] +[assembly: InternalsVisibleTo("Unity.2D.PixelPerfect.Editor")] namespace UnityEditor.Rendering.Universal.Converters { // Might need to change this name before making it public diff --git a/com.unity.render-pipelines.universal/Runtime/2D/PixelPerfectCamera.cs b/com.unity.render-pipelines.universal/Runtime/2D/PixelPerfectCamera.cs index 7debeb613de..fafbaf705cb 100644 --- a/com.unity.render-pipelines.universal/Runtime/2D/PixelPerfectCamera.cs +++ b/com.unity.render-pipelines.universal/Runtime/2D/PixelPerfectCamera.cs @@ -3,7 +3,7 @@ using UnityEngine.Rendering.Universal; using UnityEngine.Scripting.APIUpdating; -namespace UnityEngine.Experimental.Rendering.Universal +namespace UnityEngine.Rendering.Universal { /// /// The Pixel Perfect Camera component ensures your pixel art remains crisp and clear at different resolutions, and stable in motion. From d2b84ee113e553cdd871e4c5f87a9ebfd1ca9a8d Mon Sep 17 00:00:00 2001 From: Kenny Tan Date: Tue, 16 Nov 2021 22:04:55 +0800 Subject: [PATCH 4/7] Fix format --- .../Editor/2D/PixelPerfectCameraEditor.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/com.unity.render-pipelines.universal/Editor/2D/PixelPerfectCameraEditor.cs b/com.unity.render-pipelines.universal/Editor/2D/PixelPerfectCameraEditor.cs index fdb86217c6d..e2d789d9523 100644 --- a/com.unity.render-pipelines.universal/Editor/2D/PixelPerfectCameraEditor.cs +++ b/com.unity.render-pipelines.universal/Editor/2D/PixelPerfectCameraEditor.cs @@ -139,8 +139,8 @@ public override void OnInspectorGUI() { EditorGUILayout.HelpBox(Style.nonRenderer2DWarning, MessageType.Warning); - // Allow override usage if using SRP - if(UsingSRP()) + // Allow to override usage if using SRP + if (UsingSRP()) { EditorGUILayout.Space(); if (GUILayout.Button(Style.overrideUsage)) From 3cc3b659aa65ee5d28dc21a1a66204f244a3cc36 Mon Sep 17 00:00:00 2001 From: Kenny Tan Date: Wed, 17 Nov 2021 12:24:46 +0800 Subject: [PATCH 5/7] reverse experimental namespace, should be handled in a different PR --- .../Editor/2D/GameObjectCreation.cs | 2 +- .../Editor/Camera/UniversalRenderPipelineCameraUI.Drawers.cs | 2 +- .../Runtime/2D/PixelPerfectCamera.cs | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/com.unity.render-pipelines.universal/Editor/2D/GameObjectCreation.cs b/com.unity.render-pipelines.universal/Editor/2D/GameObjectCreation.cs index 99ef9ba6fee..61491ba7da6 100644 --- a/com.unity.render-pipelines.universal/Editor/2D/GameObjectCreation.cs +++ b/com.unity.render-pipelines.universal/Editor/2D/GameObjectCreation.cs @@ -1,7 +1,7 @@ using System; using UnityEditor.SceneManagement; using UnityEngine; -using UnityEngine.Rendering.Universal; +using UnityEngine.Experimental.Rendering.Universal; namespace UnityEditor.Rendering.Universal { diff --git a/com.unity.render-pipelines.universal/Editor/Camera/UniversalRenderPipelineCameraUI.Drawers.cs b/com.unity.render-pipelines.universal/Editor/Camera/UniversalRenderPipelineCameraUI.Drawers.cs index b6dc165b747..094e2cb5ad6 100644 --- a/com.unity.render-pipelines.universal/Editor/Camera/UniversalRenderPipelineCameraUI.Drawers.cs +++ b/com.unity.render-pipelines.universal/Editor/Camera/UniversalRenderPipelineCameraUI.Drawers.cs @@ -61,7 +61,7 @@ public enum Expandable static void DrawerProjection(UniversalRenderPipelineSerializedCamera p, Editor owner) { var camera = p.serializedObject.targetObject as Camera; - bool pixelPerfectEnabled = camera.TryGetComponent(out var pixelPerfectCamera) && pixelPerfectCamera.enabled; + bool pixelPerfectEnabled = camera.TryGetComponent(out var pixelPerfectCamera) && pixelPerfectCamera.enabled; if (pixelPerfectEnabled) EditorGUILayout.HelpBox(Styles.pixelPerfectInfo, MessageType.Info); diff --git a/com.unity.render-pipelines.universal/Runtime/2D/PixelPerfectCamera.cs b/com.unity.render-pipelines.universal/Runtime/2D/PixelPerfectCamera.cs index fafbaf705cb..7debeb613de 100644 --- a/com.unity.render-pipelines.universal/Runtime/2D/PixelPerfectCamera.cs +++ b/com.unity.render-pipelines.universal/Runtime/2D/PixelPerfectCamera.cs @@ -3,7 +3,7 @@ using UnityEngine.Rendering.Universal; using UnityEngine.Scripting.APIUpdating; -namespace UnityEngine.Rendering.Universal +namespace UnityEngine.Experimental.Rendering.Universal { /// /// The Pixel Perfect Camera component ensures your pixel art remains crisp and clear at different resolutions, and stable in motion. From 1695620705b8ae70d0b6e51ea6e2fff5aecb0a82 Mon Sep 17 00:00:00 2001 From: Kenny Tan Date: Mon, 22 Nov 2021 10:48:38 +0800 Subject: [PATCH 6/7] Remove override box, update changelog --- .../CHANGELOG.md | 1 + .../Editor/2D/PixelPerfectCameraEditor.cs | 23 ++++++++----------- 2 files changed, 10 insertions(+), 14 deletions(-) diff --git a/com.unity.render-pipelines.universal/CHANGELOG.md b/com.unity.render-pipelines.universal/CHANGELOG.md index 7986dc8671f..ae752f06d70 100644 --- a/com.unity.render-pipelines.universal/CHANGELOG.md +++ b/com.unity.render-pipelines.universal/CHANGELOG.md @@ -7,6 +7,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. ## [13.1.1] - 2021-10-04 ### Added +- Added a warning when using Pixel Perfect Camera in SRP without a 2D Renderer and exposed RenderPipelineConverter for 2D Pixel Perfect to URP converter. - Added Depth Texture setting for Overlay Camera. - Added Depth Priming support for Vulkan with MSAA. - Added Shadows and Additional Lights off variants stripping. diff --git a/com.unity.render-pipelines.universal/Editor/2D/PixelPerfectCameraEditor.cs b/com.unity.render-pipelines.universal/Editor/2D/PixelPerfectCameraEditor.cs index e2d789d9523..0cb85a2aeaf 100644 --- a/com.unity.render-pipelines.universal/Editor/2D/PixelPerfectCameraEditor.cs +++ b/com.unity.render-pipelines.universal/Editor/2D/PixelPerfectCameraEditor.cs @@ -22,7 +22,7 @@ private class Style public GUIContent runInEditMode = new GUIContent("Run In Edit Mode", "Enable this to preview Camera setting changes in Edit Mode. This will cause constant changes to the Scene while active."); public const string cameraStackingWarning = "Pixel Perfect Camera won't function properly if stacked with another camera."; public const string nonRenderer2DWarning = "URP Pixel Perfect Camera requires a camera using a 2D Renderer. Some features, such as Upscale Render Texture, are not supported with other Renderers."; - public static GUIContent overrideUsage = EditorGUIUtility.TrTextContent("Override and Use"); + public const string nonRenderer2DError = "URP Pixel Perfect Camera requires a camera using a 2D Renderer."; public GUIStyle centeredLabel; @@ -48,7 +48,6 @@ public Style() private Vector2 m_GameViewSize = Vector2.zero; private GUIContent m_CurrentPixelRatioValue; bool m_CameraStacking; - static bool m_OverrideUsage = false; private void LazyInit() { @@ -92,6 +91,7 @@ void CheckForCameraStacking() m_CameraStacking = false; var cameraData = GetCameraData(); + if (cameraData == null || cameraData.scriptableRenderer == null) return; @@ -135,21 +135,16 @@ public override void OnInspectorGUI() { LazyInit(); - if (!UsingRenderer2D() && !m_OverrideUsage) + if(!UsingSRP()) { - EditorGUILayout.HelpBox(Style.nonRenderer2DWarning, MessageType.Warning); - - // Allow to override usage if using SRP - if (UsingSRP()) - { - EditorGUILayout.Space(); - if (GUILayout.Button(Style.overrideUsage)) - m_OverrideUsage = true; - - } - + EditorGUILayout.HelpBox(Style.nonRenderer2DError, MessageType.Error); return; } + else if (!UsingRenderer2D()) + { + EditorGUILayout.HelpBox(Style.nonRenderer2DWarning, MessageType.Warning); + EditorGUILayout.Space(); + } float originalLabelWidth = EditorGUIUtility.labelWidth; From a827e50e5a5514c455d8be466a815954edea8c9c Mon Sep 17 00:00:00 2001 From: Kenny Tan Date: Tue, 23 Nov 2021 12:22:48 +0800 Subject: [PATCH 7/7] fix formating --- .../Editor/2D/PixelPerfectCameraEditor.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/com.unity.render-pipelines.universal/Editor/2D/PixelPerfectCameraEditor.cs b/com.unity.render-pipelines.universal/Editor/2D/PixelPerfectCameraEditor.cs index 0cb85a2aeaf..a6bd89d2670 100644 --- a/com.unity.render-pipelines.universal/Editor/2D/PixelPerfectCameraEditor.cs +++ b/com.unity.render-pipelines.universal/Editor/2D/PixelPerfectCameraEditor.cs @@ -135,7 +135,7 @@ public override void OnInspectorGUI() { LazyInit(); - if(!UsingSRP()) + if (!UsingSRP()) { EditorGUILayout.HelpBox(Style.nonRenderer2DError, MessageType.Error); return;