using System; using UnityEngine; using UnityEngine.Rendering; using UnityEngine.Rendering.Universal; namespace X.Rendering.Feature { public class AutoExposureVolumeProfile : VolumeComponent, IPostProcessComponent { 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 { /// /// Progressive (smooth) eye adaptation. /// Progressive, /// /// Fixed (instant) eye adaptation. /// Fixed } [Serializable] public sealed class EyeAdaptationParameter : VolumeParameter { } [Range(1f, 99f)] public Vector2Parameter filtering = new Vector2Parameter(new Vector2(50f, 95f)); /// /// Minimum average luminance to consider for auto exposure (in EV). /// [Range(rangeMin, rangeMax), InspectorName("Minimum (EV)")] public FloatParameter minLuminance = new FloatParameter (0f); /// /// Maximum average luminance to consider for auto exposure (in EV). /// [Range(rangeMin, rangeMax), InspectorName("Maximum (EV)")] public FloatParameter maxLuminance = new FloatParameter (0f); /// /// Middle-grey value. Use this to compensate the global exposure of the scene. /// [Min(0f), InspectorName("Exposure Compensation"), Tooltip("Use this to scale the global exposure of the scene.")] public FloatParameter exposureCompensation = new FloatParameter (1f); /// /// The type of eye adaptation to use. /// [InspectorName("Type"), Tooltip("Use \"Progressive\" if you want auto exposure to be animated. Use \"Fixed\" otherwise.")] public EyeAdaptationParameter eyeAdaptation = new EyeAdaptationParameter() { value = EyeAdaptation.Progressive }; /// /// The adaptation speed from a dark to a light environment. /// [Min(0f), Tooltip("Adaptation speed from a dark to a light environment.")] public FloatParameter speedUp = new FloatParameter (2f); /// /// The adaptation speed from a light to a dark environment. /// [Min(0f), Tooltip("Adaptation speed from a light to a dark environment.")] public FloatParameter speedDown = new FloatParameter (1f); public bool IsActive() => filtering.overrideState; public bool IsTileCompatible() { return true; } } }