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 436135eaf..a25d41a78 100644 --- a/Assets/AWSIM/Scripts/Sensors/Camera/CameraSensorFeatureManager.cs +++ b/Assets/AWSIM/Scripts/Sensors/Camera/CameraSensorFeatureManager.cs @@ -1,6 +1,11 @@ using UnityEngine; using UnityEngine.Rendering; + +#if USE_URP +using UnityEngine.Rendering.Universal; +#else using UnityEngine.Rendering.HighDefinition; +#endif namespace AWSIM { @@ -21,6 +26,12 @@ private enum CameraExposureMode MANUAL = 1, } + private enum RenderingType + { + HDRP = 0, + URP = 1 + } + #region [Components] [Header("Components")] @@ -31,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")] @@ -115,7 +134,11 @@ private enum CameraExposureMode #region [Effects Component] private ColorAdjustments colorAdjustmentsComponent = default; + +#if !USE_URP // Exposure effect is only supported by HDRP private Exposure exposureComponent = default; +#endif + private Bloom bloomComponent = default; private ChromaticAberration chromaticAberrationComponent = default; private DepthOfField depthOfFieldComponent = default; @@ -132,10 +155,12 @@ private void Awake() Debug.LogWarning("The required Color Adjustment property is not found in camera volume profile."); } +#if !USE_URP // Exposure effect is only supported by HDRP if(!profile.TryGet(out exposureComponent)) { Debug.LogWarning("The required Exposure property is not found in camera volume profile."); } +#endif if(!profile.TryGet(out bloomComponent)) { @@ -172,6 +197,7 @@ private void Start() camera.gameObject.SetActive(cameraObjectActive); +#if !USE_URP // exposure mode if(exposureComponent != null) { @@ -184,9 +210,12 @@ private void Start() exposureComponent.mode = new ExposureModeParameter(ExposureMode.UsePhysicalCamera, true); } } +#endif +#if !USE_URP // exposure settings ApplyExposureSettings(); +#endif // image adjustments ApplyImageAdjustments(); @@ -210,12 +239,14 @@ private void Start() ApplyMotionBlur(); } +#if !USE_URP private void ApplyExposureSettings() { camera.GetComponent().physicalParameters.iso = ISO; camera.GetComponent().physicalParameters.shutterSpeed = 1f/shutterSpeed; camera.GetComponent().physicalParameters.aperture = aperture; } +#endif private void ApplyImageAdjustments() { @@ -300,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 + } } @@ -310,8 +347,12 @@ private void ApplyMotionBlur() motionBlurComponent.active = motionBlur; motionBlurComponent.intensity.overrideState = motionBlur; +#if USE_URP + motionBlurComponent.intensity.value = (2f / shutterSpeed) / Time.fixedDeltaTime; +#else float shutterSpeed = camera.GetComponent().physicalParameters.shutterSpeed; motionBlurComponent.intensity.value = 2f * shutterSpeed / Time.fixedDeltaTime; +#endif } } }