This commit is contained in:
2024-09-20 20:30:10 +02:00
commit 4fabf1a6fd
29169 changed files with 1706941 additions and 0 deletions

View File

@@ -0,0 +1,171 @@
using System.Linq;
using UnityEngine;
namespace UnityEditor.Rendering
{
/// <summary> Camera UI Shared Properties among SRP</summary>
public static partial class CameraUI
{
/// <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;
static ProjectionType DrawerProjectionType(ISerializedCamera p, Editor owner)
{
var cam = p.baseCameraSettings;
ProjectionType projectionType;
Rect perspectiveRect = EditorGUILayout.GetControlRect();
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();
return projectionType;
}
static void DrawerOrthographicType(ISerializedCamera p, Editor owner)
{
EditorGUILayout.PropertyField(p.baseCameraSettings.orthographicSize, Styles.sizeContent);
Drawer_FieldClippingPlanes(p, owner);
}
static void DrawerPerspectiveType(ISerializedCamera p, Editor owner)
{
var cam = p.baseCameraSettings;
var targets = p.serializedObject.targetObjects;
var camera0 = targets[0] as Camera;
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;
CoreEditorUtils.DrawEnumPopup<Camera.FieldOfViewAxis>(rect, guiContent, cam.fovAxisMode);
bool fovAxisVertical = cam.fovAxisMode.intValue == 0;
if (!fovAxisVertical && !cam.fovAxisMode.hasMultipleDifferentValues)
{
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;
Drawer_FieldClippingPlanes(p, owner);
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;
s_FovChanged = true;
}
EditorGUILayout.EndHorizontal();
EditorGUI.EndProperty();
EditorGUI.showMixedValue = false;
if (s_FovChanged)
{
if (!isPhysicalCamera || p.projectionMatrixMode.hasMultipleDifferentValues)
{
cam.verticalFOV.floatValue = fovAxisVertical
? s_FovLastValue
: Camera.HorizontalToVerticalFieldOfView(s_FovLastValue, camera0.aspect);
}
else if (!p.projectionMatrixMode.hasMultipleDifferentValues)
{
cam.verticalFOV.floatValue = fovAxisVertical
? s_FovLastValue
: Camera.HorizontalToVerticalFieldOfView(s_FovLastValue, camera0.aspect);
}
}
}
/// <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 projectionType = DrawerProjectionType(p, owner);
if (p.baseCameraSettings.orthographic.hasMultipleDifferentValues)
return;
using (new EditorGUI.IndentLevelScope())
{
if (projectionType == ProjectionType.Orthographic)
{
DrawerOrthographicType(p, owner);
}
else
{
DrawerPerspectiveType(p, owner);
}
}
}
static void Drawer_FieldClippingPlanes(ISerializedCamera p, Editor owner)
{
CoreEditorUtils.DrawMultipleFields(
Styles.clippingPlaneMultiFieldTitle,
new[] { p.baseCameraSettings.nearClippingPlane, p.baseCameraSettings.farClippingPlane },
new[] { Styles.nearPlaneContent, Styles.farPlaneContent });
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: a0d2633fc585aec4a8a89a6014bd7640
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -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);
}
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 40b2b7ce6c436184b91d2d7ea4ef35ce
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -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.");
}
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: c94bc25276e67ea429b40e3228a39b05
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -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);
}
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: c77d1122a4e2ed448966b1535f9f1130
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -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");
}
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: f82f0aee4a6afa04f86310b233ea3d66
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,290 @@
using System;
using System.Runtime.CompilerServices;
using UnityEngine;
namespace UnityEditor.Rendering
{
using CED = CoreEditorDrawer<ISerializedCamera>;
/// <summary> Camera UI Shared Properties among SRP</summary>
public static partial class CameraUI
{
/// <summary>
/// Physical camera related drawers
/// </summary>
public static partial class PhysicalCamera
{
// Saves the value of the sensor size when the user switches from "custom" size to a preset per camera.
// We use a ConditionalWeakTable instead of a Dictionary to avoid keeping alive (with strong references) deleted cameras
static ConditionalWeakTable<Camera, object> s_PerCameraSensorSizeHistory = new ConditionalWeakTable<Camera, object>();
/// <summary>Draws Body Sensor 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_PhysicalCamera_CameraBody_Sensor(ISerializedCamera p, Editor owner)
{
var cam = p.baseCameraSettings;
EditorGUI.BeginChangeCheck();
int oldFilmGateIndex = Array.IndexOf(Styles.apertureFormatValues, new Vector2((float)Math.Round(cam.sensorSize.vector2Value.x, 3), (float)Math.Round(cam.sensorSize.vector2Value.y, 3)));
// If it is not one of the preset sizes, set it to custom
oldFilmGateIndex = (oldFilmGateIndex == -1) ? Styles.customPresetIndex : oldFilmGateIndex;
// Get the new user selection
int newFilmGateIndex = EditorGUILayout.Popup(Styles.sensorType, oldFilmGateIndex, Styles.apertureFormatNames);
if (EditorGUI.EndChangeCheck())
{
// Retrieve the previous custom size value, if one exists for this camera
object previousCustomValue;
s_PerCameraSensorSizeHistory.TryGetValue((Camera)p.serializedObject.targetObject, out previousCustomValue);
// When switching from custom to a preset, update the last custom value (to display again, in case the user switches back to custom)
if (oldFilmGateIndex == Styles.customPresetIndex)
{
if (previousCustomValue == null)
{
s_PerCameraSensorSizeHistory.Add((Camera)p.serializedObject.targetObject, cam.sensorSize.vector2Value);
}
else
{
previousCustomValue = cam.sensorSize.vector2Value;
}
}
if (newFilmGateIndex < Styles.customPresetIndex)
{
cam.sensorSize.vector2Value = Styles.apertureFormatValues[newFilmGateIndex];
}
else
{
// The user switched back to custom, so display by deafulr the previous custom value
if (previousCustomValue != null)
{
cam.sensorSize.vector2Value = (Vector2)previousCustomValue;
}
else
{
cam.sensorSize.vector2Value = new Vector2(36.0f, 24.0f); // this is the value new cameras are created with
}
}
}
EditorGUILayout.PropertyField(cam.sensorSize, Styles.sensorSize);
}
/// <summary>Draws Gate fit 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_PhysicalCamera_CameraBody_GateFit(ISerializedCamera p, Editor owner)
{
var cam = p.baseCameraSettings;
using (var horizontal = new EditorGUILayout.HorizontalScope())
using (var propertyScope = new EditorGUI.PropertyScope(horizontal.rect, Styles.gateFit, cam.gateFit))
using (var checkScope = new EditorGUI.ChangeCheckScope())
{
int gateValue = (int)(Camera.GateFitMode)EditorGUILayout.EnumPopup(propertyScope.content, (Camera.GateFitMode)cam.gateFit.intValue);
if (checkScope.changed)
cam.gateFit.intValue = gateValue;
}
}
/// <summary>Draws Focal Length 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_PhysicalCamera_Lens_FocalLength(ISerializedCamera p, Editor owner)
{
var cam = p.baseCameraSettings;
using (var horizontal = new EditorGUILayout.HorizontalScope())
using (new EditorGUI.PropertyScope(horizontal.rect, Styles.focalLength, cam.focalLength))
using (var checkScope = new EditorGUI.ChangeCheckScope())
{
bool isPhysical = p.projectionMatrixMode.intValue == (int)CameraUI.ProjectionMatrixMode.PhysicalPropertiesBased;
// We need to update the focal length if the camera is physical and the FoV has changed.
bool focalLengthIsDirty = (s_FovChanged && isPhysical);
float sensorLength = cam.fovAxisMode.intValue == 0 ? cam.sensorSize.vector2Value.y : cam.sensorSize.vector2Value.x;
float focalLengthVal = focalLengthIsDirty ? Camera.FieldOfViewToFocalLength(s_FovLastValue, sensorLength) : cam.focalLength.floatValue;
focalLengthVal = EditorGUILayout.FloatField(Styles.focalLength, focalLengthVal);
if (checkScope.changed || focalLengthIsDirty)
cam.focalLength.floatValue = focalLengthVal;
}
}
/// <summary>Draws Lens Shift 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_PhysicalCamera_Lens_Shift(ISerializedCamera p, Editor owner)
{
EditorGUILayout.PropertyField(p.baseCameraSettings.lensShift, Styles.shift);
}
/// <summary>Draws Focus Distance 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_PhysicalCamera_FocusDistance(ISerializedCamera p, Editor owner)
{
var cam = p.baseCameraSettings;
EditorGUILayout.PropertyField(cam.focusDistance, Styles.focusDistance);
}
/// <summary>Draws ISO 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_PhysicalCamera_CameraBody_ISO(ISerializedCamera p, Editor owner)
{
var cam = p.baseCameraSettings;
EditorGUILayout.PropertyField(cam.iso, Styles.ISO);
}
static EditorPrefBoolFlags<ShutterSpeedUnit> m_ShutterSpeedState = new EditorPrefBoolFlags<ShutterSpeedUnit>($"HDRP:{nameof(CameraUI)}:ShutterSpeedState");
enum ShutterSpeedUnit
{
[InspectorName("Second")]
Second,
[InspectorName("1 \u2215 Second")] // Don't use a slash here else Unity will auto-create a submenu...
OneOverSecond
}
/// <summary>Draws Shutter Speed 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_PhysicalCamera_CameraBody_ShutterSpeed(ISerializedCamera p, Editor owner)
{
var cam = p.baseCameraSettings;
// Custom layout for shutter speed
const int k_UnitMenuWidth = 90;
const int k_OffsetPerIndent = 15;
const int k_LabelFieldSeparator = 2;
const int k_Offset = 1;
int oldIndentLevel = EditorGUI.indentLevel;
// Don't take into account the indentLevel when rendering the units field
EditorGUI.indentLevel = 0;
var lineRect = EditorGUILayout.GetControlRect();
var fieldRect = new Rect(k_OffsetPerIndent + k_LabelFieldSeparator + k_Offset, lineRect.y, lineRect.width - k_UnitMenuWidth, lineRect.height);
var unitMenu = new Rect(fieldRect.xMax + k_LabelFieldSeparator, lineRect.y, k_UnitMenuWidth - k_LabelFieldSeparator, lineRect.height);
// We cannot had the shutterSpeedState as this is not a serialized property but a global edition mode.
// This imply that it will never go bold nor can be reverted in prefab overrides
m_ShutterSpeedState.value = (ShutterSpeedUnit)EditorGUI.EnumPopup(unitMenu, m_ShutterSpeedState.value);
// Reset the indent level
EditorGUI.indentLevel = oldIndentLevel;
EditorGUI.BeginProperty(fieldRect, Styles.shutterSpeed, cam.shutterSpeed);
{
// if we we use (1 / second) units, then change the value for the display and then revert it back
if (m_ShutterSpeedState.value == ShutterSpeedUnit.OneOverSecond && cam.shutterSpeed.floatValue > 0)
cam.shutterSpeed.floatValue = 1.0f / cam.shutterSpeed.floatValue;
EditorGUI.PropertyField(fieldRect, cam.shutterSpeed, Styles.shutterSpeed);
if (m_ShutterSpeedState.value == ShutterSpeedUnit.OneOverSecond && cam.shutterSpeed.floatValue > 0)
cam.shutterSpeed.floatValue = 1.0f / cam.shutterSpeed.floatValue;
}
EditorGUI.EndProperty();
}
/// <summary>Draws Lens Aperture 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_PhysicalCamera_Lens_Aperture(ISerializedCamera p, Editor owner)
{
var cam = p.baseCameraSettings;
// Custom layout for aperture
var rect = EditorGUILayout.BeginHorizontal();
{
// Magic values/offsets to get the UI look consistent
const float textRectSize = 80;
const float textRectPaddingRight = 62;
const float unitRectPaddingRight = 97;
const float sliderPaddingLeft = 2;
const float sliderPaddingRight = 77;
var labelRect = rect;
labelRect.width = EditorGUIUtility.labelWidth;
labelRect.height = EditorGUIUtility.singleLineHeight;
EditorGUI.LabelField(labelRect, Styles.aperture);
GUI.SetNextControlName("ApertureSlider");
var sliderRect = rect;
sliderRect.x += labelRect.width + sliderPaddingLeft;
sliderRect.width = rect.width - labelRect.width - sliderPaddingRight;
float newVal = GUI.HorizontalSlider(sliderRect, cam.aperture.floatValue, Camera.kMinAperture, Camera.kMaxAperture);
// keep only 2 digits of precision, like the otehr editor fields
newVal = Mathf.Floor(100 * newVal) / 100.0f;
if (cam.aperture.floatValue != newVal)
{
cam.aperture.floatValue = newVal;
// Note: We need to move the focus when the slider changes, otherwise the textField will not update
GUI.FocusControl("ApertureSlider");
}
var unitRect = rect;
unitRect.x += rect.width - unitRectPaddingRight;
unitRect.width = textRectSize;
unitRect.height = EditorGUIUtility.singleLineHeight;
EditorGUI.LabelField(unitRect, "f /", EditorStyles.label);
var textRect = rect;
textRect.x = rect.width - textRectPaddingRight;
textRect.width = textRectSize;
textRect.height = EditorGUIUtility.singleLineHeight;
string newAperture = EditorGUI.TextField(textRect, cam.aperture.floatValue.ToString());
if (float.TryParse(newAperture, out float parsedValue))
cam.aperture.floatValue = Mathf.Clamp(parsedValue, Camera.kMinAperture, Camera.kMaxAperture);
}
EditorGUILayout.EndHorizontal();
EditorGUILayout.Space(EditorGUIUtility.singleLineHeight);
}
/// <summary>Draws Aperture Shape 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_PhysicalCamera_ApertureShape(ISerializedCamera p, Editor owner)
{
var cam = p.baseCameraSettings;
EditorGUILayout.PropertyField(cam.bladeCount, Styles.bladeCount);
using (var horizontal = new EditorGUILayout.HorizontalScope())
using (var propertyScope = new EditorGUI.PropertyScope(horizontal.rect, Styles.curvature, cam.curvature))
{
var v = cam.curvature.vector2Value;
// The layout system breaks alignment when mixing inspector fields with custom layout'd
// fields as soon as a scrollbar is needed in the inspector, so we'll do the layout
// manually instead
const int kFloatFieldWidth = 50;
const int kSeparatorWidth = 5;
float indentOffset = EditorGUI.indentLevel * 15f;
var lineRect = EditorGUILayout.GetControlRect();
var labelRect = new Rect(lineRect.x, lineRect.y, EditorGUIUtility.labelWidth - indentOffset, lineRect.height);
var floatFieldLeft = new Rect(labelRect.xMax, lineRect.y, kFloatFieldWidth + indentOffset, lineRect.height);
var sliderRect = new Rect(floatFieldLeft.xMax + kSeparatorWidth - indentOffset, lineRect.y, lineRect.width - labelRect.width - kFloatFieldWidth * 2 - kSeparatorWidth * 2, lineRect.height);
var floatFieldRight = new Rect(sliderRect.xMax + kSeparatorWidth - indentOffset, lineRect.y, kFloatFieldWidth + indentOffset, lineRect.height);
EditorGUI.PrefixLabel(labelRect, propertyScope.content);
v.x = EditorGUI.FloatField(floatFieldLeft, v.x);
EditorGUI.MinMaxSlider(sliderRect, ref v.x, ref v.y, Camera.kMinAperture, Camera.kMaxAperture);
v.y = EditorGUI.FloatField(floatFieldRight, v.y);
cam.curvature.vector2Value = v;
}
EditorGUILayout.PropertyField(cam.barrelClipping, Styles.barrelClipping);
EditorGUILayout.PropertyField(cam.anamorphism, Styles.anamorphism);
}
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: b7fbad490dc4ecc46b2936be42e9c71f
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,120 @@
using System.Linq;
using UnityEngine;
namespace UnityEditor.Rendering
{
/// <summary> Camera UI Shared Properties among SRP</summary>
public static partial class CameraUI
{
/// <summary>
/// Physical camera content content
/// </summary>
public static partial class PhysicalCamera
{
/// <summary>
/// Styles
/// </summary>
public static class Styles
{
// Camera Body
/// <summary>
/// Camera Body content
/// </summary>
public static readonly GUIContent cameraBody = EditorGUIUtility.TrTextContent("Camera Body");
/// <summary>
/// Sensor type content
/// </summary>
public static readonly GUIContent sensorType = EditorGUIUtility.TrTextContent("Sensor Type", "Common sensor sizes. Choose an item to set Sensor Size, or edit Sensor Size for your custom settings.");
/// <summary>
/// Aperture format names
/// </summary>
public static readonly string[] apertureFormatNames = CameraEditor.Settings.ApertureFormatNames.ToArray();
/// <summary>
/// Aperture format values
/// </summary>
public static readonly Vector2[] apertureFormatValues = CameraEditor.Settings.ApertureFormatValues.ToArray();
/// <summary>
/// Custom preset index
/// </summary>
public static readonly int customPresetIndex = apertureFormatNames.Length - 1;
/// <summary>
/// Sensor size
/// </summary>
public static readonly GUIContent sensorSize = EditorGUIUtility.TrTextContent("Sensor Size", "The size of the camera sensor in millimeters.");
/// <summary>
/// Gate Fit
/// </summary>
public static readonly GUIContent gateFit = EditorGUIUtility.TrTextContent("Gate Fit", "Determines how the rendered area (resolution gate) fits into the sensor area (film gate).");
// Lens
/// <summary>
/// Lens content
/// </summary>
public static readonly GUIContent lens = EditorGUIUtility.TrTextContent("Lens");
/// <summary>
/// Focal Length content
/// </summary>
public static readonly GUIContent focalLength = EditorGUIUtility.TrTextContent("Focal Length", "The simulated distance between the lens and the sensor of the physical camera. Larger values give a narrower field of view.");
/// <summary>
/// Shift content
/// </summary>
public static readonly GUIContent shift = EditorGUIUtility.TrTextContent("Shift", "Offset from the camera sensor. Use these properties to simulate a shift lens. Measured as a multiple of the sensor size.");
/// <summary>
/// ISO content
/// </summary>
public static readonly GUIContent ISO = EditorGUIUtility.TrTextContent("ISO", "Sets the light sensitivity of the Camera sensor. This property affects Exposure if you set its Mode to Use Physical Camera.");
/// <summary>
/// Shutter Speed content
/// </summary>
public static readonly GUIContent shutterSpeed = EditorGUIUtility.TrTextContent("Shutter Speed", "The amount of time the Camera sensor is capturing light.");
/// <summary>
/// Aperture content
/// </summary>
public static readonly GUIContent aperture = EditorGUIUtility.TrTextContent("Aperture", "The f-stop (f-number) of the lens. Lower values give a wider lens aperture.");
/// <summary>
/// Focus Distance content
/// </summary>
public static readonly GUIContent focusDistance = EditorGUIUtility.TrTextContent("Focus Distance", "The distance from the camera where objects appear sharp when Depth Of Field is enabled.");
// Aperture Shape
/// <summary>
/// Aperture Shape content
/// </summary>
public static readonly GUIContent apertureShape = EditorGUIUtility.TrTextContent("Aperture Shape", "Common sensor sizes. Choose an item to set Sensor Size, or edit Sensor Size for your custom settings.");
/// <summary>
/// Blade Count content
/// </summary>
public static readonly GUIContent bladeCount = EditorGUIUtility.TrTextContent("Blade Count", "The number of blades in the lens aperture. Higher values give a rounder aperture shape.");
/// <summary>
/// Curvature content
/// </summary>
public static readonly GUIContent curvature = EditorGUIUtility.TrTextContent("Curvature", "Controls the curvature of the lens aperture blades. The minimum value results in fully-curved, perfectly-circular bokeh, and the maximum value results in visible aperture blades.");
/// <summary>
/// Barrel Clipping content
/// </summary>
public static readonly GUIContent barrelClipping = EditorGUIUtility.TrTextContent("Barrel Clipping", "Controls the self-occlusion of the lens, creating a cat's eye effect.");
/// <summary>
/// Anamorphism content
/// </summary>
public static readonly GUIContent anamorphism = EditorGUIUtility.TrTextContent("Anamorphism", "Use the slider to stretch the sensor to simulate an anamorphic look.");
}
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 7e978521b37d51146b2cc9750ebfa16c
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,41 @@
namespace UnityEditor.Rendering
{
/// <summary> Camera UI Shared Properties among SRP</summary>
public static partial class CameraUI
{
public static partial class Rendering
{
/// <summary>Draws Stop NaNs 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_Rendering_StopNaNs(ISerializedCamera p, Editor owner)
{
EditorGUILayout.PropertyField(p.stopNaNs, Styles.stopNaNs);
}
/// <summary>Draws Dithering 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_Rendering_Dithering(ISerializedCamera p, Editor owner)
{
EditorGUILayout.PropertyField(p.dithering, Styles.dithering);
}
/// <summary>Draws Culling mask 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_Rendering_CullingMask(ISerializedCamera p, Editor owner)
{
EditorGUILayout.PropertyField(p.baseCameraSettings.cullingMask, Styles.cullingMask);
}
/// <summary>Draws occlusion Culling 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_Rendering_OcclusionCulling(ISerializedCamera p, Editor owner)
{
EditorGUILayout.PropertyField(p.baseCameraSettings.occlusionCulling, Styles.occlusionCulling);
}
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 6cf20b5e989565749903509e13e351f6
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,60 @@
using UnityEngine;
namespace UnityEditor.Rendering
{
/// <summary> Camera UI Shared Properties among SRP</summary>
public static partial class CameraUI
{
/// <summary>
/// Rendering section
/// </summary>
public static partial class Rendering
{
/// <summary>
/// Styles
/// </summary>
public static class Styles
{
/// <summary>
/// Header of the section
/// </summary>
public static readonly GUIContent header = EditorGUIUtility.TrTextContent("Rendering", "These settings control for the specific rendering features for this camera.");
/// <summary>
/// antialiasing content
/// </summary>
public static readonly GUIContent antialiasing = EditorGUIUtility.TrTextContent("Post Anti-aliasing", "The postprocess anti-aliasing method to use.");
/// <summary>
/// dithering content
/// </summary>
public static readonly GUIContent dithering = EditorGUIUtility.TrTextContent("Dithering", "Applies 8-bit dithering to the final render to reduce color banding.");
/// <summary>
/// stopNaNs content
/// </summary>
public static readonly GUIContent stopNaNs = EditorGUIUtility.TrTextContent("Stop NaNs", "Automatically replaces NaN/Inf in shaders by a black pixel to avoid breaking some effects. This will slightly affect performances and should only be used if you experience NaN issues that you can't fix.");
/// <summary>
/// cullingMask content
/// </summary>
public static readonly GUIContent cullingMask = EditorGUIUtility.TrTextContent("Culling Mask");
/// <summary>
/// occlusionCulling content
/// </summary>
public static readonly GUIContent occlusionCulling = EditorGUIUtility.TrTextContent("Occlusion Culling");
/// <summary>
/// renderingPath content
/// </summary>
public static readonly GUIContent renderingPath = EditorGUIUtility.TrTextContent("Custom Frame Settings", "Define the custom Frame Settings for this Camera to use.");
/// <summary>
/// exposureTarget content
/// </summary>
public static readonly GUIContent exposureTarget = EditorGUIUtility.TrTextContent("Exposure Target", "The object used as a target for centering the Exposure's Procedural Mask metering mode when target object option is set (See Exposure Volume Component).");
}
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 96acda4e859ca224986250b52266e0c9
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,64 @@
using UnityEngine;
namespace UnityEditor.Rendering
{
/// <summary> Camera UI Shared Properties among SRP</summary>
public static partial class CameraUI
{
/// <summary>
/// Styles
/// </summary>
public static class Styles
{
/// <summary>
/// Projection section header
/// </summary>
public static GUIContent projectionSettingsHeaderContent { get; } = EditorGUIUtility.TrTextContent("Projection");
/// <summary>
/// Clipping planes content
/// </summary>
public static GUIContent clippingPlaneMultiFieldTitle = EditorGUIUtility.TrTextContent("Clipping Planes");
/// <summary>
/// Projection Content
/// </summary>
public static readonly GUIContent projectionContent = EditorGUIUtility.TrTextContent("Projection", "How the Camera renders perspective.\n\nChoose Perspective to render objects with perspective.\n\nChoose Orthographic to render objects uniformly, with no sense of perspective.");
/// <summary>
/// Size content
/// </summary>
public static readonly GUIContent sizeContent = EditorGUIUtility.TrTextContent("Size");
/// <summary>
/// FOV content
/// </summary>
public static readonly GUIContent fieldOfViewContent = EditorGUIUtility.TrTextContent("Field of View", "The height of the Camera's view angle, measured in degrees along the specified axis.");
/// <summary>
/// FOV Axis content
/// </summary>
public static readonly GUIContent FOVAxisModeContent = EditorGUIUtility.TrTextContent("Field of View Axis", "The axis the Camera's view angle is measured along.");
/// <summary>
/// Physical camera content
/// </summary>
public static readonly GUIContent physicalCameraContent = EditorGUIUtility.TrTextContent("Physical Camera", "Enables Physical camera mode for FOV calculation. When checked, the field of view is calculated from properties for simulating physical attributes (focal length, sensor size, and lens shift).");
/// <summary>
/// Near plane content
/// </summary>
public static readonly GUIContent nearPlaneContent = EditorGUIUtility.TrTextContent("Near", "The closest point relative to the camera that drawing occurs.");
/// <summary>
/// Far plane content
/// </summary>
public static readonly GUIContent farPlaneContent = EditorGUIUtility.TrTextContent("Far", "The furthest point relative to the camera that drawing occurs.");
/// <summary>
/// Message displayed about unsupported fields for Camera Presets
/// </summary>
public static readonly string unsupportedPresetPropertiesMessage = L10n.Tr("When using Preset of Camera Component, only a subset of properties are supported. Unsupported properties are hidden.");
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: e26c221569d1d284a9d21434b3a4b277
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,42 @@
namespace UnityEditor.Rendering
{
/// <summary>
/// Interface to be implemented by each pipeline to hold the <see cref="SerializedObject"/> for a Camera Editor
/// </summary>
public interface ISerializedCamera
{
/// <summary>The camera serialized</summary>
SerializedObject serializedObject { get; }
/// <summary>The additional camera data serialized</summary>
SerializedObject serializedAdditionalDataObject { get; }
/// <summary>The base camera settings</summary>
CameraEditor.Settings baseCameraSettings { get; }
// This one is internal in UnityEditor for whatever reason...
/// <summary>The projection matrix mode</summary>
SerializedProperty projectionMatrixMode { get; }
// Common properties
/// <summary>Dithering property</summary>
SerializedProperty dithering { get; }
/// <summary>Stop NaNs property</summary>
SerializedProperty stopNaNs { get; }
/// <summary>Allow Dynamic resolution property</summary>
SerializedProperty allowDynamicResolution { get; }
/// <summary>Volume layer mask property</summary>
SerializedProperty volumeLayerMask { get; }
/// <summary>Clear Depth property property</summary>
SerializedProperty clearDepth { get; }
/// <summary>Anti aliasing property</summary>
SerializedProperty antialiasing { get; }
/// <summary>Method that updates the <see cref="SerializedObject"/> of the Camera and the Additional Camera Data</summary>
void Update();
/// <summary>Applies the modified properties to the <see cref="SerializedObject"/> of the Camera and the Additional Camera Data</summary>
void Apply();
/// <summary>Refreshes the <see cref="SerializedProperty"/> of the <see cref="SerializedObject"/> of the Camera and the Additional Camera Data</summary>
void Refresh();
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 55ef358f023224145a079dd70d4692b5
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant: