From cb8d447402e7fcc1d56b387440abce3e94722287 Mon Sep 17 00:00:00 2001 From: etienne cella Date: Thu, 10 Feb 2022 17:23:59 -0500 Subject: [PATCH 1/4] add asset option --- TestProjects/GraphicsTestsURP/Assets/URPAsset.asset | 1 + .../Editor/Inspectors/ClusterRendererInspector.cs | 9 +++++++++ 2 files changed, 10 insertions(+) diff --git a/TestProjects/GraphicsTestsURP/Assets/URPAsset.asset b/TestProjects/GraphicsTestsURP/Assets/URPAsset.asset index b4e255581..ac2766687 100644 --- a/TestProjects/GraphicsTestsURP/Assets/URPAsset.asset +++ b/TestProjects/GraphicsTestsURP/Assets/URPAsset.asset @@ -63,6 +63,7 @@ MonoBehaviour: m_ColorGradingMode: 0 m_ColorGradingLutSize: 32 m_UseFastSRGBLinearConversion: 0 + m_UseScreenCoordOverride: 1 m_ShadowType: 1 m_LocalShadowsSupported: 0 m_LocalShadowsAtlasResolution: 256 diff --git a/source/com.unity.cluster-display.graphics/Editor/Inspectors/ClusterRendererInspector.cs b/source/com.unity.cluster-display.graphics/Editor/Inspectors/ClusterRendererInspector.cs index 11cbca0e0..e2e275d00 100644 --- a/source/com.unity.cluster-display.graphics/Editor/Inspectors/ClusterRendererInspector.cs +++ b/source/com.unity.cluster-display.graphics/Editor/Inspectors/ClusterRendererInspector.cs @@ -2,6 +2,9 @@ using System.Linq; using UnityEngine; using UnityEditor; +#if CLUSTER_DISPLAY_URP +using UnityEngine.Rendering.Universal; +#endif using Object = UnityEngine.Object; namespace Unity.ClusterDisplay.Graphics.Editor @@ -12,6 +15,7 @@ class ClusterRendererInspector : UnityEditor.Editor const string k_NoCamerasMessage = "No cameras are marked to render in this cluster."; const string k_AddCameraScriptText = "Add ClusterCamera component to all cameras"; const string k_NoPolicyMessage = "No projection policy assigned. You can create a new Projection Policy using the \"Create/Cluster Display\" menu."; + const string k_UrpAssetDoesNotSupportScreenCoordOverride = "Universal Render Pipeline asset does not use Screen Coordinates Override. You can fix this by selecting the \"Screen Coordinates Override\" checkbox in the \"Post-processing\" section."; SerializedProperty m_PolicyProp; SerializedProperty m_OverscanProp; @@ -32,6 +36,11 @@ public override void OnInspectorGUI() { #if CLUSTER_DISPLAY_URP RenderFeatureEditorUtils.OnInspectorGUI(); + + if (UniversalRenderPipeline.asset is not { useScreenCoordOverride: true }) + { + EditorGUILayout.HelpBox(k_UrpAssetDoesNotSupportScreenCoordOverride, MessageType.Warning); + } #endif CheckForClusterCameraComponents(); From f9c5fff87480cb012e34128ca92851b40608207c Mon Sep 17 00:00:00 2001 From: etienne cella Date: Thu, 10 Feb 2022 19:12:08 -0500 Subject: [PATCH 2/4] use preprocessor to check stripping --- .../Inspectors/ClusterRendererInspector.cs | 9 ------- .../Editor/ShaderPreprocessor.cs | 27 +++++++++++++++++++ .../Editor/ShaderPreprocessor.cs.meta | 3 +++ 3 files changed, 30 insertions(+), 9 deletions(-) create mode 100644 source/com.unity.cluster-display.graphics/Editor/ShaderPreprocessor.cs create mode 100644 source/com.unity.cluster-display.graphics/Editor/ShaderPreprocessor.cs.meta diff --git a/source/com.unity.cluster-display.graphics/Editor/Inspectors/ClusterRendererInspector.cs b/source/com.unity.cluster-display.graphics/Editor/Inspectors/ClusterRendererInspector.cs index e2e275d00..11cbca0e0 100644 --- a/source/com.unity.cluster-display.graphics/Editor/Inspectors/ClusterRendererInspector.cs +++ b/source/com.unity.cluster-display.graphics/Editor/Inspectors/ClusterRendererInspector.cs @@ -2,9 +2,6 @@ using System.Linq; using UnityEngine; using UnityEditor; -#if CLUSTER_DISPLAY_URP -using UnityEngine.Rendering.Universal; -#endif using Object = UnityEngine.Object; namespace Unity.ClusterDisplay.Graphics.Editor @@ -15,7 +12,6 @@ class ClusterRendererInspector : UnityEditor.Editor const string k_NoCamerasMessage = "No cameras are marked to render in this cluster."; const string k_AddCameraScriptText = "Add ClusterCamera component to all cameras"; const string k_NoPolicyMessage = "No projection policy assigned. You can create a new Projection Policy using the \"Create/Cluster Display\" menu."; - const string k_UrpAssetDoesNotSupportScreenCoordOverride = "Universal Render Pipeline asset does not use Screen Coordinates Override. You can fix this by selecting the \"Screen Coordinates Override\" checkbox in the \"Post-processing\" section."; SerializedProperty m_PolicyProp; SerializedProperty m_OverscanProp; @@ -36,11 +32,6 @@ public override void OnInspectorGUI() { #if CLUSTER_DISPLAY_URP RenderFeatureEditorUtils.OnInspectorGUI(); - - if (UniversalRenderPipeline.asset is not { useScreenCoordOverride: true }) - { - EditorGUILayout.HelpBox(k_UrpAssetDoesNotSupportScreenCoordOverride, MessageType.Warning); - } #endif CheckForClusterCameraComponents(); diff --git a/source/com.unity.cluster-display.graphics/Editor/ShaderPreprocessor.cs b/source/com.unity.cluster-display.graphics/Editor/ShaderPreprocessor.cs new file mode 100644 index 000000000..2e6e9e21b --- /dev/null +++ b/source/com.unity.cluster-display.graphics/Editor/ShaderPreprocessor.cs @@ -0,0 +1,27 @@ +#if CLUSTER_DISPLAY_URP +using System; +using System.Collections.Generic; +using UnityEditor.Build; +using UnityEditor.Rendering; +using UnityEngine; +using UnityEngine.Rendering.Universal; + +namespace Unity.ClusterDisplay.Graphics.Editor +{ + public class ShaderPreprocessor : IPreprocessShaders + { + public int callbackOrder => 0; + + public void OnProcessShader(Shader shader, ShaderSnippetData snippet, IList data) + { + if (UniversalRenderPipeline.asset is not { useScreenCoordOverride: true }) + { + throw new InvalidOperationException( + "Universal Render Pipeline asset does not use Screen Coordinates Override. " + + "You can fix this by selecting the \"Screen Coordinates Override\" checkbox " + + "in the \"Post-processing\" section of the asset."); + } + } + } +} +#endif diff --git a/source/com.unity.cluster-display.graphics/Editor/ShaderPreprocessor.cs.meta b/source/com.unity.cluster-display.graphics/Editor/ShaderPreprocessor.cs.meta new file mode 100644 index 000000000..bdf768b94 --- /dev/null +++ b/source/com.unity.cluster-display.graphics/Editor/ShaderPreprocessor.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 1f0f77e426e64b61924c59e9327571e3 +timeCreated: 1644537944 \ No newline at end of file From 25c756fb558e7367e4ff95eca88c8bd6c48b1e80 Mon Sep 17 00:00:00 2001 From: etienne cella Date: Fri, 11 Feb 2022 10:35:00 -0500 Subject: [PATCH 3/4] preprocessor not public --- .../Editor/ShaderPreprocessor.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/com.unity.cluster-display.graphics/Editor/ShaderPreprocessor.cs b/source/com.unity.cluster-display.graphics/Editor/ShaderPreprocessor.cs index 2e6e9e21b..a6ce07715 100644 --- a/source/com.unity.cluster-display.graphics/Editor/ShaderPreprocessor.cs +++ b/source/com.unity.cluster-display.graphics/Editor/ShaderPreprocessor.cs @@ -8,7 +8,7 @@ namespace Unity.ClusterDisplay.Graphics.Editor { - public class ShaderPreprocessor : IPreprocessShaders + class ShaderPreprocessor : IPreprocessShaders { public int callbackOrder => 0; From 0e9a0d56f2a53dbcbc7c878d7495bcf6c0e5bc65 Mon Sep 17 00:00:00 2001 From: etienne cella Date: Fri, 11 Feb 2022 15:18:18 -0500 Subject: [PATCH 4/4] move to global settings --- .../Editor/ShaderPreprocessor.cs | 39 ++++++++++++++++--- 1 file changed, 34 insertions(+), 5 deletions(-) diff --git a/source/com.unity.cluster-display.graphics/Editor/ShaderPreprocessor.cs b/source/com.unity.cluster-display.graphics/Editor/ShaderPreprocessor.cs index a6ce07715..7504e86d7 100644 --- a/source/com.unity.cluster-display.graphics/Editor/ShaderPreprocessor.cs +++ b/source/com.unity.cluster-display.graphics/Editor/ShaderPreprocessor.cs @@ -1,10 +1,11 @@ #if CLUSTER_DISPLAY_URP using System; using System.Collections.Generic; +using System.Reflection; using UnityEditor.Build; using UnityEditor.Rendering; using UnityEngine; -using UnityEngine.Rendering.Universal; +using UnityEngine.Assertions; namespace Unity.ClusterDisplay.Graphics.Editor { @@ -14,14 +15,42 @@ class ShaderPreprocessor : IPreprocessShaders public void OnProcessShader(Shader shader, ShaderSnippetData snippet, IList data) { - if (UniversalRenderPipeline.asset is not { useScreenCoordOverride: true }) + if (TryGetGlobalSettingsStripScreenCoordOverrideVariants(out var stripped) && stripped) { throw new InvalidOperationException( - "Universal Render Pipeline asset does not use Screen Coordinates Override. " + - "You can fix this by selecting the \"Screen Coordinates Override\" checkbox " + - "in the \"Post-processing\" section of the asset."); + "Screen Coordinates Override shader variants are stripped from Player builds. " + + "You can fix this by unselecting the \"Strip Screen Coord Override Variants\" checkbox " + + "in the Universal Render Pipeline Global Settings."); } } + + static bool TryGetGlobalSettingsStripScreenCoordOverrideVariants(out bool value) + { + try + { + var type = Type.GetType("UnityEngine.Rendering.Universal.UniversalRenderPipelineGlobalSettings, Unity.RenderPipelines.Universal.Runtime"); + Assert.IsNotNull(type); + + var instanceProp = type.GetProperty("instance", BindingFlags.Public | BindingFlags.Static); + Assert.IsNotNull(instanceProp); + + var instance = instanceProp.GetValue(null); + Assert.IsNotNull(instance); + + var settingProp = type.GetProperty("stripScreenCoordOverrideVariants", BindingFlags.Public | BindingFlags.Instance); + Assert.IsNotNull(settingProp); + + value = (bool)settingProp.GetValue(instance); + return true; + } + catch + { + Debug.LogError("Could not read Universal Render Pipeline Global Settings."); + } + + value = true; + return false; + } } } #endif