Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Camera Sensor Feature Manager to Handle URP #380

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ namespace AWSIM
public class CameraSensorFeatureManagerEditor : Editor
{
private bool debugMode = false;
private bool prefabSettings = false;

private SerializedProperty hueProperty;
private SerializedProperty saturationProperty;
Expand All @@ -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()
{
Expand All @@ -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()
Expand All @@ -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)
Expand Down Expand Up @@ -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 ------- //
Expand All @@ -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();
}
Expand Down
41 changes: 41 additions & 0 deletions Assets/AWSIM/Scripts/Sensors/Camera/CameraSensorFeatureManager.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
using UnityEngine;
using UnityEngine.Rendering;

#if USE_URP
using UnityEngine.Rendering.Universal;
#else
using UnityEngine.Rendering.HighDefinition;
#endif

namespace AWSIM
{
Expand All @@ -21,6 +26,12 @@ private enum CameraExposureMode
MANUAL = 1,
}

private enum RenderingType
{
HDRP = 0,
URP = 1
}

#region [Components]

[Header("Components")]
Expand All @@ -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")]
Expand Down Expand Up @@ -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;
Expand All @@ -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<Exposure>(out exposureComponent))
{
Debug.LogWarning("The required Exposure property is not found in camera volume profile.");
}
#endif

if(!profile.TryGet<Bloom>(out bloomComponent))
{
Expand Down Expand Up @@ -172,6 +197,7 @@ private void Start()

camera.gameObject.SetActive(cameraObjectActive);

#if !USE_URP
// exposure mode
if(exposureComponent != null)
{
Expand All @@ -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();
Expand All @@ -210,12 +239,14 @@ private void Start()
ApplyMotionBlur();
}

#if !USE_URP
private void ApplyExposureSettings()
{
camera.GetComponent<HDAdditionalCameraData>().physicalParameters.iso = ISO;
camera.GetComponent<HDAdditionalCameraData>().physicalParameters.shutterSpeed = 1f/shutterSpeed;
camera.GetComponent<HDAdditionalCameraData>().physicalParameters.aperture = aperture;
}
#endif

private void ApplyImageAdjustments()
{
Expand Down Expand Up @@ -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

}
}

Expand All @@ -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<HDAdditionalCameraData>().physicalParameters.shutterSpeed;
motionBlurComponent.intensity.value = 2f * shutterSpeed / Time.fixedDeltaTime;
#endif
}
}
}
Expand Down
Loading