Skip to content

Commit

Permalink
Adopted Camera Feature Manager to URP
Browse files Browse the repository at this point in the history
  • Loading branch information
szylis committed Jan 3, 2025
1 parent 9657215 commit cad175d
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 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 Down Expand Up @@ -115,7 +120,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 +141,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 +183,7 @@ private void Start()

camera.gameObject.SetActive(cameraObjectActive);

#if !USE_URP
// exposure mode
if(exposureComponent != null)
{
Expand All @@ -184,9 +196,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 +225,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 @@ -310,8 +327,12 @@ private void ApplyMotionBlur()
motionBlurComponent.active = motionBlur;
motionBlurComponent.intensity.overrideState = motionBlur;

#if USE_URP
motionBlurComponent.intensity.value = 1f;
#else
float shutterSpeed = camera.GetComponent<HDAdditionalCameraData>().physicalParameters.shutterSpeed;
motionBlurComponent.intensity.value = 2f * shutterSpeed / Time.fixedDeltaTime;
#endif
}
}
}
Expand Down

0 comments on commit cad175d

Please sign in to comment.