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
166 changes: 166 additions & 0 deletions com.unity.render-pipelines.core/Editor/Camera/CameraUI.Drawers.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,166 @@
using System.Linq;
using UnityEngine;

namespace UnityEditor.Rendering
{
/// <summary> Camera UI Shared Properties among SRP</summary>
public static partial class CameraUI
{
/// <summary>Enum to store know the expanded state of a expandable section on the camera inspector</summary>
public enum Expandable
{
/// <summary> Projection</summary>
Projection = 1 << 0,
/// <summary> Physical</summary>
Physical = 1 << 1,
/// <summary> Output</summary>
Output = 1 << 2,
/// <summary> Orthographic</summary>
Orthographic = 1 << 3,
/// <summary> RenderLoop</summary>
RenderLoop = 1 << 4,
/// <summary> Rendering</summary>
Rendering = 1 << 5,
/// <summary> Environment</summary>
Environment = 1 << 6,
}
Comment on lines +10 to +26
Copy link
Contributor

@RSlysz RSlysz Apr 20, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a small concern here now that we share the Expendable:

  • does every SRP will always have the same Area?
  • Though as registration of expendable state is done in HDRP camera, the collapsing of lets say Projection area only collapse Projection for HDRP Camera and not for all (URP, CustomRP). Is this what we want? Should we also have a shared expendable state? What is expected to be done when making a custom SRP now regarding this change ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

URP will have an extra expandable state here that will be Stack, I will add it on the future. The expanded state isn't shared. Maybe we can share it, it will be an option.

A custom SRP could have it's own store for it expandables. The thing here is we are letting SRP to use this sections, if they want to use it is on their hands.


/// <summary>Camera Projection type</summary>
public enum ProjectionType
{
/// <summary> Perspective</summary>
Perspective,
/// <summary> Orthographic</summary>
Orthographic
}

/// <summary>Camera Projection matrix mode</summary>
public enum ProjectionMatrixMode
{
/// <summary> Explicit</summary>
Explicit,
/// <summary> Implicit</summary>
Implicit,
/// <summary> PhysicalPropertiesBased</summary>
PhysicalPropertiesBased,
}

static bool s_FovChanged;
static float s_FovLastValue;

/// <summary>Draws projection related fields on the inspector</summary>
/// <param name="p"><see cref="ISerializedCamera"/> The serialized camera</param>
/// <param name="owner"><see cref="Editor"/> The editor owner calling this drawer</param>
public static void Drawer_Projection(ISerializedCamera p, Editor owner)
{
// Most of this is replicated from CameraEditor.DrawProjection as we don't want to draw
// it the same way it's done in non-SRP cameras. Unfortunately, because a lot of the
// code is internal, we have to copy/paste some stuff from the editor code :(

var cam = p.baseCameraSettings;

Rect perspectiveRect = EditorGUILayout.GetControlRect();

ProjectionType projectionType;
EditorGUI.BeginProperty(perspectiveRect, Styles.projectionContent, cam.orthographic);
{
projectionType = cam.orthographic.boolValue ? ProjectionType.Orthographic : ProjectionType.Perspective;

EditorGUI.BeginChangeCheck();
projectionType = (ProjectionType)EditorGUI.EnumPopup(perspectiveRect, Styles.projectionContent, projectionType);
if (EditorGUI.EndChangeCheck())
cam.orthographic.boolValue = (projectionType == ProjectionType.Orthographic);
}
EditorGUI.EndProperty();

if (cam.orthographic.hasMultipleDifferentValues)
return;

if (projectionType == ProjectionType.Orthographic)
{
EditorGUILayout.PropertyField(cam.orthographicSize, Styles.sizeContent);
}
else
{
float fovCurrentValue;
bool multipleDifferentFovValues = false;
bool isPhysicalCamera = p.projectionMatrixMode.intValue == (int)ProjectionMatrixMode.PhysicalPropertiesBased;

var rect = EditorGUILayout.GetControlRect();

var guiContent = EditorGUI.BeginProperty(rect, Styles.FOVAxisModeContent, cam.fovAxisMode);
EditorGUI.showMixedValue = cam.fovAxisMode.hasMultipleDifferentValues;

EditorGUI.BeginChangeCheck();
var fovAxisNewVal = (int)(Camera.FieldOfViewAxis)EditorGUI.EnumPopup(rect, guiContent, (Camera.FieldOfViewAxis)cam.fovAxisMode.intValue);
if (EditorGUI.EndChangeCheck())
cam.fovAxisMode.intValue = fovAxisNewVal;
EditorGUI.EndProperty();

bool fovAxisVertical = cam.fovAxisMode.intValue == 0;

if (!fovAxisVertical && !cam.fovAxisMode.hasMultipleDifferentValues)
{
var targets = p.serializedObject.targetObjects;
var camera0 = targets[0] as Camera;
float aspectRatio = isPhysicalCamera ? cam.sensorSize.vector2Value.x / cam.sensorSize.vector2Value.y : camera0.aspect;
// camera.aspect is not serialized so we have to check all targets.
fovCurrentValue = Camera.VerticalToHorizontalFieldOfView(camera0.fieldOfView, aspectRatio);
if (targets.Cast<Camera>().Any(camera => camera.fieldOfView != fovCurrentValue))
multipleDifferentFovValues = true;
}
else
{
fovCurrentValue = cam.verticalFOV.floatValue;
multipleDifferentFovValues = cam.fovAxisMode.hasMultipleDifferentValues;
}

EditorGUI.showMixedValue = multipleDifferentFovValues;
var content = EditorGUI.BeginProperty(EditorGUILayout.BeginHorizontal(), Styles.fieldOfViewContent, cam.verticalFOV);
EditorGUI.BeginDisabledGroup(p.projectionMatrixMode.hasMultipleDifferentValues || isPhysicalCamera && (cam.sensorSize.hasMultipleDifferentValues || cam.fovAxisMode.hasMultipleDifferentValues));
EditorGUI.BeginChangeCheck();
s_FovLastValue = EditorGUILayout.Slider(content, fovCurrentValue, 0.00001f, 179f);
s_FovChanged = EditorGUI.EndChangeCheck();
EditorGUI.EndDisabledGroup();
EditorGUILayout.EndHorizontal();
EditorGUI.EndProperty();
EditorGUI.showMixedValue = false;

content = EditorGUI.BeginProperty(EditorGUILayout.BeginHorizontal(), Styles.physicalCameraContent, p.projectionMatrixMode);
EditorGUI.showMixedValue = p.projectionMatrixMode.hasMultipleDifferentValues;

EditorGUI.BeginChangeCheck();
isPhysicalCamera = EditorGUILayout.Toggle(content, isPhysicalCamera);
if (EditorGUI.EndChangeCheck())
p.projectionMatrixMode.intValue = isPhysicalCamera ? (int)ProjectionMatrixMode.PhysicalPropertiesBased : (int)ProjectionMatrixMode.Implicit;
EditorGUILayout.EndHorizontal();
EditorGUI.EndProperty();

EditorGUI.showMixedValue = false;
if (s_FovChanged && (!isPhysicalCamera || p.projectionMatrixMode.hasMultipleDifferentValues))
{
cam.verticalFOV.floatValue = fovAxisVertical
? s_FovLastValue
: Camera.HorizontalToVerticalFieldOfView(s_FovLastValue, (p.serializedObject.targetObjects[0] as Camera).aspect);
}
else if (s_FovChanged && isPhysicalCamera && !p.projectionMatrixMode.hasMultipleDifferentValues)
{
cam.verticalFOV.floatValue = fovAxisVertical
? s_FovLastValue
: Camera.HorizontalToVerticalFieldOfView(s_FovLastValue, (p.serializedObject.targetObjects[0] as Camera).aspect);
}
}
}

/// <summary>Draws clippling planes related fields on the inspector</summary>
/// <param name="p"><see cref="ISerializedCamera"/> The serialized camera</param>
/// <param name="owner"><see cref="Editor"/> The editor owner calling this drawer</param>
public static void Drawer_FieldClippingPlanes(ISerializedCamera p, Editor owner)
{
CoreEditorUtils.DrawMultipleFields(
Styles.clippingPlaneMultiFieldTitle,
new[] { p.baseCameraSettings.nearClippingPlane, p.baseCameraSettings.farClippingPlane },
new[] { Styles.nearPlaneContent, Styles.farPlaneContent });
}
}
}

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
@@ -0,0 +1,20 @@
namespace UnityEditor.Rendering
{
/// <summary> Camera UI Shared Properties among SRP</summary>
public static partial class CameraUI
{
/// <summary>
/// Environment Section
/// </summary>
public static partial class Environment
{
/// <summary>Draws layer mask planes related fields on the inspector</summary>
/// <param name="p"><see cref="ISerializedCamera"/> The serialized camera</param>
/// <param name="owner"><see cref="Editor"/> The editor owner calling this drawer</param>
public static void Drawer_Environment_VolumeLayerMask(ISerializedCamera p, Editor owner)
{
EditorGUILayout.PropertyField(p.volumeLayerMask, Styles.volumeLayerMask);
}
}
}
}

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
@@ -0,0 +1,30 @@
using UnityEngine;

