From da812cffb9f82026a0bfde6ef15f543d2d7bcb9d Mon Sep 17 00:00:00 2001 From: Szymon Lis Date: Fri, 3 Jan 2025 16:20:30 +0100 Subject: [PATCH] Improve the Inpsector UI View for URP and HDRP --- .../CameraSensorFeatureManagerEditor.cs | 47 ++++++++++++++++--- .../Camera/CameraSensorFeatureManager.cs | 22 ++++++++- 2 files changed, 61 insertions(+), 8 deletions(-) diff --git a/Assets/AWSIM/Scripts/Editor/Sensors/CameraSensorFeatureManagerEditor.cs b/Assets/AWSIM/Scripts/Editor/Sensors/CameraSensorFeatureManagerEditor.cs index 9824a45be..3a2a64244 100644 --- a/Assets/AWSIM/Scripts/Editor/Sensors/CameraSensorFeatureManagerEditor.cs +++ b/Assets/AWSIM/Scripts/Editor/Sensors/CameraSensorFeatureManagerEditor.cs @@ -10,6 +10,7 @@ namespace AWSIM public class CameraSensorFeatureManagerEditor : Editor { private bool debugMode = false; + private bool prefabSettings = false; private SerializedProperty hueProperty; private SerializedProperty saturationProperty; @@ -22,7 +23,9 @@ public class CameraSensorFeatureManagerEditor : Editor private SerializedProperty bloomEffectProperty; private SerializedProperty chromaticAberrationProperty; private SerializedProperty depthOfFieldProperty; + private SerializedProperty motionBlurProperty; + private SerializedProperty targetRendererProperty; private void OnEnable() { @@ -37,6 +40,9 @@ private void OnEnable() bloomEffectProperty = serializedObject.FindProperty("bloomEffect"); chromaticAberrationProperty = serializedObject.FindProperty("chromaticAberration"); depthOfFieldProperty = serializedObject.FindProperty("depthOfField"); + motionBlurProperty = serializedObject.FindProperty("motionBlur"); + + targetRendererProperty = serializedObject.FindProperty("prefabTargetRenderer"); } public override void OnInspectorGUI() @@ -53,6 +59,16 @@ public override void OnInspectorGUI() EditorGUILayout.PropertyField(serializedObject.FindProperty("profile"), true); } + // ------ Prefab Settings ------- // + prefabSettings = GUILayout.Toggle(prefabSettings, new GUIContent("Show Prefab Settings", "Section with prefab settings"), "Button"); + + if(prefabSettings) + { + EditorGUILayout.PropertyField(serializedObject.FindProperty("prefabTargetRenderer"), true); + } + + EditorGUILayout.Space(10f); + // ------ Image Adjustment ------- // EditorGUILayout.PropertyField(serializedObject.FindProperty("hue"), true); if(hueProperty.boolValue) @@ -84,13 +100,17 @@ public override void OnInspectorGUI() EditorGUILayout.PropertyField(serializedObject.FindProperty("sharpnessValue"), true); } - // ------ Exposure Settings ------- // - EditorGUILayout.PropertyField(serializedObject.FindProperty("exposureMode"), true); - if(exposureModeProperty.enumValueIndex != 0) + // Show exposure settings only if the prefab is intended for HDRP. + if(targetRendererProperty.enumValueIndex == 0) { - EditorGUILayout.PropertyField(serializedObject.FindProperty("ISO"), true); - EditorGUILayout.PropertyField(serializedObject.FindProperty("shutterSpeed"), true); - EditorGUILayout.PropertyField(serializedObject.FindProperty("aperture"), true); + // ------ Exposure Settings ------- // + EditorGUILayout.PropertyField(serializedObject.FindProperty("exposureMode"), true); + if(exposureModeProperty.enumValueIndex != 0) + { + EditorGUILayout.PropertyField(serializedObject.FindProperty("ISO"), true); + EditorGUILayout.PropertyField(serializedObject.FindProperty("shutterSpeed"), true); + EditorGUILayout.PropertyField(serializedObject.FindProperty("aperture"), true); + } } // ------ Distortion Correction ------- // @@ -113,10 +133,23 @@ public override void OnInspectorGUI() if(depthOfFieldProperty.boolValue) { EditorGUILayout.PropertyField(serializedObject.FindProperty("focusDistance"), true); + + // Show additional parameters only if the prefab is intended for URP. + if(targetRendererProperty.enumValueIndex == 1) + { + EditorGUILayout.PropertyField(serializedObject.FindProperty("aperture"), true); + } } EditorGUILayout.PropertyField(serializedObject.FindProperty("motionBlur"), true); - + if(motionBlurProperty.boolValue) + { + // Show additional parameters only if the prefab is intended for URP. + if(targetRendererProperty.enumValueIndex == 1) + { + EditorGUILayout.PropertyField(serializedObject.FindProperty("shutterSpeed"), true); + } + } serializedObject.ApplyModifiedProperties(); } diff --git a/Assets/AWSIM/Scripts/Sensors/Camera/CameraSensorFeatureManager.cs b/Assets/AWSIM/Scripts/Sensors/Camera/CameraSensorFeatureManager.cs index 12b5a067c..a25d41a78 100644 --- a/Assets/AWSIM/Scripts/Sensors/Camera/CameraSensorFeatureManager.cs +++ b/Assets/AWSIM/Scripts/Sensors/Camera/CameraSensorFeatureManager.cs @@ -26,6 +26,12 @@ private enum CameraExposureMode MANUAL = 1, } + private enum RenderingType + { + HDRP = 0, + URP = 1 + } + #region [Components] [Header("Components")] @@ -36,6 +42,14 @@ private enum CameraExposureMode #endregion + #region [Settings] + + [Header("Prefab Settings")] + [Tooltip("The rendering pipeline for which the prefab is intended to be used.")] + [SerializeField] private RenderingType prefabTargetRenderer = RenderingType.HDRP; + + #endregion + #region [Image Adjustment"] [Header("Image Adjustment")] @@ -317,6 +331,12 @@ private void ApplyDepthOfField() depthOfFieldComponent.active = depthOfField; depthOfFieldComponent.focusDistance.overrideState = depthOfField; depthOfFieldComponent.focusDistance.value = focusDistance; + +#if USE_URP + depthOfFieldComponent.aperture.overrideState = depthOfField; + depthOfFieldComponent.aperture.value = aperture; +#endif + } } @@ -328,7 +348,7 @@ private void ApplyMotionBlur() motionBlurComponent.intensity.overrideState = motionBlur; #if USE_URP - motionBlurComponent.intensity.value = 1f; + motionBlurComponent.intensity.value = (2f / shutterSpeed) / Time.fixedDeltaTime; #else float shutterSpeed = camera.GetComponent().physicalParameters.shutterSpeed; motionBlurComponent.intensity.value = 2f * shutterSpeed / Time.fixedDeltaTime;