Skip to content
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
3 changes: 3 additions & 0 deletions com.unity.render-pipelines.core/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
Version Updated
The version number for this package has increased due to a version update of a related graphics package.

### Added
- New `IVolumeDebugSettings` interface and `VolumeDebugSettings<T>` class that stores the information for the Volumes Debug Panel.

## [12.0.0] - 2021-01-11

### Added
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using UnityEditor;

namespace UnityEngine.Rendering
{
/// <summary>
/// Volume debug settings.
/// </summary>
public interface IVolumeDebugSettings
{
/// <summary>Selected component.</summary>
int selectedComponent { get; set; }

/// <summary>Current camera to debug.</summary>
Camera selectedCamera { get; }

/// <summary>Returns the collection of registered cameras.</summary>
IEnumerable<Camera> cameras { get; }

/// <summary>Selected camera index.</summary>
int selectedCameraIndex { get; set; }

/// <summary>Selected camera volume stack.</summary>
VolumeStack selectedCameraVolumeStack { get; }

/// <summary>Selected camera volume layer mask.</summary>
LayerMask selectedCameraLayerMask { get; }

/// <summary>Selected camera volume position.</summary>
Vector3 selectedCameraPosition { get; }

/// <summary>Type of the current component to debug.</summary>
Type selectedComponentType { get; set; }

/// <summary>
/// Obtains the Volumes
/// </summary>
/// <returns>The list of <see cref="Volume"/></returns>
Volume[] GetVolumes();

/// <summary>
/// Return if the <see cref="Volume"/> has influence
/// </summary>
/// <param name="volume"><see cref="Volume"/> to check the influence</param>
/// <returns>If the volume has influence</returns>
bool VolumeHasInfluence(Volume volume);

/// <summary>
/// Refreshes the volumes, fetches the stored volumes on the panel
/// </summary>
/// <param name="newVolumes">The list of <see cref="Volume"/> to refresh</param>
/// <returns>If the volumes have been refreshed</returns>
bool RefreshVolumes(Volume[] newVolumes);

/// <summary>
/// Obtains the volume weight
/// </summary>
/// <param name="volume"><see cref="Volume"/></param>
/// <returns>The weight of the volume</returns>
float GetVolumeWeight(Volume volume);
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -4,31 +4,34 @@
using System.Reflection;
using UnityEditor;

namespace UnityEngine.Rendering.HighDefinition
namespace UnityEngine.Rendering
{
/// <summary>
/// Volume debug settings.
/// </summary>
public class VolumeDebugSettings
public abstract class VolumeDebugSettings<T> : IVolumeDebugSettings
where T : MonoBehaviour, IAdditionalData
{
/// <summary>Current volume component to debug.</summary>
internal int selectedComponent = 0;
int m_SelectedCamera = 0;
public int selectedComponent { get; set; } = 0;

internal int selectedCameraIndex
protected int m_SelectedCameraIndex = 0;

/// <summary>Selected camera index.</summary>
public int selectedCameraIndex
{
get
{
#if UNITY_EDITOR
if (m_SelectedCamera < 0 || m_SelectedCamera > cameras.Count + 1)
if (m_SelectedCameraIndex < 0 || m_SelectedCameraIndex > additionalCameraDatas.Count + 1)
return 0;
#else
if (m_SelectedCamera < 0 || m_SelectedCamera > cameras.Count)
if (m_SelectedCameraIndex < 0 || m_SelectedCameraIndex > additionalCameraDatas.Count)
return 0;
#endif
return m_SelectedCamera;
return m_SelectedCameraIndex;
}
set { m_SelectedCamera = value; }
set { m_SelectedCameraIndex = value; }
}

/// <summary>Current camera to debug.</summary>
Expand All @@ -37,77 +40,40 @@ public Camera selectedCamera
get
{
#if UNITY_EDITOR
if (m_SelectedCamera <= 0 || m_SelectedCamera > cameras.Count + 1)
if (m_SelectedCameraIndex <= 0 || m_SelectedCameraIndex > additionalCameraDatas.Count + 1)
return null;
if (m_SelectedCamera == 1)
if (m_SelectedCameraIndex == 1)
return SceneView.lastActiveSceneView.camera;
else
return cameras[m_SelectedCamera - 2].GetComponent<Camera>();
return additionalCameraDatas[m_SelectedCameraIndex - 2].GetComponent<Camera>();
#else
if (m_SelectedCamera <= 0 || m_SelectedCamera > cameras.Count)
if (m_SelectedCameraIndex <= 0 || m_SelectedCameraIndex > additionalCameraDatas.Count)
return null;
return cameras[m_SelectedCamera - 1].GetComponent<Camera>();
return additionalCameraDatas[m_SelectedCameraIndex - 1].GetComponent<Camera>();
#endif
}
}

/// <summary>Selected camera volume stack.</summary>
public VolumeStack selectedCameraVolumeStack
/// <summary>Returns the collection of registered cameras.</summary>
public IEnumerable<Camera> cameras
{
get
{
Camera cam = selectedCamera;
if (cam == null)
return null;
var stack = HDCamera.GetOrCreate(cam).volumeStack;
if (stack != null)
return stack;
return VolumeManager.instance.stack;
foreach (T additionalCameraData in additionalCameraDatas)
{
yield return additionalCameraData.GetComponent<Camera>();
}
}
}

/// <summary>Selected camera volume stack.</summary>
public abstract VolumeStack selectedCameraVolumeStack { get; }

/// <summary>Selected camera volume layer mask.</summary>
public LayerMask selectedCameraLayerMask
{
get
{
#if UNITY_EDITOR
if (m_SelectedCamera <= 0 || m_SelectedCamera > cameras.Count + 1)
return (LayerMask)0;
if (m_SelectedCamera == 1)
return -1;
return cameras[m_SelectedCamera - 2].volumeLayerMask;
#else
if (m_SelectedCamera <= 0 || m_SelectedCamera > cameras.Count)
return (LayerMask)0;
return cameras[m_SelectedCamera - 1].volumeLayerMask;
#endif
}
}
public abstract LayerMask selectedCameraLayerMask { get; }

/// <summary>Selected camera volume position.</summary>
public Vector3 selectedCameraPosition
{
get
{
Camera cam = selectedCamera;
if (cam == null)
return Vector3.zero;

var anchor = HDCamera.GetOrCreate(cam).volumeAnchor;
if (anchor == null) // means the hdcamera has not been initialized
{
// So we have to update the stack manually
if (cam.TryGetComponent<HDAdditionalCameraData>(out var data))
anchor = data.volumeAnchorOverride;
if (anchor == null) anchor = cam.transform;
var stack = selectedCameraVolumeStack;
if (stack != null)
VolumeManager.instance.Update(stack, anchor, selectedCameraLayerMask);
}
return anchor.position;
}
}
public abstract Vector3 selectedCameraPosition { get; }

/// <summary>Type of the current component to debug.</summary>
public Type selectedComponentType
Expand Down Expand Up @@ -154,18 +120,26 @@ public static string ComponentDisplayName(Type component)
return component.Name;
}

internal static List<HDAdditionalCameraData> cameras { get; private set; } = new List<HDAdditionalCameraData>();
protected static List<T> additionalCameraDatas { get; private set; } = new List<T>();

internal static void RegisterCamera(HDAdditionalCameraData camera)
/// <summary>
/// Register the camera for the Volume Debug.
/// </summary>
/// <param name="additionalCamera">The AdditionalCameraData of the camera to be registered.</param>
public static void RegisterCamera(T additionalCamera)
{
if (!cameras.Contains(camera))
cameras.Add(camera);
if (!additionalCameraDatas.Contains(additionalCamera))
additionalCameraDatas.Add(additionalCamera);
}

internal static void UnRegisterCamera(HDAdditionalCameraData camera)
/// <summary>
/// Unregister the camera for the Volume Debug.
/// </summary>
/// <param name="additionalCamera">The AdditionalCameraData of the camera to be registered.</param>
public static void UnRegisterCamera(T additionalCamera)
{
if (cameras.Contains(camera))
cameras.Remove(camera);
if (additionalCameraDatas.Contains(additionalCamera))
additionalCameraDatas.Remove(additionalCamera);
}

internal VolumeParameter GetParameter(VolumeComponent component, FieldInfo field)
Expand Down Expand Up @@ -277,7 +251,12 @@ bool ChangedStates(VolumeParameter[,] newStates)
return false;
}

internal bool RefreshVolumes(Volume[] newVolumes)
/// <summary>
/// Refreshes the volumes, fetches the stored volumes on the panel
/// </summary>
/// <param name="newVolumes">The list of <see cref="Volume"/> to refresh</param>
/// <returns>If the volumes have been refreshed</returns>
public bool RefreshVolumes(Volume[] newVolumes)
{
bool ret = false;
if (volumes == null || !newVolumes.SequenceEqual(volumes))
Expand All @@ -304,7 +283,12 @@ internal bool RefreshVolumes(Volume[] newVolumes)
return ret;
}

internal float GetVolumeWeight(Volume volume)
/// <summary>
/// Obtains the volume weight
/// </summary>
/// <param name="volume"><see cref="Volume"/></param>
/// <returns>The weight of the volume</returns>
public float GetVolumeWeight(Volume volume)
{
if (weights == null)
return 0;
Expand All @@ -323,7 +307,12 @@ internal float GetVolumeWeight(Volume volume)
return 0f;
}

internal bool VolumeHasInfluence(Volume volume)
/// <summary>
/// Return if the <see cref="Volume"/> has influence
/// </summary>
/// <param name="volume"><see cref="Volume"/> to check the influence</param>
/// <returns>If the volume has influence</returns>
public bool VolumeHasInfluence(Volume volume)
{
if (weights == null)
return false;
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ public class DebugData
/// <summary>Current transparency debug settings.</summary>
public TransparencyDebugSettings transparencyDebugSettings = new TransparencyDebugSettings();
/// <summary>Current volume debug settings.</summary>
public VolumeDebugSettings volumeDebugSettings = new VolumeDebugSettings();
public IVolumeDebugSettings volumeDebugSettings = new HDVolumeDebugSettings();
/// <summary>Index of screen space shadow to display.</summary>
public uint screenSpaceShadowIndex = 0;
/// <summary>Max quad cost for quad overdraw display.</summary>
Expand Down Expand Up @@ -1646,9 +1646,10 @@ void RegisterVolumeDebug()
var componentNames = new List<GUIContent>() { new GUIContent("None") };
var componentValues = new List<int>() { componentIndex++ };

foreach (var type in VolumeDebugSettings.componentTypes)
// TODO @alex.vazquez: Use the same method as VolumeComponentProvider
foreach (var type in HDVolumeDebugSettings.componentTypes)
{
componentNames.Add(new GUIContent() { text = VolumeDebugSettings.ComponentDisplayName(type) });
componentNames.Add(new GUIContent() { text = HDVolumeDebugSettings.ComponentDisplayName(type) });
componentValues.Add(componentIndex++);
}

Expand All @@ -1675,7 +1676,7 @@ void RegisterVolumeDebug()
componentValues.Add(componentIndex++);
#endif

foreach (var camera in VolumeDebugSettings.cameras)
foreach (var camera in data.volumeDebugSettings.cameras)
{
componentNames.Add(new GUIContent() { text = camera.name });
componentValues.Add(componentIndex++);
Expand Down
Loading