Skip to content

Commit

Permalink
Added Shapness and Distoration to Feature Manager Script
Browse files Browse the repository at this point in the history
  • Loading branch information
szylis committed Mar 29, 2024
1 parent 6d4d2ef commit 19e2b03
Show file tree
Hide file tree
Showing 3 changed files with 99 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,50 +3,55 @@

namespace AWSIM
{

/// <summary>
/// Editor extension for camera sensor feature manager class.
/// </summary>
[CustomEditor(typeof(CameraSensorFeatureManager))]
public class CameraSensorFeatureManagerEditor : Editor
{

private CameraSensorFeatureManager manager;
private bool debugMode = false;

private SerializedProperty hueProperty;
private SerializedProperty saturationProperty;
private SerializedProperty contrastProperty;
private SerializedProperty postExposureProperty;
private SerializedProperty sharpnessProperty;

private SerializedProperty exposureModeProperty;

private SerializedProperty bloomEffectProperty;
private SerializedProperty chromaticAberrationProperty;
private SerializedProperty depthOfFieldProperty;
private SerializedProperty motionBlurProperty;


private void OnEnable()
{
manager = (CameraSensorFeatureManager)target;

hueProperty = serializedObject.FindProperty("hue");
saturationProperty = serializedObject.FindProperty("saturation");
contrastProperty = serializedObject.FindProperty("contrast");
postExposureProperty =serializedObject.FindProperty("postExposure");
sharpnessProperty = serializedObject.FindProperty("sharpness");

exposureModeProperty = serializedObject.FindProperty("exposureMode");

bloomEffectProperty = serializedObject.FindProperty("bloomEffect");
chromaticAberrationProperty = serializedObject.FindProperty("chromaticAberration");
depthOfFieldProperty = serializedObject.FindProperty("depthOfField");
motionBlurProperty = serializedObject.FindProperty("motionBlur");
}

public override void OnInspectorGUI()
{
// ------ Components ------- //
EditorGUILayout.PropertyField(serializedObject.FindProperty("camera"), true);
EditorGUILayout.PropertyField(serializedObject.FindProperty("cameraSensor"), true);
EditorGUILayout.PropertyField(serializedObject.FindProperty("volume"), true);
EditorGUILayout.PropertyField(serializedObject.FindProperty("profile"), true);

debugMode = GUILayout.Toggle(debugMode, new GUIContent("Show Components", "Debug mode to see the references to the required components"), "Button");

if(debugMode)
{
EditorGUILayout.PropertyField(serializedObject.FindProperty("camera"), true);
EditorGUILayout.PropertyField(serializedObject.FindProperty("cameraSensor"), true);
EditorGUILayout.PropertyField(serializedObject.FindProperty("volume"), true);
EditorGUILayout.PropertyField(serializedObject.FindProperty("profile"), true);
}

// ------ Image Adjustment ------- //
EditorGUILayout.PropertyField(serializedObject.FindProperty("hue"), true);
Expand All @@ -73,6 +78,12 @@ public override void OnInspectorGUI()
EditorGUILayout.PropertyField(serializedObject.FindProperty("postExposureValue"), true);
}

EditorGUILayout.PropertyField(serializedObject.FindProperty("sharpness"), true);
if(sharpnessProperty.boolValue)
{
EditorGUILayout.PropertyField(serializedObject.FindProperty("sharpnessValue"), true);
}

// ------ Exposure Settings ------- //
EditorGUILayout.PropertyField(serializedObject.FindProperty("exposureMode"), true);
if(exposureModeProperty.enumValueIndex != 0)
Expand All @@ -82,9 +93,10 @@ public override void OnInspectorGUI()
EditorGUILayout.PropertyField(serializedObject.FindProperty("aperture"), true);
}


// ------ Additonal Effect ------- //
// ------ Distortion Correction ------- //
EditorGUILayout.PropertyField(serializedObject.FindProperty("distortionCorrection"), true);

// ------ Additonal Effect ------- //
EditorGUILayout.PropertyField(serializedObject.FindProperty("bloomEffect"), true);
if(bloomEffectProperty.boolValue)
{
Expand Down
6 changes: 6 additions & 0 deletions Assets/AWSIM/Scripts/Sensors/Camera/CameraSensor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,12 @@ public class ImageOnGui
[SerializeField] Camera cameraObject;

[SerializeField] bool enableLensDistortionCorrection = false;
public bool EnableLensDistortionCorrection
{
get => enableLensDistortionCorrection;
set => enableLensDistortionCorrection = value;
}

[Range(0.0f, 1.0f)] public float sharpeningStrength = 0.0f;

RenderTexture targetRenderTexture;
Expand Down
88 changes: 68 additions & 20 deletions Assets/AWSIM/Scripts/Sensors/Camera/CameraSensorFeatureManager.cs
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
using System.Collections;
using System.Collections.Generic;
using System.Runtime.CompilerServices;
using Unity.VisualScripting;
using UnityEditor;
using UnityEngine;
using UnityEngine.Rendering;
using UnityEngine.Rendering.HighDefinition;

namespace AWSIM
{

/// <summary>
/// Camera sensor feature manager class, serves as a user interface for configuring parameters related to camera features.
/// </summary>
public class CameraSensorFeatureManager : MonoBehaviour
{
private enum CameraExposureMode
Expand Down Expand Up @@ -46,18 +43,39 @@ private enum CameraExposureMode
[SerializeField] private bool postExposure = false;
[Range(-10f, 10f)]
[SerializeField] private float postExposureValue = 0f;

[SerializeField] private bool sharpness = false;
[Range(0f, 1f)]
[SerializeField] private float sharpnessValue = 0f;

#endregion

#region [Exposure Settings]

[Header("Exposure Settings")]
[SerializeField] private CameraExposureMode exposureMode = CameraExposureMode.MANUAL;

[Range(1f, 12800f)]
[SerializeField] private int ISO = 200;

[Range(0.001f, 10000f)]
[SerializeField] private float shutterSpeed = 125;

[Range(0.7f, 32f)]
[SerializeField] private float aperture = 16;


[Header("Additonal Effect")]
#endregion

#region [Distortion Correction]

[Header("Lens Distortion Correction")]
[SerializeField] private bool distortionCorrection = false;

#endregion

#region [Additonal Effect]

[Header("Additonal Effect")]
[SerializeField] private bool bloomEffect = false;
[Range(0f, 1f)]
[SerializeField] private float bloomValue = 0f;
Expand All @@ -72,12 +90,12 @@ private enum CameraExposureMode

[SerializeField] private bool motionBlur = false;

#endregion

#region [Effects Component]

private ColorAdjustments colorAdjustmentsComponent = default;
private Exposure exposureComponent = default;

private Bloom bloomComponent = default;
private ChromaticAberration chromaticAberrationComponent = default;
private DepthOfField depthOfFieldComponent = default;
Expand All @@ -91,35 +109,33 @@ private void Awake()
{
if(!profile.TryGet<ColorAdjustments>(out colorAdjustmentsComponent))
{

Debug.LogWarning("The required Color Adjustment property is not found in camera volume profile.");
}

if(!profile.TryGet<Exposure>(out exposureComponent))
{

Debug.LogWarning("The required Exposure property is not found in camera volume profile.");
}


if(!profile.TryGet<Bloom>(out bloomComponent))
{

Debug.LogWarning("The required Bloom property is not found in camera volume profile.");
}

if(!profile.TryGet<ChromaticAberration>(out chromaticAberrationComponent))
{

Debug.LogWarning("The required ChromaticAberration property is not found in camera volume profile.");
}

if(!profile.TryGet<DepthOfField>(out depthOfFieldComponent))
{

Debug.LogWarning("The required DepthOfField property is not found in camera volume profile.");
}

if(!profile.TryGet<MotionBlur>(out motionBlurComponent))
{

Debug.LogWarning("The required MotionBlur property is not found in camera volume profile.");
}

}

private void Start()
Expand All @@ -134,6 +150,8 @@ private void Start()
cameraObjectActive = false;
}

camera.gameObject.SetActive(cameraObjectActive);

// exposure mode
if(exposureComponent != null)
{
Expand All @@ -153,6 +171,12 @@ private void Start()
// image adjustments
ApplyImageAdjustments();

// sharpness
ApplySharpness();

// lens distortion correction
ApplyLensDistortionCorrection();

// bloom effect
ApplyBloom();

Expand All @@ -164,9 +188,6 @@ private void Start()

// motion blur
ApplyMotionBlur();


camera.gameObject.SetActive(cameraObjectActive);
}

private void ApplyExposureSettings()
Expand Down Expand Up @@ -205,6 +226,33 @@ private void ApplyImageAdjustments()
colorAdjustmentsComponent.postExposure.value = postExposureValue;
}

private void ApplySharpness()
{
if(cameraSensor == null)
{
return;
}

if(sharpness)
{
cameraSensor.sharpeningStrength = sharpnessValue;
}
else
{
cameraSensor.sharpeningStrength = 0f;
}
}

private void ApplyLensDistortionCorrection()
{
if(cameraSensor == null)
{
return;
}

cameraSensor.EnableLensDistortionCorrection = distortionCorrection;
}

private void ApplyBloom()
{
if(bloomComponent != null)
Expand Down

0 comments on commit 19e2b03

Please sign in to comment.