diff --git a/com.unity.render-pipelines.core/Editor/Camera/CameraUI.PhysicalCamera.Drawers.cs b/com.unity.render-pipelines.core/Editor/Camera/CameraUI.PhysicalCamera.Drawers.cs index 8f211b34230..2ae770078b8 100644 --- a/com.unity.render-pipelines.core/Editor/Camera/CameraUI.PhysicalCamera.Drawers.cs +++ b/com.unity.render-pipelines.core/Editor/Camera/CameraUI.PhysicalCamera.Drawers.cs @@ -4,6 +4,9 @@ namespace UnityEditor.Rendering { + + using CED = CoreEditorDrawer; + /// Camera UI Shared Properties among SRP public static partial class CameraUI { @@ -119,6 +122,169 @@ public static void Drawer_PhysicalCamera_Lens_Shift(ISerializedCamera p, Editor { EditorGUILayout.PropertyField(p.baseCameraSettings.lensShift, Styles.shift); } + + + /// Draws Focus Distance related fields on the inspector + /// The serialized camera + /// The editor owner calling this drawer + public static void Drawer_PhysicalCamera_FocusDistance(ISerializedCamera p, Editor owner) + { + var cam = p.baseCameraSettings; + EditorGUILayout.PropertyField(cam.focusDistance, Styles.focusDistance); + } + + /// Draws ISO related fields on the inspector + /// The serialized camera + /// The editor owner calling this drawer + public static void Drawer_PhysicalCamera_CameraBody_ISO(ISerializedCamera p, Editor owner) + { + var cam = p.baseCameraSettings; + EditorGUILayout.PropertyField(cam.iso, Styles.ISO); + } + + static EditorPrefBoolFlags m_ShutterSpeedState = new EditorPrefBoolFlags($"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 + } + + /// Draws Shutter Speed related fields on the inspector + /// The serialized camera + /// The editor owner calling this drawer + 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(); + } + + /// Draws Lens Aperture related fields on the inspector + /// The serialized camera + /// The editor owner calling this drawer + 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); + } + + /// Draws Aperture Shape related fields on the inspector + /// The serialized camera + /// The editor owner calling this drawer + 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); + } } } } diff --git a/com.unity.render-pipelines.core/Editor/Camera/CameraUI.PhysicalCamera.Skin.cs b/com.unity.render-pipelines.core/Editor/Camera/CameraUI.PhysicalCamera.Skin.cs index 6ed88b18a18..0c1d5aa6020 100644 --- a/com.unity.render-pipelines.core/Editor/Camera/CameraUI.PhysicalCamera.Skin.cs +++ b/com.unity.render-pipelines.core/Editor/Camera/CameraUI.PhysicalCamera.Skin.cs @@ -59,7 +59,7 @@ public static class Styles public static readonly GUIContent lens = EditorGUIUtility.TrTextContent("Lens"); /// - /// Focal Length Content + /// Focal Length content /// 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."); @@ -67,6 +67,53 @@ public static class Styles /// Shift content /// 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."); + + /// + /// ISO content + /// + 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."); + + /// + /// Shutter Speed content + /// + public static readonly GUIContent shutterSpeed = EditorGUIUtility.TrTextContent("Shutter Speed", "The amount of time the Camera sensor is capturing light."); + + /// + /// Aperture content + /// + public static readonly GUIContent aperture = EditorGUIUtility.TrTextContent("Aperture", "The f-stop (f-number) of the lens. Lower values give a wider lens aperture."); + + /// + /// Focus Distance content + /// + 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 + + /// + /// Aperture Shape content + /// + 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."); + + /// + /// Blade Count content + /// + public static readonly GUIContent bladeCount = EditorGUIUtility.TrTextContent("Blade Count", "The number of blades in the lens aperture. Higher values give a rounder aperture shape."); + + /// + /// Curvature content + /// + 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."); + + /// + /// Barrel Clipping content + /// + public static readonly GUIContent barrelClipping = EditorGUIUtility.TrTextContent("Barrel Clipping", "Controls the self-occlusion of the lens, creating a cat's eye effect."); + + /// + /// Anamorphism content + /// + public static readonly GUIContent anamorphism = EditorGUIUtility.TrTextContent("Anamorphism", "Use the slider to stretch the sensor to simulate an anamorphic look."); } } } diff --git a/com.unity.render-pipelines.high-definition/Editor/RenderPipeline/Camera/HDCameraUI.Drawers.cs b/com.unity.render-pipelines.high-definition/Editor/RenderPipeline/Camera/HDCameraUI.Drawers.cs index 41d9556b7bb..9d31cc4b9e6 100644 --- a/com.unity.render-pipelines.high-definition/Editor/RenderPipeline/Camera/HDCameraUI.Drawers.cs +++ b/com.unity.render-pipelines.high-definition/Editor/RenderPipeline/Camera/HDCameraUI.Drawers.cs @@ -1,4 +1,3 @@ -using System.Linq; using UnityEngine; using UnityEngine.Rendering.HighDefinition; diff --git a/com.unity.render-pipelines.high-definition/Editor/RenderPipeline/Camera/HDCameraUI.PhysicalCamera.Drawers.cs b/com.unity.render-pipelines.high-definition/Editor/RenderPipeline/Camera/HDCameraUI.PhysicalCamera.Drawers.cs index 258edd27d3a..d4adc1025e2 100644 --- a/com.unity.render-pipelines.high-definition/Editor/RenderPipeline/Camera/HDCameraUI.PhysicalCamera.Drawers.cs +++ b/com.unity.render-pipelines.high-definition/Editor/RenderPipeline/Camera/HDCameraUI.PhysicalCamera.Drawers.cs @@ -1,8 +1,3 @@ -using System; -using System.Runtime.CompilerServices; -using UnityEngine; -using UnityEngine.Rendering.HighDefinition; - namespace UnityEditor.Rendering.HighDefinition { using CED = CoreEditorDrawer; @@ -19,9 +14,9 @@ partial class PhysicalCamera CED.Group( GroupOption.Indent, CameraUI.PhysicalCamera.Drawer_PhysicalCamera_CameraBody_Sensor, - Drawer_PhysicalCamera_CameraBody_ISO, - Drawer_PhysicalCamera_CameraBody_ShutterSpeed, - Drawer_PhysicalCamera_CameraBody_GateFit + CameraUI.PhysicalCamera.Drawer_PhysicalCamera_CameraBody_ISO, + CameraUI.PhysicalCamera.Drawer_PhysicalCamera_CameraBody_ShutterSpeed, + CameraUI.PhysicalCamera.Drawer_PhysicalCamera_CameraBody_GateFit ) ), CED.Group( @@ -31,16 +26,16 @@ partial class PhysicalCamera GroupOption.Indent, CameraUI.PhysicalCamera.Drawer_PhysicalCamera_Lens_FocalLength, CameraUI.PhysicalCamera.Drawer_PhysicalCamera_Lens_Shift, - Drawer_PhysicalCamera_Lens_Aperture, - Drawer_PhysicalCamera_FocusDistance + CameraUI.PhysicalCamera.Drawer_PhysicalCamera_Lens_Aperture, + CameraUI.PhysicalCamera.Drawer_PhysicalCamera_FocusDistance ) ), CED.Group( - Styles.apertureShape, + CameraUI.PhysicalCamera.Styles.apertureShape, GroupOption.Indent, CED.Group( GroupOption.Indent, - Drawer_PhysicalCamera_ApertureShape + CameraUI.PhysicalCamera.Drawer_PhysicalCamera_ApertureShape ) ) ); @@ -53,7 +48,7 @@ partial class PhysicalCamera CED.Group( GroupOption.Indent, CameraUI.PhysicalCamera.Drawer_PhysicalCamera_CameraBody_Sensor, - Drawer_PhysicalCamera_CameraBody_GateFit + CameraUI.PhysicalCamera.Drawer_PhysicalCamera_CameraBody_GateFit ) ), CED.Group( @@ -66,168 +61,6 @@ partial class PhysicalCamera ) ) ); - - static void Drawer_PhysicalCamera_FocusDistance(SerializedHDCamera p, Editor owner) - { - EditorGUILayout.PropertyField(p.focusDistance, Styles.focusDistance); - } - - static void Drawer_PhysicalCamera_CameraBody_ISO(SerializedHDCamera p, Editor owner) - { - EditorGUILayout.PropertyField(p.iso, Styles.ISO); - } - - static EditorPrefBoolFlags m_ShutterSpeedState = new EditorPrefBoolFlags($"HDRP:{typeof(HDCameraUI).Name}:ShutterSpeedState"); - - enum ShutterSpeedUnit - { - Second, - OneOverSecond - } - - static readonly string[] k_ShutterSpeedUnitNames = - { - "Second", - "1 \u2215 Second" // Don't use a slash here else Unity will auto-create a submenu... - }; - - static void Drawer_PhysicalCamera_CameraBody_GateFit(SerializedHDCamera p, Editor owner) - { - using (var horizontal = new EditorGUILayout.HorizontalScope()) - using (var propertyScope = new EditorGUI.PropertyScope(horizontal.rect, CameraUI.PhysicalCamera.Styles.gateFit, p.gateFit)) - using (var checkScope = new EditorGUI.ChangeCheckScope()) - { - int gateValue = (int)(Camera.GateFitMode)EditorGUILayout.EnumPopup(propertyScope.content, (Camera.GateFitMode)p.gateFit.intValue); - if (checkScope.changed) - { - p.gateFit.intValue = gateValue; - } - // Change same property on base camera - p.baseCameraSettings.gateFit.intValue = gateValue; - } - } - - static void Drawer_PhysicalCamera_CameraBody_ShutterSpeed(SerializedHDCamera p, Editor owner) - { - // 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.Popup(unitMenu, (int)m_ShutterSpeedState.value, k_ShutterSpeedUnitNames); - // Reset the indent level - EditorGUI.indentLevel = oldIndentLevel; - - EditorGUI.BeginProperty(fieldRect, Styles.shutterSpeed, p.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 && p.shutterSpeed.floatValue > 0) - p.shutterSpeed.floatValue = 1.0f / p.shutterSpeed.floatValue; - EditorGUI.PropertyField(fieldRect, p.shutterSpeed, Styles.shutterSpeed); - if (m_ShutterSpeedState.value == ShutterSpeedUnit.OneOverSecond && p.shutterSpeed.floatValue > 0) - p.shutterSpeed.floatValue = 1.0f / p.shutterSpeed.floatValue; - } - EditorGUI.EndProperty(); - } - - static void Drawer_PhysicalCamera_Lens_Aperture(SerializedHDCamera p, Editor owner) - { - // 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, p.aperture.floatValue, HDPhysicalCamera.kMinAperture, HDPhysicalCamera.kMaxAperture); - - // keep only 2 digits of precision, like the otehr editor fields - newVal = Mathf.Floor(100 * newVal) / 100.0f; - - if (p.aperture.floatValue != newVal) - { - p.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, p.aperture.floatValue.ToString()); - if (float.TryParse(newAperture, out float parsedValue)) - p.aperture.floatValue = Mathf.Clamp(parsedValue, HDPhysicalCamera.kMinAperture, HDPhysicalCamera.kMaxAperture); - } - - EditorGUILayout.EndHorizontal(); - EditorGUILayout.Space(EditorGUIUtility.singleLineHeight); - } - - static void Drawer_PhysicalCamera_ApertureShape(SerializedHDCamera p, Editor owner) - { - var cam = p.baseCameraSettings; - - EditorGUILayout.PropertyField(p.bladeCount, Styles.bladeCount); - - using (var horizontal = new EditorGUILayout.HorizontalScope()) - using (var propertyScope = new EditorGUI.PropertyScope(horizontal.rect, Styles.curvature, p.curvature)) - { - var v = p.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, HDPhysicalCamera.kMinAperture, HDPhysicalCamera.kMaxAperture); - v.y = EditorGUI.FloatField(floatFieldRight, v.y); - - p.curvature.vector2Value = v; - } - - EditorGUILayout.PropertyField(p.barrelClipping, Styles.barrelClipping); - EditorGUILayout.PropertyField(p.anamorphism, Styles.anamorphism); - } } } } diff --git a/com.unity.render-pipelines.high-definition/Editor/RenderPipeline/Camera/HDCameraUI.PhysicalCamera.Skin.cs b/com.unity.render-pipelines.high-definition/Editor/RenderPipeline/Camera/HDCameraUI.PhysicalCamera.Skin.cs index 30c93810df7..e69de29bb2d 100644 --- a/com.unity.render-pipelines.high-definition/Editor/RenderPipeline/Camera/HDCameraUI.PhysicalCamera.Skin.cs +++ b/com.unity.render-pipelines.high-definition/Editor/RenderPipeline/Camera/HDCameraUI.PhysicalCamera.Skin.cs @@ -1,29 +0,0 @@ -using System.Linq; -using UnityEngine; - -namespace UnityEditor.Rendering.HighDefinition -{ - static partial class HDCameraUI - { - partial class PhysicalCamera - { - class Styles - { - // Camera Body - 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."); - public static readonly GUIContent shutterSpeed = EditorGUIUtility.TrTextContent("Shutter Speed", "The amount of time the Camera sensor is capturing light."); - - // Lens - public static readonly GUIContent aperture = EditorGUIUtility.TrTextContent("Aperture", "The f-stop (f-number) of the lens. Lower values give a wider lens aperture."); - 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 - 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."); - public static readonly GUIContent bladeCount = EditorGUIUtility.TrTextContent("Blade Count", "The number of blades in the lens aperture. Higher values give a rounder aperture shape."); - 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."); - public static readonly GUIContent barrelClipping = EditorGUIUtility.TrTextContent("Barrel Clipping", "Controls the self-occlusion of the lens, creating a cat's eye effect."); - public static readonly GUIContent anamorphism = EditorGUIUtility.TrTextContent("Anamorphism", "Use the slider to stretch the sensor to simulate an anamorphic look."); - } - } - } -} diff --git a/com.unity.render-pipelines.high-definition/Editor/RenderPipeline/Camera/HDCameraUI.PresetInspector.cs b/com.unity.render-pipelines.high-definition/Editor/RenderPipeline/Camera/HDCameraUI.PresetInspector.cs index da3552b8932..427f261c5a7 100644 --- a/com.unity.render-pipelines.high-definition/Editor/RenderPipeline/Camera/HDCameraUI.PresetInspector.cs +++ b/com.unity.render-pipelines.high-definition/Editor/RenderPipeline/Camera/HDCameraUI.PresetInspector.cs @@ -1,6 +1,4 @@ -using System.Linq; using UnityEngine; -using UnityEngine.Rendering.HighDefinition; namespace UnityEditor.Rendering.HighDefinition { diff --git a/com.unity.render-pipelines.high-definition/Editor/RenderPipeline/Camera/SerializedHDCamera.cs b/com.unity.render-pipelines.high-definition/Editor/RenderPipeline/Camera/SerializedHDCamera.cs index e13b17670a3..c6d96dcb5ee 100644 --- a/com.unity.render-pipelines.high-definition/Editor/RenderPipeline/Camera/SerializedHDCamera.cs +++ b/com.unity.render-pipelines.high-definition/Editor/RenderPipeline/Camera/SerializedHDCamera.cs @@ -21,15 +21,6 @@ class SerializedHDCamera : ISerializedCamera public SerializedProperty antialiasing { get; } // HDRP specific properties - public SerializedProperty gateFit; - public SerializedProperty focusDistance; - public SerializedProperty iso; - public SerializedProperty shutterSpeed; - public SerializedProperty aperture; - public SerializedProperty bladeCount; - public SerializedProperty curvature; - public SerializedProperty barrelClipping; - public SerializedProperty anamorphism; public SerializedProperty exposureTarget; public SerializedProperty allowDeepLearningSuperSampling; @@ -83,17 +74,6 @@ public SerializedHDCamera(SerializedObject serializedObject) clearDepth = serializedAdditionalDataObject.Find((HDAdditionalCameraData d) => d.clearDepth); antialiasing = serializedAdditionalDataObject.Find((HDAdditionalCameraData d) => d.antialiasing); - // HDRP specific properties - gateFit = serializedAdditionalDataObject.FindProperty("physicalParameters.m_GateFit"); - focusDistance = serializedAdditionalDataObject.FindProperty("physicalParameters.m_FocusDistance"); - iso = serializedAdditionalDataObject.FindProperty("physicalParameters.m_Iso"); - shutterSpeed = serializedAdditionalDataObject.FindProperty("physicalParameters.m_ShutterSpeed"); - aperture = serializedAdditionalDataObject.FindProperty("physicalParameters.m_Aperture"); - bladeCount = serializedAdditionalDataObject.FindProperty("physicalParameters.m_BladeCount"); - curvature = serializedAdditionalDataObject.FindProperty("physicalParameters.m_Curvature"); - barrelClipping = serializedAdditionalDataObject.FindProperty("physicalParameters.m_BarrelClipping"); - anamorphism = serializedAdditionalDataObject.FindProperty("physicalParameters.m_Anamorphism"); - exposureTarget = serializedAdditionalDataObject.Find((HDAdditionalCameraData d) => d.exposureTarget); allowDeepLearningSuperSampling = serializedAdditionalDataObject.Find((HDAdditionalCameraData d) => d.allowDeepLearningSuperSampling); diff --git a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Camera/HDAdditionalCameraData.Migration.cs b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Camera/HDAdditionalCameraData.Migration.cs index e3ba9fc8086..49b70119c11 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Camera/HDAdditionalCameraData.Migration.cs +++ b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Camera/HDAdditionalCameraData.Migration.cs @@ -28,13 +28,15 @@ protected enum Version AddCustomPostprocessAndCustomPass, /// Version Step. UpdateMSAA, + /// Version Step. + UpdatePhysicalCameraPropertiesToCore } [SerializeField, FormerlySerializedAs("version")] [ExcludeCopy] Version m_Version = MigrationDescription.LastVersion(); - static readonly MigrationDescription k_Migration = MigrationDescription.New( + private static readonly MigrationDescription k_Migration = MigrationDescription.New( MigrationStep.New(Version.SeparatePassThrough, (HDAdditionalCameraData data) => { #pragma warning disable 618 // Type or member is obsolete @@ -76,6 +78,23 @@ protected enum Version MigrationStep.New(Version.UpdateMSAA, (HDAdditionalCameraData data) => { FrameSettings.MigrateMSAA(ref data.renderingPathCustomFrameSettings, ref data.renderingPathCustomFrameSettingsOverrideMask); + }), + MigrationStep.New(Version.UpdatePhysicalCameraPropertiesToCore, (HDAdditionalCameraData data) => + { + var camera = data.GetComponent(); + var physicalProps = data.physicalParameters; + if (camera != null) + { + camera.iso = physicalProps.iso; + camera.shutterSpeed = physicalProps.shutterSpeed; + camera.aperture = physicalProps.aperture; + camera.focusDistance = physicalProps.focusDistance; + camera.gateFit = physicalProps.m_GateFit; + camera.bladeCount = physicalProps.bladeCount; + camera.curvature = physicalProps.curvature; + camera.barrelClipping = physicalProps.barrelClipping; + camera.anamorphism = physicalProps.anamorphism; + } }) ); diff --git a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Camera/HDAdditionalCameraData.cs b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Camera/HDAdditionalCameraData.cs index c46288c0ddb..8c9ef77cef8 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Camera/HDAdditionalCameraData.cs +++ b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Camera/HDAdditionalCameraData.cs @@ -8,6 +8,7 @@ namespace UnityEngine.Rendering.HighDefinition /// Holds the physical settings set on cameras. /// [Serializable] + [Obsolete("Properties have been migrated to Camera class", false)] public struct HDPhysicalCamera { /// @@ -36,14 +37,14 @@ public struct HDPhysicalCamera // Lens // Note: focalLength is already defined in the regular camera component - [SerializeField] [Range(kMinAperture, kMaxAperture)] float m_Aperture; + [SerializeField] [Range(Camera.kMinAperture, Camera.kMaxAperture)] float m_Aperture; [SerializeField] [Min(0.1f)] float m_FocusDistance; #pragma warning disable 0414 - [SerializeField] Camera.GateFitMode m_GateFit; // This is private with no public access because it is mainly just used to drive UX, the code should still access the main camera version. + [SerializeField] internal Camera.GateFitMode m_GateFit; // This is private with no public access because it is mainly just used to drive UX, the code should still access the main camera version. #pragma warning restore 0414 // Aperture shape - [SerializeField] [Range(kMinBladeCount, kMaxBladeCount)] int m_BladeCount; + [SerializeField] [Range(Camera.kMinBladeCount, Camera.kMaxBladeCount)] int m_BladeCount; [SerializeField] Vector2 m_Curvature; [SerializeField] [Range(0f, 1f)] float m_BarrelClipping; [SerializeField] [Range(-1f, 1f)] float m_Anamorphism; @@ -81,7 +82,7 @@ public float shutterSpeed public float aperture { get => m_Aperture; - set => m_Aperture = Mathf.Clamp(value, kMinAperture, kMaxAperture); + set => m_Aperture = Mathf.Clamp(value, Camera.kMinAperture, Camera.kMaxAperture); } /// @@ -90,7 +91,7 @@ public float aperture public int bladeCount { get => m_BladeCount; - set => m_BladeCount = Mathf.Clamp(value, kMinBladeCount, kMaxBladeCount); + set => m_BladeCount = Mathf.Clamp(value, Camera.kMinBladeCount, Camera.kMaxBladeCount); } /// @@ -101,8 +102,8 @@ public Vector2 curvature get => m_Curvature; set { - m_Curvature.x = Mathf.Max(value.x, kMinAperture); - m_Curvature.y = Mathf.Min(value.y, kMaxAperture); + m_Curvature.x = Mathf.Max(value.x, Camera.kMinAperture); + m_Curvature.y = Mathf.Min(value.y, Camera.kMaxAperture); } } @@ -335,6 +336,7 @@ public enum TAAQualityLevel /// Physical camera parameters. [ValueCopy] // reference should not be same. only content. + [Obsolete("Physical camera properties have been migrated to Camera.", false)] public HDPhysicalCamera physicalParameters = HDPhysicalCamera.GetDefaults(); /// Vertical flip mode. @@ -616,7 +618,6 @@ public void CopyTo(HDAdditionalCameraData data) data.probeLayerMask = probeLayerMask; data.hasPersistentHistory = hasPersistentHistory; data.exposureTarget = exposureTarget; - physicalParameters = data.physicalParameters; data.renderingPathCustomFrameSettings = renderingPathCustomFrameSettings; data.renderingPathCustomFrameSettingsOverrideMask = renderingPathCustomFrameSettingsOverrideMask; diff --git a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Camera/HDCamera.cs b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Camera/HDCamera.cs index a0b6e5bab8a..9d3670896b8 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Camera/HDCamera.cs +++ b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Camera/HDCamera.cs @@ -618,10 +618,6 @@ RTHandle Allocator(string id, int frameIndex, RTHandleSystem rtHandleSystem) internal bool allowDynamicResolution => m_AdditionalCameraData != null && m_AdditionalCameraData.allowDynamicResolution; - // We set the values of the physical camera in the Update() call. Here we initialize with - // the defaults, in case someone is trying to access the values before the first Update - internal HDPhysicalCamera physicalParameters { get; private set; } = HDPhysicalCamera.GetDefaults(); - internal IEnumerable aovRequests => m_AdditionalCameraData != null && !m_AdditionalCameraData.Equals(null) ? m_AdditionalCameraData.aovRequests @@ -1690,7 +1686,6 @@ void UpdateVolumeAndPhysicalParameters() { volumeLayerMask = m_AdditionalCameraData.volumeLayerMask; volumeAnchor = m_AdditionalCameraData.volumeAnchorOverride; - physicalParameters = m_AdditionalCameraData.physicalParameters; } else { @@ -1708,7 +1703,6 @@ void UpdateVolumeAndPhysicalParameters() { volumeLayerMask = mainCamAdditionalData.volumeLayerMask; volumeAnchor = mainCamAdditionalData.volumeAnchorOverride; - physicalParameters = mainCamAdditionalData.physicalParameters; needFallback = false; } } @@ -1716,8 +1710,6 @@ void UpdateVolumeAndPhysicalParameters() if (needFallback) { volumeLayerMask = GetSceneViewLayerMaskFallback(); - // Use the default physical camera values so the exposure will look reasonable - physicalParameters = HDPhysicalCamera.GetDefaults(); } } } diff --git a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/HDRenderPipeline.PostProcess.cs b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/HDRenderPipeline.PostProcess.cs index 9bf183904bd..5508d9c3c89 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/HDRenderPipeline.PostProcess.cs +++ b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/HDRenderPipeline.PostProcess.cs @@ -153,9 +153,6 @@ public RTHandle Allocator(string id, int frameIndex, RTHandleSystem rtHandleSyst // Debug Exposure compensation (Drive by debug menu) to add to all exposure processed value float m_DebugExposureCompensation; - // Physical camera copy - HDPhysicalCamera m_PhysicalCamera; - // HDRP has the following behavior regarding alpha: // - If post processing is disabled, the alpha channel of the rendering passes (if any) will be passed to the frame buffer by the final pass // - If post processing is enabled, then post processing passes will either copy (exposure, color grading, etc) or process (DoF, TAA, etc) the alpha channel, if one exists. @@ -323,9 +320,6 @@ void BeginPostProcessFrame(CommandBuffer cmd, HDCamera camera, HDRenderPipeline m_AfterDynamicResUpscaleRes = new Vector2Int((int)Mathf.Round(camera.finalViewport.width), (int)Mathf.Round(camera.finalViewport.height)); m_BeforeDynamicResUpscaleRes = new Vector2Int(camera.actualWidth, camera.actualHeight); - // Grab a copy of the physical camera settings - m_PhysicalCamera = camera.physicalParameters; - // Prefetch all the volume components we need to save some cycles as most of these will // be needed in multiple places var stack = camera.volumeStack; @@ -982,7 +976,7 @@ void DoFixedExposure(HDCamera hdCamera, CommandBuffer cmd) else // ExposureMode.UsePhysicalCamera { kernel = cs.FindKernel("KManualCameraExposure"); - exposureParams = new Vector4(m_Exposure.compensation.value + m_DebugExposureCompensation, m_PhysicalCamera.aperture, m_PhysicalCamera.shutterSpeed, m_PhysicalCamera.iso); + exposureParams = new Vector4(m_Exposure.compensation.value + m_DebugExposureCompensation, hdCamera.camera.aperture, hdCamera.camera.shutterSpeed, hdCamera.camera.iso); } cmd.SetComputeVectorParam(cs, HDShaderIDs._ExposureParams, exposureParams); @@ -2000,7 +1994,7 @@ struct DepthOfFieldParameters public bool useMipSafePath; } - DepthOfFieldParameters PrepareDoFParameters(HDCamera camera) + DepthOfFieldParameters PrepareDoFParameters(HDCamera hdCamera) { DepthOfFieldParameters parameters = new DepthOfFieldParameters(); @@ -2046,14 +2040,14 @@ DepthOfFieldParameters PrepareDoFParameters(HDCamera camera) parameters.pbDoFCombineKernel = parameters.pbDoFGatherCS.FindKernel("KMain"); parameters.minMaxCoCTileSize = 8; - parameters.camera = camera; + parameters.camera = hdCamera; parameters.viewportSize = postProcessViewportSize; - parameters.resetPostProcessingHistory = camera.resetPostProcessingHistory; + parameters.resetPostProcessingHistory = hdCamera.resetPostProcessingHistory; parameters.nearLayerActive = m_DepthOfField.IsNearLayerActive(); parameters.farLayerActive = m_DepthOfField.IsFarLayerActive(); parameters.highQualityFiltering = m_DepthOfField.highQualityFiltering; - parameters.useTiles = !camera.xr.singlePassEnabled; + parameters.useTiles = !hdCamera.xr.singlePassEnabled; parameters.resolution = m_DepthOfField.resolution; @@ -2076,11 +2070,12 @@ DepthOfFieldParameters PrepareDoFParameters(HDCamera camera) parameters.threadGroup8 = new Vector2Int(threadGroup8X, threadGroup8Y); - parameters.physicalCameraCurvature = m_PhysicalCamera.curvature; - parameters.physicalCameraAnamorphism = m_PhysicalCamera.anamorphism; - parameters.physicalCameraAperture = m_PhysicalCamera.aperture; - parameters.physicalCameraBarrelClipping = m_PhysicalCamera.barrelClipping; - parameters.physicalCameraBladeCount = m_PhysicalCamera.bladeCount; + var camera = hdCamera.camera; + parameters.physicalCameraCurvature = camera.curvature; + parameters.physicalCameraAnamorphism = camera.anamorphism; + parameters.physicalCameraAperture = camera.aperture; + parameters.physicalCameraBarrelClipping = camera.barrelClipping; + parameters.physicalCameraBladeCount = camera.bladeCount; parameters.nearFocusStart = m_DepthOfField.nearFocusStart.value; parameters.nearFocusEnd = m_DepthOfField.nearFocusEnd.value; @@ -2090,7 +2085,7 @@ DepthOfFieldParameters PrepareDoFParameters(HDCamera camera) if (m_DepthOfField.focusDistanceMode.value == FocusDistanceMode.Volume) parameters.focusDistance = m_DepthOfField.focusDistance.value; else - parameters.focusDistance = m_PhysicalCamera.focusDistance; + parameters.focusDistance = hdCamera.camera.focusDistance; parameters.focusMode = m_DepthOfField.focusMode.value; @@ -2178,7 +2173,7 @@ DepthOfFieldParameters PrepareDoFParameters(HDCamera camera) parameters.resolution = DepthOfFieldResolution.Half; } - if (camera.msaaEnabled) + if (hdCamera.msaaEnabled) { // When MSAA is enabled, DoF should use the min depth of the MSAA samples to avoid 1-pixel ringing around in-focus objects [case 1347291] parameters.dofCoCCS.EnableKeyword("USE_MIN_DEPTH"); @@ -2247,7 +2242,7 @@ static void DoDepthOfField(in DepthOfFieldParameters dofParameters, CommandBuffe int bladeCount = dofParameters.physicalCameraBladeCount; - float rotation = (dofParameters.physicalCameraAperture - HDPhysicalCamera.kMinAperture) / (HDPhysicalCamera.kMaxAperture - HDPhysicalCamera.kMinAperture); + float rotation = (dofParameters.physicalCameraAperture - Camera.kMinAperture) / (Camera.kMaxAperture - Camera.kMinAperture); rotation *= (360f / bladeCount) * Mathf.Deg2Rad; // TODO: Crude approximation, make it correct float ngonFactor = 1f; @@ -3862,7 +3857,7 @@ void PrepareBloomData(RenderGraph renderGraph, in RenderGraphBuilder builder, Bl if (m_Bloom.anamorphic.value) { // Positive anamorphic ratio values distort vertically - negative is horizontal - float anamorphism = m_PhysicalCamera.anamorphism * 0.5f; + float anamorphism = camera.camera.anamorphism * 0.5f; scaleW *= anamorphism < 0 ? 1f + anamorphism : 1f; scaleH *= anamorphism > 0 ? 1f - anamorphism : 1f; } diff --git a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/PathTracing/PathTracing.cs b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/PathTracing/PathTracing.cs index 5e4c0d8c834..15eee02fd23 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/PathTracing/PathTracing.cs +++ b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/PathTracing/PathTracing.cs @@ -281,9 +281,9 @@ private Vector4 ComputeDoFConstants(HDCamera hdCamera, PathTracing settings) bool enableDof = (dofSettings.focusMode.value == DepthOfFieldMode.UsePhysicalCamera) && !(hdCamera.camera.cameraType == CameraType.SceneView); // focalLength is in mm, so we need to convert to meters. We also want the aperture radius, not diameter, so we divide by two. - float apertureRadius = (enableDof && hdCamera.physicalParameters.aperture > 0) ? 0.5f * 0.001f * hdCamera.camera.focalLength / hdCamera.physicalParameters.aperture : 0.0f; + float apertureRadius = (enableDof && hdCamera.camera.aperture > 0) ? 0.5f * 0.001f * hdCamera.camera.focalLength / hdCamera.camera.aperture : 0.0f; - float focusDistance = (dofSettings.focusDistanceMode.value == FocusDistanceMode.Volume) ? dofSettings.focusDistance.value : hdCamera.physicalParameters.focusDistance; + float focusDistance = (dofSettings.focusDistanceMode.value == FocusDistanceMode.Volume) ? dofSettings.focusDistance.value : hdCamera.camera.focusDistance; return new Vector4(apertureRadius, focusDistance, 0.0f, 0.0f); } diff --git a/com.unity.render-pipelines.universal/Editor/Camera/UniversalRenderPipelineCameraUI.PhysicalCamera.Drawers.cs b/com.unity.render-pipelines.universal/Editor/Camera/UniversalRenderPipelineCameraUI.PhysicalCamera.Drawers.cs index b79f0545473..5697d67c208 100644 --- a/com.unity.render-pipelines.universal/Editor/Camera/UniversalRenderPipelineCameraUI.PhysicalCamera.Drawers.cs +++ b/com.unity.render-pipelines.universal/Editor/Camera/UniversalRenderPipelineCameraUI.PhysicalCamera.Drawers.cs @@ -14,6 +14,8 @@ public partial class PhysicalCamera CED.Group( GroupOption.Indent, CameraUI.PhysicalCamera.Drawer_PhysicalCamera_CameraBody_Sensor, + CameraUI.PhysicalCamera.Drawer_PhysicalCamera_CameraBody_ISO, + CameraUI.PhysicalCamera.Drawer_PhysicalCamera_CameraBody_ShutterSpeed, CameraUI.PhysicalCamera.Drawer_PhysicalCamera_CameraBody_GateFit ) ), @@ -23,7 +25,17 @@ public partial class PhysicalCamera CED.Group( GroupOption.Indent, CameraUI.PhysicalCamera.Drawer_PhysicalCamera_Lens_FocalLength, - CameraUI.PhysicalCamera.Drawer_PhysicalCamera_Lens_Shift + CameraUI.PhysicalCamera.Drawer_PhysicalCamera_Lens_Shift, + CameraUI.PhysicalCamera.Drawer_PhysicalCamera_Lens_Aperture, + CameraUI.PhysicalCamera.Drawer_PhysicalCamera_FocusDistance + ) + ), + CED.Group( + CameraUI.PhysicalCamera.Styles.apertureShape, + GroupOption.Indent, + CED.Group( + GroupOption.Indent, + CameraUI.PhysicalCamera.Drawer_PhysicalCamera_ApertureShape ) ) ); diff --git a/com.unity.render-pipelines.universal/Editor/Camera/UniversalRenderPipelineCameraUI.PresetInspector.cs b/com.unity.render-pipelines.universal/Editor/Camera/UniversalRenderPipelineCameraUI.PresetInspector.cs index 0ecd9ab0eec..d6d483e6277 100644 --- a/com.unity.render-pipelines.universal/Editor/Camera/UniversalRenderPipelineCameraUI.PresetInspector.cs +++ b/com.unity.render-pipelines.universal/Editor/Camera/UniversalRenderPipelineCameraUI.PresetInspector.cs @@ -1,6 +1,4 @@ using UnityEngine; -using UnityEngine.Rendering; -using UnityEngine.Rendering.Universal; namespace UnityEditor.Rendering.Universal {