2025-07-21 18:10:06 +08:00
|
|
|
using System;
|
2025-07-21 12:13:06 +08:00
|
|
|
using UnityEngine;
|
|
|
|
|
using UnityEngine.Rendering;
|
|
|
|
|
using UnityEngine.Rendering.Universal;
|
|
|
|
|
|
|
|
|
|
namespace X.Rendering.Feature
|
|
|
|
|
{
|
2025-07-21 18:10:06 +08:00
|
|
|
|
|
|
|
|
|
2025-07-21 12:13:06 +08:00
|
|
|
public class AutoExposureVolumeProfile : VolumeComponent, IPostProcessComponent
|
|
|
|
|
{
|
2025-07-21 18:10:06 +08:00
|
|
|
public const int rangeMin = -9; // ev
|
|
|
|
|
public const int rangeMax = 9; // ev
|
|
|
|
|
|
|
|
|
|
public static Vector4 GetHistogramScaleOffsetRes()
|
|
|
|
|
{
|
|
|
|
|
float diff = rangeMax - rangeMin;
|
|
|
|
|
float scale = 1f / diff;
|
|
|
|
|
float offset = -rangeMin * scale;
|
|
|
|
|
return new Vector4(scale, offset, Screen.width, Screen.height);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public enum EyeAdaptation
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Progressive (smooth) eye adaptation.
|
|
|
|
|
/// </summary>
|
|
|
|
|
Progressive,
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Fixed (instant) eye adaptation.
|
|
|
|
|
/// </summary>
|
|
|
|
|
Fixed
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Serializable]
|
|
|
|
|
public sealed class EyeAdaptationParameter : VolumeParameter<EyeAdaptation> { }
|
|
|
|
|
|
|
|
|
|
[Range(1f, 99f)]
|
|
|
|
|
public Vector2Parameter filtering = new Vector2Parameter(new Vector2(50f, 95f));
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Minimum average luminance to consider for auto exposure (in EV).
|
|
|
|
|
/// </summary>
|
|
|
|
|
[Range(rangeMin, rangeMax), InspectorName("Minimum (EV)")]
|
|
|
|
|
public FloatParameter minLuminance = new FloatParameter (0f);
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Maximum average luminance to consider for auto exposure (in EV).
|
|
|
|
|
/// </summary>
|
|
|
|
|
[Range(rangeMin, rangeMax), InspectorName("Maximum (EV)")]
|
|
|
|
|
public FloatParameter maxLuminance = new FloatParameter (0f);
|
2025-07-21 12:13:06 +08:00
|
|
|
|
2025-07-21 18:10:06 +08:00
|
|
|
/// <summary>
|
|
|
|
|
/// Middle-grey value. Use this to compensate the global exposure of the scene.
|
|
|
|
|
/// </summary>
|
|
|
|
|
[Min(0f), InspectorName("Exposure Compensation"), Tooltip("Use this to scale the global exposure of the scene.")]
|
|
|
|
|
public FloatParameter exposureCompensation = new FloatParameter (1f);
|
2025-07-21 12:13:06 +08:00
|
|
|
|
2025-07-21 18:10:06 +08:00
|
|
|
/// <summary>
|
|
|
|
|
/// The type of eye adaptation to use.
|
|
|
|
|
/// </summary>
|
|
|
|
|
[InspectorName("Type"), Tooltip("Use \"Progressive\" if you want auto exposure to be animated. Use \"Fixed\" otherwise.")]
|
|
|
|
|
public EyeAdaptationParameter eyeAdaptation = new EyeAdaptationParameter() { value = EyeAdaptation.Progressive };
|
2025-07-21 12:13:06 +08:00
|
|
|
|
2025-07-21 18:10:06 +08:00
|
|
|
/// <summary>
|
|
|
|
|
/// The adaptation speed from a dark to a light environment.
|
|
|
|
|
/// </summary>
|
|
|
|
|
[Min(0f), Tooltip("Adaptation speed from a dark to a light environment.")]
|
|
|
|
|
public FloatParameter speedUp = new FloatParameter (2f);
|
2025-07-21 12:13:06 +08:00
|
|
|
|
2025-07-21 18:10:06 +08:00
|
|
|
/// <summary>
|
|
|
|
|
/// The adaptation speed from a light to a dark environment.
|
|
|
|
|
/// </summary>
|
|
|
|
|
[Min(0f), Tooltip("Adaptation speed from a light to a dark environment.")]
|
|
|
|
|
public FloatParameter speedDown = new FloatParameter (1f);
|
2025-07-21 12:13:06 +08:00
|
|
|
|
|
|
|
|
|
2025-07-21 18:10:06 +08:00
|
|
|
public bool IsActive() => filtering.overrideState;
|
2025-07-21 12:13:06 +08:00
|
|
|
|
|
|
|
|
public bool IsTileCompatible()
|
|
|
|
|
{
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|