Skip to content

Commit

Permalink
Improve the Inpsector UI View for URP and HDRP
Browse files Browse the repository at this point in the history
  • Loading branch information
szylis committed Jan 3, 2025
1 parent cad175d commit da812cf
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 8 deletions.
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
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,12 @@ private enum CameraExposureMode
MANUAL = 1,
}

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

#region [Components]

[Header("Components")]
Expand All @@ -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")]
Expand Down Expand Up @@ -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

}
}

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

0 comments on commit da812cf

Please sign in to comment.