namespace UnityEditor.Rendering
{
/// <summary> Camera UI Shared Properties among SRP</summary>
public static partial class CameraUI
{
/// <summary>
/// Environment section
/// </summary>
public static partial class Environment
{
/// <summary>
/// Styles
/// </summary>
public static class Styles
{
/// <summary>
/// Header of the section
/// </summary>
public static readonly GUIContent header = EditorGUIUtility.TrTextContent("Environment", "These settings control what the camera background looks like.");

/// <summary>
/// Volume layer mask content
/// </summary>
public static readonly GUIContent volumeLayerMask = EditorGUIUtility.TrTextContent("Volume Mask", "This camera will only be affected by volumes in the selected scene-layers.");
}
}
}
}

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
@@ -0,0 +1,45 @@
namespace UnityEditor.Rendering
{
/// <summary> Camera UI Shared Properties among SRP</summary>
public static partial class CameraUI
{
/// <summary>
/// Output Section
/// </summary>
public static partial class Output
{
/// <summary>Draws Allow Dynamic Resolution related fields on the inspector</summary>
/// <param name="p"><see cref="ISerializedCamera"/> The serialized camera</param>
/// <param name="owner"><see cref="Editor"/> The editor owner calling this drawer</param>
public static void Drawer_Output_AllowDynamicResolution(ISerializedCamera p, Editor owner)
{
EditorGUILayout.PropertyField(p.allowDynamicResolution, Styles.allowDynamicResolution);
p.baseCameraSettings.allowDynamicResolution.boolValue = p.allowDynamicResolution.boolValue;
}

/// <summary>Draws Normalized ViewPort related fields on the inspector</summary>
/// <param name="p"><see cref="ISerializedCamera"/> The serialized camera</param>
/// <param name="owner"><see cref="Editor"/> The editor owner calling this drawer</param>
public static void Drawer_Output_NormalizedViewPort(ISerializedCamera p, Editor owner)
{
EditorGUILayout.PropertyField(p.baseCameraSettings.normalizedViewPortRect, Styles.viewport);
}

/// <summary>Draws Depth related fields on the inspector</summary>
/// <param name="p"><see cref="ISerializedCamera"/> The serialized camera</param>
/// <param name="owner"><see cref="Editor"/> The editor owner calling this drawer</param>
public static void Drawer_Output_Depth(ISerializedCamera p, Editor owner)
{
EditorGUILayout.PropertyField(p.baseCameraSettings.depth, Styles.depth);
}

/// <summary>Draws Render Target related fields on the inspector</summary>
/// <param name="p"><see cref="ISerializedCamera"/> The serialized camera</param>
/// <param name="owner"><see cref="Editor"/> The editor owner calling this drawer</param>
public static void Drawer_Output_RenderTarget(ISerializedCamera p, Editor owner)
{
EditorGUILayout.PropertyField(p.baseCameraSettings.targetTexture);
}
}
}
}

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
@@ -0,0 +1,47 @@
using UnityEngine;

