Skip to content

Custom pass scene visibility #2136

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions com.unity.render-pipelines.high-definition/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ public class CustomPassVolume : MonoBehaviour
/// <value>The fade value that should be applied to the custom pass effect</value>
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<CustomPassVolume> m_ActivePassVolumes = new HashSet<CustomPassVolume>();
static List<CustomPassVolume> m_OverlappingPassVolumes = new List<CustomPassVolume>();
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand Down