2025-07-21 18:10:06 +08:00

87 lines
2.9 KiB
C#

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
{
/// <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);
/// <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);
/// <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 };
/// <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);
/// <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);
public bool IsActive() => filtering.overrideState;
public bool IsTileCompatible()
{
return true;
}
}
}