From 3bbbc88cf26a7a971f78e52c8e94d40ec846b187 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Antoine=20Leli=C3=A8vre?= Date: Thu, 8 Oct 2020 19:36:06 +0200 Subject: [PATCH 1/3] Added scene visibility controls forn custom pass --- .../RenderPass/CustomPass/CustomPassVolume.cs | 45 ++++++++++++++++--- 1 file changed, 38 insertions(+), 7 deletions(-) diff --git a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/RenderPass/CustomPass/CustomPassVolume.cs b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/RenderPass/CustomPass/CustomPassVolume.cs index c8dd973bbb4..ed7ca8c60b7 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/RenderPass/CustomPass/CustomPassVolume.cs +++ b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/RenderPass/CustomPass/CustomPassVolume.cs @@ -49,6 +49,9 @@ public class CustomPassVolume : MonoBehaviour /// The fade value that should be applied to the custom pass effect public float fadeValue { get; private set; } + [System.NonSerialized] + bool visible; + // The current active custom pass volume is simply the smallest overlapping volume with the trigger transform static HashSet m_ActivePassVolumes = new HashSet(); static List m_OverlappingPassVolumes = new List(); @@ -73,19 +76,49 @@ void OnEnable() customPasses.RemoveAll(c => c is null); GetComponents(m_Colliders); Register(this); + +#if UNITY_EDITOR + UnityEditor.SceneVisibilityManager.visibilityChanged -= UpdateCustomPassVolumeVisibility; + UnityEditor.SceneVisibilityManager.visibilityChanged += UpdateCustomPassVolumeVisibility; +#endif } - void OnDisable() => UnRegister(this); + void OnDisable() + { + UnRegister(this); +#if UNITY_EDITOR + UnityEditor.SceneVisibilityManager.visibilityChanged -= UpdateCustomPassVolumeVisibility; +#endif + } void OnDestroy() => CleanupPasses(); - internal bool Execute(ScriptableRenderContext renderContext, CommandBuffer cmd, HDCamera hdCamera, CullingResults cullingResult, SharedRTManager rtManager, CustomPass.RenderTargets targets) +#if UNITY_EDITOR + void UpdateCustomPassVolumeVisibility() { - bool executed = false; + visible = !UnityEditor.SceneVisibilityManager.instance.IsHidden(gameObject); + } +#endif + + bool IsVisible(HDCamera hdCamera) + { + // Scene visibility + if (hdCamera.camera.cameraType == CameraType.SceneView && !visible) + return false; // We never execute volume if the layer is not within the culling layers of the camera if ((hdCamera.volumeLayerMask & (1 << gameObject.layer)) == 0) return false; + + return true; + } + + internal bool Execute(ScriptableRenderContext renderContext, CommandBuffer cmd, HDCamera hdCamera, CullingResults cullingResult, SharedRTManager rtManager, CustomPass.RenderTargets targets) + { + bool executed = false; + + if (!IsVisible(hdCamera)) + return false; Shader.SetGlobalFloat(HDShaderIDs._CustomPassInjectionPoint, (float)injectionPoint); if (injectionPoint == CustomPassInjectionPoint.AfterPostProcess) @@ -107,8 +140,7 @@ internal bool Execute(RenderGraph renderGraph, HDCamera hdCamera, CullingResults { bool executed = false; - // We never execute volume if the layer is not within the culling layers of the camera - if ((hdCamera.volumeLayerMask & (1 << gameObject.layer)) == 0) + if (!IsVisible(hdCamera)) return false; foreach (var pass in customPasses) @@ -127,8 +159,7 @@ internal bool WillExecuteInjectionPoint(HDCamera hdCamera) { bool executed = false; - // We never execute volume if the layer is not within the culling layers of the camera - if ((hdCamera.volumeLayerMask & (1 << gameObject.layer)) == 0) + if (!IsVisible(hdCamera)) return false; foreach (var pass in customPasses) From 2419d406bf97d370db299f85ab2b27edfe2f2eb2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Antoine=20Leli=C3=A8vre?= Date: Thu, 8 Oct 2020 19:36:31 +0200 Subject: [PATCH 2/3] Updated changelog --- com.unity.render-pipelines.high-definition/CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/com.unity.render-pipelines.high-definition/CHANGELOG.md b/com.unity.render-pipelines.high-definition/CHANGELOG.md index 626460da63c..f1785b845a7 100644 --- a/com.unity.render-pipelines.high-definition/CHANGELOG.md +++ b/com.unity.render-pipelines.high-definition/CHANGELOG.md @@ -145,6 +145,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. - Fix issue with alpha output in forward. - Fix compilation issue on Vulkan for shaders using high quality shadows in XR mode. - Fixed wrong error message when fixing DXR resources from Wizard. +- Fixed scene visibility not working for custom pass volumes. ### Changed - Preparation pass for RTSSShadows to be supported by render graph. From c26bed927c0f012a2fa5d392c6e9ee5b6483612c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Antoine=20Leli=C3=A8vre?= Date: Fri, 9 Oct 2020 12:09:04 +0200 Subject: [PATCH 3/3] Fixed doc --- .../Documentation~/Custom-Pass.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/com.unity.render-pipelines.high-definition/Documentation~/Custom-Pass.md b/com.unity.render-pipelines.high-definition/Documentation~/Custom-Pass.md index 4c6a04bb926..d1174921fb5 100644 --- a/com.unity.render-pipelines.high-definition/Documentation~/Custom-Pass.md +++ b/com.unity.render-pipelines.high-definition/Documentation~/Custom-Pass.md @@ -102,7 +102,7 @@ In this snippet, we fetch a lot of useful input data that you might need in your ### DrawRenderers Custom Pass -This pass will allow you to draw a subset of objects that are in the camera view (the result of the camera culling). +This pass will allow you to draw any objects in a certain layer, note that the layer don't require to be visible by the camera to be rendered in this pass. Here is how the inspector for the DrawRenderers pass looks like: ![CustomPassDrawRenderers_Inspector](Images/CustomPassDrawRenderers_Inspector.png)