From 4fba5fcc60e49726e11f94938c7f5de704b2ab0a Mon Sep 17 00:00:00 2001 From: Nico de Poel Date: Mon, 14 Aug 2023 12:58:18 +0200 Subject: [PATCH] Ported over compute shader fixes from the Unity Graphics repository: [PPV2] PPB-6 Disabled compute effects on WebGL and Android OpenGL (#7936) * Disabled compute based effects not supported on WebGL and Android OpenGL * Improved editor warning messages. * Fix editor warning messages. --- .../Editor/Effects/AmbientOcclusionEditor.cs | 10 ++++++-- .../Editor/Effects/AutoExposureEditor.cs | 10 ++++++-- .../Editor/Utils/EditorUtilities.cs | 24 +++++++++++++++++++ .../Runtime/Effects/AmbientOcclusion.cs | 1 + .../Runtime/Effects/AutoExposure.cs | 1 + .../Runtime/Monitors/Monitor.cs | 1 + .../Runtime/Utils/RuntimeUtilities.cs | 15 ++++++++++++ 7 files changed, 58 insertions(+), 4 deletions(-) diff --git a/com.unity.postprocessing/PostProcessing/Editor/Effects/AmbientOcclusionEditor.cs b/com.unity.postprocessing/PostProcessing/Editor/Effects/AmbientOcclusionEditor.cs index c200d59..ecb253d 100644 --- a/com.unity.postprocessing/PostProcessing/Editor/Effects/AmbientOcclusionEditor.cs +++ b/com.unity.postprocessing/PostProcessing/Editor/Effects/AmbientOcclusionEditor.cs @@ -49,8 +49,14 @@ namespace UnityEditor.Rendering.PostProcessing } else if (aoMode == (int)AmbientOcclusionMode.MultiScaleVolumetricObscurance) { - if (!SystemInfo.supportsComputeShaders) - EditorGUILayout.HelpBox("Multi-scale volumetric obscurance requires compute shader support.", MessageType.Warning); + if (!SystemInfo.supportsComputeShaders || EditorUtilities.isTargetingWebGL) + { + EditorGUILayout.HelpBox("Multi-scale volumetric obscurance requires compute shader support which is not available on this platform.", MessageType.Error); + } + else if(EditorUtilities.isTargetingAndroid) + { + EditorGUILayout.HelpBox("Multi-scale volumetric obscurance requires compute shader support (Vulkan) when running on Android.", MessageType.Warning); + } PropertyField(m_ThicknessModifier); PropertyField(m_ZBias); diff --git a/com.unity.postprocessing/PostProcessing/Editor/Effects/AutoExposureEditor.cs b/com.unity.postprocessing/PostProcessing/Editor/Effects/AutoExposureEditor.cs index cdf1e78..559cf51 100644 --- a/com.unity.postprocessing/PostProcessing/Editor/Effects/AutoExposureEditor.cs +++ b/com.unity.postprocessing/PostProcessing/Editor/Effects/AutoExposureEditor.cs @@ -31,8 +31,14 @@ namespace UnityEditor.Rendering.PostProcessing public override void OnInspectorGUI() { - if (!SystemInfo.supportsComputeShaders) - EditorGUILayout.HelpBox("Auto exposure requires compute shader support.", MessageType.Warning); + if (!SystemInfo.supportsComputeShaders || EditorUtilities.isTargetingWebGL) + { + EditorGUILayout.HelpBox("Auto exposure requires compute shader support which is not available on this platform.", MessageType.Error); + } + else if (EditorUtilities.isTargetingAndroid) + { + EditorGUILayout.HelpBox("Auto exposure requires compute shader support (Vulkan) when running on Android.", MessageType.Warning); + } EditorUtilities.DrawHeaderLabel("Exposure"); diff --git a/com.unity.postprocessing/PostProcessing/Editor/Utils/EditorUtilities.cs b/com.unity.postprocessing/PostProcessing/Editor/Utils/EditorUtilities.cs index 276f775..f59f69e 100644 --- a/com.unity.postprocessing/PostProcessing/Editor/Utils/EditorUtilities.cs +++ b/com.unity.postprocessing/PostProcessing/Editor/Utils/EditorUtilities.cs @@ -64,6 +64,30 @@ namespace UnityEditor.Rendering.PostProcessing } } + /// + /// Returns true if the current target is Android, false otherwise. + /// + public static bool isTargetingAndroid + { + get + { + var t = EditorUserBuildSettings.activeBuildTarget; + return t == BuildTarget.Android; + } + } + + /// + /// Returns true if the current target is WebGL, false otherwise. + /// + public static bool isTargetingWebGL + { + get + { + var t = EditorUserBuildSettings.activeBuildTarget; + return t == BuildTarget.WebGL; + } + } + /// /// Returns true if the current target is a console or a mobile, false /// otherwise. diff --git a/com.unity.postprocessing/PostProcessing/Runtime/Effects/AmbientOcclusion.cs b/com.unity.postprocessing/PostProcessing/Runtime/Effects/AmbientOcclusion.cs index db13cec..afffab9 100644 --- a/com.unity.postprocessing/PostProcessing/Runtime/Effects/AmbientOcclusion.cs +++ b/com.unity.postprocessing/PostProcessing/Runtime/Effects/AmbientOcclusion.cs @@ -196,6 +196,7 @@ namespace UnityEngine.Rendering.PostProcessing state &= SystemInfo.supportsComputeShaders && !RuntimeUtilities.isAndroidOpenGL + && !RuntimeUtilities.isWebGL #if UNITY_2023_2_OR_NEWER && SystemInfo.IsFormatSupported(GraphicsFormat.R32_SFloat, GraphicsFormatUsage.Render) && SystemInfo.IsFormatSupported(GraphicsFormat.R16_SFloat, GraphicsFormatUsage.Render) diff --git a/com.unity.postprocessing/PostProcessing/Runtime/Effects/AutoExposure.cs b/com.unity.postprocessing/PostProcessing/Runtime/Effects/AutoExposure.cs index 79b8696..7a0e933 100644 --- a/com.unity.postprocessing/PostProcessing/Runtime/Effects/AutoExposure.cs +++ b/com.unity.postprocessing/PostProcessing/Runtime/Effects/AutoExposure.cs @@ -85,6 +85,7 @@ namespace UnityEngine.Rendering.PostProcessing return enabled.value && SystemInfo.supportsComputeShaders && !RuntimeUtilities.isAndroidOpenGL + && !RuntimeUtilities.isWebGL && RenderTextureFormat.RFloat.IsSupported() && context.resources.computeShaders.autoExposure && context.resources.computeShaders.exposureHistogram; diff --git a/com.unity.postprocessing/PostProcessing/Runtime/Monitors/Monitor.cs b/com.unity.postprocessing/PostProcessing/Runtime/Monitors/Monitor.cs index 4cb3ad9..fbcbb21 100644 --- a/com.unity.postprocessing/PostProcessing/Runtime/Monitors/Monitor.cs +++ b/com.unity.postprocessing/PostProcessing/Runtime/Monitors/Monitor.cs @@ -48,6 +48,7 @@ namespace UnityEngine.Rendering.PostProcessing return requested && SystemInfo.supportsComputeShaders && !RuntimeUtilities.isAndroidOpenGL + && !RuntimeUtilities.isWebGL && ShaderResourcesAvailable(context); } diff --git a/com.unity.postprocessing/PostProcessing/Runtime/Utils/RuntimeUtilities.cs b/com.unity.postprocessing/PostProcessing/Runtime/Utils/RuntimeUtilities.cs index cc706d6..a1d9154 100644 --- a/com.unity.postprocessing/PostProcessing/Runtime/Utils/RuntimeUtilities.cs +++ b/com.unity.postprocessing/PostProcessing/Runtime/Utils/RuntimeUtilities.cs @@ -858,6 +858,21 @@ namespace UnityEngine.Rendering.PostProcessing get { return Application.platform == RuntimePlatform.Android && SystemInfo.graphicsDeviceType != GraphicsDeviceType.Vulkan; } } + /// + /// Returns true if the target platform is WebGL, + /// false otherwise. + /// + public static bool isWebGL + { + get { +#if UNITY_WEBGL + return true; +#else + return false; +#endif + } + } + /// /// Gets the default HDR render texture format for the current target platform. ///