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/ShaderPreprocessor.cs b/source/com.unity.cluster-display.graphics/Editor/ShaderPreprocessor.cs new file mode 100644 index 000000000..7504e86d7 --- /dev/null +++ b/source/com.unity.cluster-display.graphics/Editor/ShaderPreprocessor.cs @@ -0,0 +1,56 @@ +#if CLUSTER_DISPLAY_URP +using System; +using System.Collections.Generic; +using System.Reflection; +using UnityEditor.Build; +using UnityEditor.Rendering; +using UnityEngine; +using UnityEngine.Assertions; + +namespace Unity.ClusterDisplay.Graphics.Editor +{ + class ShaderPreprocessor : IPreprocessShaders + { + public int callbackOrder => 0; + + public void OnProcessShader(Shader shader, ShaderSnippetData snippet, IList data) + { + if (TryGetGlobalSettingsStripScreenCoordOverrideVariants(out var stripped) && stripped) + { + throw new InvalidOperationException( + "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 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