using System;
namespace UnityEngine.Rendering.Universal
{
///
/// Options to select a tonemapping algorithm to use for color grading.
///
public enum TonemappingMode
{
///
/// Use this option if you do not want to apply tonemapping
///
None,
///
/// Use this option if you only want range-remapping with minimal impact on color hue and saturation.
/// It is generally a great starting point for extensive color grading.
///
Neutral, // Neutral tonemapper
///
/// Use this option to apply a close approximation of the reference ACES tonemapper for a more filmic look.
/// It is more contrasted than Neutral and has an effect on actual color hue and saturation.
/// Note that if you use this tonemapper all the grading operations will be done in the ACES color spaces for optimal precision and results.
///
ACES, // ACES Filmic reference tonemapper (custom approximation)
}
///
/// Available options for when HDR Output is enabled and Tonemap is set to Neutral.
///
public enum NeutralRangeReductionMode
{
///
/// Simple Reinhard tonemapping curve.
///
Reinhard = HDRRangeReduction.Reinhard,
///
/// Range reduction curve as specified in the BT.2390 standard.
///
BT2390 = HDRRangeReduction.BT2390
}
///
/// Preset used when selecting ACES tonemapping for HDR displays.
///
public enum HDRACESPreset
{
///
/// Preset for a display with a maximum range of 1000 nits.
///
ACES1000Nits = HDRRangeReduction.ACES1000Nits,
///
/// Preset for a display with a maximum range of 2000 nits.
///
ACES2000Nits = HDRRangeReduction.ACES2000Nits,
///
/// Preset for a display with a maximum range of 4000 nits.
///
ACES4000Nits = HDRRangeReduction.ACES4000Nits,
}
///
/// A volume component that holds settings for the tonemapping effect.
///
///
/// You can add to a in the Editor to apply a tonemapping post-processing effect.
///
///
/// This sample code shows how settings can be retrieved and modified in runtime:
///
/// using System;
/// using UnityEngine;
/// using UnityEngine.Rendering;
/// using UnityEngine.Rendering.Universal;
///
/// public class ModifyVolumeComponent : MonoBehaviour
/// {
/// [SerializeField] VolumeProfile volumeProfile;
/// [SerializeField] VolumeSettings volumeSettings;
///
/// private bool m_HasRetrievedVolumeComponent;
/// private Tonemapping m_VolumeComponent;
///
/// [Serializable]
/// private struct VolumeSettings
/// {
/// public bool active;
/// public TonemappingModeParameter mode;
/// public NeutralRangeReductionModeParameter neutralHDRRangeReductionMode;
/// public HDRACESPresetParameter acesPreset;
/// public ClampedFloatParameter hueShiftAmount;
/// public BoolParameter detectPaperWhite;
/// public ClampedFloatParameter paperWhite;
/// public BoolParameter detectBrightnessLimits;
/// public ClampedFloatParameter minNits;
/// public ClampedFloatParameter maxNits;
///
///
/// public void SetVolumeComponentSettings(ref Tonemapping volumeComponent)
/// {
/// volumeComponent.active = active;
/// volumeComponent.mode = mode;
/// volumeComponent.neutralHDRRangeReductionMode = neutralHDRRangeReductionMode;
/// volumeComponent.acesPreset = acesPreset;
/// volumeComponent.hueShiftAmount = hueShiftAmount;
/// volumeComponent.detectPaperWhite = detectPaperWhite;
/// volumeComponent.paperWhite = paperWhite;
/// volumeComponent.detectBrightnessLimits = detectBrightnessLimits;
/// volumeComponent.minNits = minNits;
/// volumeComponent.maxNits = maxNits;
/// }
///
/// public void GetVolumeComponentSettings(ref Tonemapping volumeComponent)
/// {
/// active = volumeComponent.active;
/// mode = volumeComponent.mode;
/// neutralHDRRangeReductionMode = volumeComponent.neutralHDRRangeReductionMode;
/// acesPreset = volumeComponent.acesPreset;
/// hueShiftAmount = volumeComponent.hueShiftAmount;
/// detectPaperWhite = volumeComponent.detectPaperWhite;
/// paperWhite = volumeComponent.paperWhite;
/// detectBrightnessLimits = volumeComponent.detectBrightnessLimits;
/// minNits = volumeComponent.minNits;
/// maxNits = volumeComponent.maxNits;
/// }
/// }
///
/// private void Start()
/// {
/// m_HasRetrievedVolumeComponent = GetVolumeComponent(in volumeProfile, ref m_VolumeComponent);
/// if (m_HasRetrievedVolumeComponent)
/// volumeSettings.GetVolumeComponentSettings(ref m_VolumeComponent);
/// }
///
/// private void Update()
/// {
/// if (!m_HasRetrievedVolumeComponent)
/// return;
///
/// volumeSettings.SetVolumeComponentSettings(ref m_VolumeComponent);
/// }
///
/// private static bool GetVolumeComponent(in VolumeProfile volumeProfile, ref Tonemapping volumeComponent)
/// {
/// if (volumeComponent != null)
/// return true;
///
/// if (volumeProfile == null)
/// {
/// Debug.LogError("ModifyVolumeComponent.GetVolumeComponent():\nvolumeProfile has not been assigned.");
/// return false;
/// }
///
/// volumeProfile.TryGet(out Tonemapping component);
/// if (component == null)
/// {
/// Debug.LogError($"ModifyVolumeComponent.GetVolumeComponent():\nMissing component in the \"{volumeProfile.name}\" VolumeProfile ");
/// return false;
/// }
///
/// volumeComponent = component;
/// return true;
/// }
/// }
///
///
///
///
///
///
///
///
///
///
///
[Serializable, VolumeComponentMenu("Post-processing/Tonemapping")]
[SupportedOnRenderPipeline(typeof(UniversalRenderPipelineAsset))]
[URPHelpURL("post-processing-tonemapping")]
public sealed class Tonemapping : VolumeComponent, IPostProcessComponent
{
///
/// Use this to select a tonemapping algorithm to use for color grading.
///
[Tooltip("Select a tonemapping algorithm to use for the color grading process.")]
public TonemappingModeParameter mode = new TonemappingModeParameter(TonemappingMode.None);
// -- HDR Output options --
///
/// Specifies the range reduction mode used when HDR output is enabled and Neutral tonemapping is enabled.
///
[AdditionalProperty]
[Tooltip("Specifies the range reduction mode used when HDR output is enabled and Neutral tonemapping is enabled.")]
public NeutralRangeReductionModeParameter neutralHDRRangeReductionMode = new NeutralRangeReductionModeParameter(NeutralRangeReductionMode.BT2390);
///
/// Specifies the preset for HDR displays.
///
[Tooltip("Use the ACES preset for HDR displays.")]
public HDRACESPresetParameter acesPreset = new HDRACESPresetParameter(HDRACESPreset.ACES1000Nits);
///
/// Specify how much hue to preserve. Values closer to 0 are likely to preserve hue. As values get closer to 1, Unity doesn't correct hue shifts.
///
[Tooltip("Specify how much hue to preserve. Values closer to 0 are likely to preserve hue. As values get closer to 1, Unity doesn't correct hue shifts.")]
public ClampedFloatParameter hueShiftAmount = new ClampedFloatParameter(0.0f, 0.0f, 1.0f);
///
/// Enable to use values detected from the output device as paper white. When enabled, output images might differ between SDR and HDR. For best accuracy, set this value manually.
///
[Tooltip("Enable to use values detected from the output device as paper white. When enabled, output images might differ between SDR and HDR. For best accuracy, set this value manually.")]
public BoolParameter detectPaperWhite = new BoolParameter(false);
///
/// The reference brightness of a paper white surface. This property determines the maximum brightness of UI. The brightness of the scene is scaled relative to this value. The value is in nits.
///
[Tooltip("The reference brightness of a paper white surface. This property determines the maximum brightness of UI. The brightness of the scene is scaled relative to this value. The value is in nits.")]
public ClampedFloatParameter paperWhite = new ClampedFloatParameter(300.0f, 0.0f, 400.0f);
///
/// Enable to use the minimum and maximum brightness values detected from the output device. For best accuracy, considering calibrating these values manually.
///
[Tooltip("Enable to use the minimum and maximum brightness values detected from the output device. For best accuracy, considering calibrating these values manually.")]
public BoolParameter detectBrightnessLimits = new BoolParameter(true);
///
/// The minimum brightness of the screen (in nits). This value is assumed to be 0.005f with ACES Tonemap.
///
[Tooltip("The minimum brightness of the screen (in nits). This value is assumed to be 0.005f with ACES Tonemap.")]
public ClampedFloatParameter minNits = new ClampedFloatParameter(0.005f, 0.0f, 50.0f);
///
/// The maximum brightness of the screen (in nits). This value is defined by the preset when using ACES Tonemap.
///
[Tooltip("The maximum brightness of the screen (in nits). This value is defined by the preset when using ACES Tonemap.")]
public ClampedFloatParameter maxNits = new ClampedFloatParameter(1000.0f, 0.0f, 5000.0f);
///
/// Tells if the post process needs to be rendered or not.
///
/// true if the effect should be rendered, false otherwise.
public bool IsActive() => mode.value != TonemappingMode.None;
///
/// Tells if the post process can run the effect on-tile or if it needs a full pass.
///
/// true if it can run on-tile, false otherwise.
[Obsolete("Unused #from(2023.1)", false)]
public bool IsTileCompatible() => true;
}
///
/// A that holds a value.
///
[Serializable]
public sealed class TonemappingModeParameter : VolumeParameter
{
///
/// Creates a new instance.
///
/// The initial value to store in the parameter.
/// The initial override state for the parameter.
public TonemappingModeParameter(TonemappingMode value, bool overrideState = false) : base(value, overrideState) { }
}
///
/// A that contains a value.
///
[Serializable]
public sealed class NeutralRangeReductionModeParameter : VolumeParameter
{
///
/// Creates a new instance.
///
/// The initial value to store in the parameter.
/// The initial override state for the parameter.
public NeutralRangeReductionModeParameter(NeutralRangeReductionMode value, bool overrideState = false) : base(value, overrideState) { }
}
///
/// A that contains a value.
///
[Serializable]
public sealed class HDRACESPresetParameter : VolumeParameter
{
///
/// Creates a new instance.
///
/// The initial value to store in the parameter.
/// The initial override state for the parameter.
public HDRACESPresetParameter(HDRACESPreset value, bool overrideState = false) : base(value, overrideState) { }
}
}