namespace UnityEditor.Rendering
{
/// <summary> Camera UI Shared Properties among SRP</summary>
public static partial class CameraUI
{
/// <summary>
/// Output section
/// </summary>
public static partial class Output
{
/// <summary>
/// Styles
/// </summary>
public static class Styles
{
/// <summary>
/// Header of the section
/// </summary>
public static readonly GUIContent header = EditorGUIUtility.TrTextContent("Output", "These settings control how the camera output is formatted.");

#if ENABLE_MULTIPLE_DISPLAYS
/// <summary>
/// Target display content
/// </summary>
public static readonly GUIContent targetDisplay = EditorGUIUtility.TrTextContent("Target Display");
#endif

/// <summary>
/// Viewport
/// </summary>
public static readonly GUIContent viewport = EditorGUIUtility.TrTextContent("Viewport Rect", "Four values that indicate where on the screen HDRP draws this Camera view. Measured in Viewport Coordinates (values in the range of [0, 1]).");

/// <summary>
/// Allow dynamic resolution content
/// </summary>
public static readonly GUIContent allowDynamicResolution = EditorGUIUtility.TrTextContent("Allow Dynamic Resolution", "Whether to support dynamic resolution.");

/// <summary>
/// Depth content
/// </summary>
public static readonly GUIContent depth = EditorGUIUtility.TrTextContent("Depth");
}
}
}
}

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

Loading