diff --git a/com.unity.render-pipelines.high-definition/CHANGELOG.md b/com.unity.render-pipelines.high-definition/CHANGELOG.md index ccb58d598d9..583efc3bd7b 100644 --- a/com.unity.render-pipelines.high-definition/CHANGELOG.md +++ b/com.unity.render-pipelines.high-definition/CHANGELOG.md @@ -148,6 +148,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. - Fixed compilation error of quad overdraw with double sided materials - Fixed screen corruption on xbox when using TAA and Motion Blur with rendergraph. - Fixed UX issue in the graphics compositor related to clear depth and the defaults for new layers, add better tooltips and fix minor bugs (case 1283904) +- Fixed scene visibility not working for custom pass volumes. ### Changed - Preparation pass for RTSSShadows to be supported by render graph. 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) 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)