Skip to content

Commit 948f115

Browse files
Custom pass scene visibility (#2136)
* Added scene visibility controls forn custom pass * Updated changelog * Fixed doc Co-authored-by: sebastienlagarde <sebastien@unity3d.com>
1 parent d0f4890 commit 948f115

File tree

3 files changed

+40
-8
lines changed

3 files changed

+40
-8
lines changed

com.unity.render-pipelines.high-definition/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
148148
- Fixed compilation error of quad overdraw with double sided materials
149149
- Fixed screen corruption on xbox when using TAA and Motion Blur with rendergraph.
150150
- 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)
151+
- Fixed scene visibility not working for custom pass volumes.
151152

152153
### Changed
153154
- Preparation pass for RTSSShadows to be supported by render graph.

com.unity.render-pipelines.high-definition/Documentation~/Custom-Pass.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ In this snippet, we fetch a lot of useful input data that you might need in your
102102

103103
### DrawRenderers Custom Pass
104104

105-
This pass will allow you to draw a subset of objects that are in the camera view (the result of the camera culling).
105+
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.
106106
Here is how the inspector for the DrawRenderers pass looks like:
107107

108108
![CustomPassDrawRenderers_Inspector](Images/CustomPassDrawRenderers_Inspector.png)

com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/RenderPass/CustomPass/CustomPassVolume.cs

Lines changed: 38 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,9 @@ public class CustomPassVolume : MonoBehaviour
4949
/// <value>The fade value that should be applied to the custom pass effect</value>
5050
public float fadeValue { get; private set; }
5151

52+
[System.NonSerialized]
53+
bool visible;
54+
5255
// The current active custom pass volume is simply the smallest overlapping volume with the trigger transform
5356
static HashSet<CustomPassVolume> m_ActivePassVolumes = new HashSet<CustomPassVolume>();
5457
static List<CustomPassVolume> m_OverlappingPassVolumes = new List<CustomPassVolume>();
@@ -73,19 +76,49 @@ void OnEnable()
7376
customPasses.RemoveAll(c => c is null);
7477
GetComponents(m_Colliders);
7578
Register(this);
79+
80+
#if UNITY_EDITOR
81+
UnityEditor.SceneVisibilityManager.visibilityChanged -= UpdateCustomPassVolumeVisibility;
82+
UnityEditor.SceneVisibilityManager.visibilityChanged += UpdateCustomPassVolumeVisibility;
83+
#endif
7684
}
7785

78-
void OnDisable() => UnRegister(this);
86+
void OnDisable()
87+
{
88+
UnRegister(this);
89+
#if UNITY_EDITOR
90+
UnityEditor.SceneVisibilityManager.visibilityChanged -= UpdateCustomPassVolumeVisibility;
91+
#endif
92+
}
7993

8094
void OnDestroy() => CleanupPasses();
8195

82-
internal bool Execute(ScriptableRenderContext renderContext, CommandBuffer cmd, HDCamera hdCamera, CullingResults cullingResult, SharedRTManager rtManager, CustomPass.RenderTargets targets)
96+
#if UNITY_EDITOR
97+
void UpdateCustomPassVolumeVisibility()
8398
{
84-
bool executed = false;
99+
visible = !UnityEditor.SceneVisibilityManager.instance.IsHidden(gameObject);
100+
}
101+
#endif
102+
103+
bool IsVisible(HDCamera hdCamera)
104+
{
105+
// Scene visibility
106+
if (hdCamera.camera.cameraType == CameraType.SceneView && !visible)
107+
return false;
85108

86109
// We never execute volume if the layer is not within the culling layers of the camera
87110
if ((hdCamera.volumeLayerMask & (1 << gameObject.layer)) == 0)
88111
return false;
112+
113+
return true;
114+
}
115+
116+
internal bool Execute(ScriptableRenderContext renderContext, CommandBuffer cmd, HDCamera hdCamera, CullingResults cullingResult, SharedRTManager rtManager, CustomPass.RenderTargets targets)
117+
{
118+
bool executed = false;
119+
120+
if (!IsVisible(hdCamera))
121+
return false;
89122

90123
Shader.SetGlobalFloat(HDShaderIDs._CustomPassInjectionPoint, (float)injectionPoint);
91124
if (injectionPoint == CustomPassInjectionPoint.AfterPostProcess)
@@ -107,8 +140,7 @@ internal bool Execute(RenderGraph renderGraph, HDCamera hdCamera, CullingResults
107140
{
108141
bool executed = false;
109142

110-
// We never execute volume if the layer is not within the culling layers of the camera
111-
if ((hdCamera.volumeLayerMask & (1 << gameObject.layer)) == 0)
143+
if (!IsVisible(hdCamera))
112144
return false;
113145

114146
foreach (var pass in customPasses)
@@ -127,8 +159,7 @@ internal bool WillExecuteInjectionPoint(HDCamera hdCamera)
127159
{
128160
bool executed = false;
129161

130-
// We never execute volume if the layer is not within the culling layers of the camera
131-
if ((hdCamera.volumeLayerMask & (1 << gameObject.layer)) == 0)
162+
if (!IsVisible(hdCamera))
132163
return false;
133164

134165
foreach (var pass in customPasses)

0 commit comments

Comments
 (0)