using System;
namespace UnityEngine.Rendering.HighDefinition
{
///
/// Available tonemapping modes.
///
///
[GenerateHLSL]
public enum TonemappingMode
{
///
/// No tonemapping.
///
None,
///
/// Tonemapping mode with minimal impact on color hue and saturation.
///
Neutral,
///
/// ACES tonemapper for a more filmic look.
///
ACES,
///
/// A tweakable, artist-friendly tonemapping curve.
///
Custom,
///
/// Specifies a custom lookup table.
///
///
///
External
}
///
/// Available options for when HDR Output is enabled and Tonemap is set to Neutral.
///
public enum NeutralRangeReductionMode
{
///
/// Simple Reinhard tonemapping curve.
///
Reinhard = 1,
///
/// Range reduction curve as specified in the BT.2390 standard.
///
BT2390 = 2
}
///
/// Preset used when selecting ACES tonemapping for HDR displays.
///
public enum HDRACESPreset
{
///
/// Preset for display with maximum 1000 nits display.
///
ACES1000Nits = HDRRangeReduction.ACES1000Nits,
///
/// Preset for display with maximum 2000 nits display.
///
ACES2000Nits = HDRRangeReduction.ACES2000Nits,
///
/// Preset for display with maximum 4000 nits display.
///
ACES4000Nits = HDRRangeReduction.ACES4000Nits,
}
///
/// Tonemap mode to be used when outputting to HDR device and when the main mode is not supported on HDR.
///
public enum FallbackHDRTonemap
{
///
/// No tonemapping.
///
None = 0,
///
/// Tonemapping mode with minimal impact on color hue and saturation.
///
Neutral,
///
/// ACES tonemapper for a more filmic look.
///
ACES
}
///
/// A that holds 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 holds 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) { }
}
///
/// A that holds a value.
///
[Serializable]
public sealed class FallbackHDRTonemapParameter : VolumeParameter
{
///
/// Creates a new instance.
///
/// The initial value to store in the parameter.
/// The initial override state for the parameter.
public FallbackHDRTonemapParameter(FallbackHDRTonemap value, bool overrideState = false) : base(value, overrideState) { }
}
///
/// A volume component that holds settings for the Tonemapping effect.
///
[Serializable, VolumeComponentMenu("Post-processing/Tonemapping")]
[SupportedOnRenderPipeline(typeof(HDRenderPipelineAsset))]
[HDRPHelpURL("Post-Processing-Tonemapping")]
public sealed class Tonemapping : VolumeComponent, IPostProcessComponent
{
///
/// Specifies the tonemapping algorithm to use for the color grading process.
///
///
[Tooltip("Specifies the tonemapping algorithm to use for the color grading process.")]
public TonemappingModeParameter mode = new TonemappingModeParameter(TonemappingMode.None);
///
/// Whether to use full ACES tonemap instead of an approximation.
///
[AdditionalProperty]
[Tooltip("Whether to use full ACES tonemap instead of an approximation. When outputting to an HDR display, full ACES is always used regardless of this checkbox.")]
public BoolParameter useFullACES = new BoolParameter(false);
///
/// Controls the transition between the toe and the mid section of the curve. A value of 0
/// results in no transition and a value of 1 results in a very hard transition.
/// This parameter is only used when is set.
///
[Tooltip("Controls the transition between the toe and the mid section of the curve. A value of 0 results in no transition and a value of 1 results in a very hard transition.")]
public ClampedFloatParameter toeStrength = new ClampedFloatParameter(0f, 0f, 1f);
///
/// Controls how much of the dynamic range is in the toe. Higher values result in longer
/// toes and therefore contain more of the dynamic range.
/// This parameter is only used when is set.
///
[Tooltip("Controls how much of the dynamic range is in the toe. Higher values result in longer toes and therefore contain more of the dynamic range.")]
public ClampedFloatParameter toeLength = new ClampedFloatParameter(0.5f, 0f, 1f);
///
/// Controls the transition between the midsection and the shoulder of the curve. A value of 0
/// results in no transition and a value of 1 results in a very hard transition.
/// This parameter is only used when is set.
///
[Tooltip("Controls the transition between the midsection and the shoulder of the curve. A value of 0 results in no transition and a value of 1 results in a very hard transition.")]
public ClampedFloatParameter shoulderStrength = new ClampedFloatParameter(0f, 0f, 1f);
///
/// Sets how many F-stops (EV) to add to the dynamic range of the curve.
/// This parameter is only used when is set.
///
[Tooltip("Sets how many F-stops (EV) to add to the dynamic range of the curve.")]
public MinFloatParameter shoulderLength = new MinFloatParameter(0.5f, 0f);
///
/// Controls how much overshoot to add to the shoulder.
/// This parameter is only used when is set.
///
[Tooltip("Controls how much overshoot to add to the shoulder.")]
public ClampedFloatParameter shoulderAngle = new ClampedFloatParameter(0f, 0f, 1f);
///
/// Sets a gamma correction value that HDRP applies to the whole curve.
/// This parameter is only used when is set.
///
[Tooltip("Sets a gamma correction value that HDRP applies to the whole curve.")]
public MinFloatParameter gamma = new MinFloatParameter(1f, 0.001f);
///
/// A custom 3D texture lookup table to apply.
/// This parameter is only used when is set.
///
[Tooltip("A custom 3D texture lookup table to apply.")]
public Texture3DParameter lutTexture = new Texture3DParameter(null);
///
/// How much of the lookup texture will contribute to the color grading effect.
/// This parameter is only used when is set.
///
[Tooltip("How much of the lookup texture will contribute to the color grading effect.")]
public ClampedFloatParameter lutContribution = new ClampedFloatParameter(1f, 0f, 1f);
// -- 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 to be used for HDR displays.
///
[Tooltip("Specifies the ACES preset to be used for HDR displays.")]
public HDRACESPresetParameter acesPreset = new HDRACESPresetParameter(HDRACESPreset.ACES1000Nits);
///
/// Specifies the fallback tonemapping algorithm to use when outputting to an HDR device, when the main mode is not supported.
///
///
[Tooltip("Specifies the fallback tonemapping algorithm to use when outputting to an HDR device, when the main mode is not supported.")]
public FallbackHDRTonemapParameter fallbackMode = new FallbackHDRTonemapParameter(FallbackHDRTonemap.Neutral);
///
/// How much hue we want to preserve. Values closer to 0 try to preserve hue, while as values get closer to 1 hue shifts are reintroduced.
///
[Tooltip("How much hue we want to preserve. Values closer to 0 try to preserve hue, while as values get closer to 1 hue shifts are reintroduced.")]
public ClampedFloatParameter hueShiftAmount = new ClampedFloatParameter(0.0f, 0.0f, 1.0f);
///
/// Whether to use values detected from the output device as paperwhite. This value will often not lead to equivalent images between SDR and HDR. It is suggested to manually set this value.
///
[Tooltip("Whether to use values detected from the output device as paperwhite. This value will often not lead to equivalent images between SDR and HDR. It is suggested to manually set this value.")]
public BoolParameter detectPaperWhite = new BoolParameter(false);
///
/// The paper white value. It controls how bright a paper white surface should be, it also determines the maximum brightness of UI. The scene is also scaled relative to this value. Value in nits.
///
[Tooltip("It controls how bright a paper white surface should be, it also determines the maximum brightness of UI. The scene is also scaled relative to this value. Value in nits.")]
public ClampedFloatParameter paperWhite = new ClampedFloatParameter(300.0f, 0.0f, 400.0f);
///
/// Whether to use the minimum and maximum brightness values detected from the output device. It might be worth considering calibrating this values manually if the results are not the desired ones.
///
[Tooltip("Whether to use the minimum and maximum brightness values detected from the output device. It might be worth considering calibrating this values manually if the results are not the desired ones.")]
public BoolParameter detectBrightnessLimits = new BoolParameter(true);
///
/// The minimum brightness (in nits) of the screen. Note that this is assumed to be 0.005f with ACES Tonemap.
///
[Tooltip("The minimum brightness (in nits) of the screen. Note that this is assumed to be 0.005 with ACES Tonemap.")]
public ClampedFloatParameter minNits = new ClampedFloatParameter(0.005f, 0.0f, 50.0f);
///
/// The maximum brightness (in nits) of the screen. Note that this is assumed to be defined by the preset when ACES Tonemap is used.
///
[Tooltip("The maximum brightness (in nits) of the screen. Note that this is assumed to be defined by the preset when ACES Tonemap is used.")]
public ClampedFloatParameter maxNits = new ClampedFloatParameter(1000.0f, 0.0f, 5000.0f);
///
/// Tells if the effect needs to be rendered or not.
///
/// true if the effect should be rendered, false otherwise.
public bool IsActive()
{
if (mode.value == TonemappingMode.External)
return ValidateLUT() && lutContribution.value > 0f;
return mode.value != TonemappingMode.None;
}
internal TonemappingMode GetHDRTonemappingMode()
{
if (mode.value == TonemappingMode.Custom ||
mode.value == TonemappingMode.External)
{
if (fallbackMode.value == FallbackHDRTonemap.None) return TonemappingMode.None;
if (fallbackMode.value == FallbackHDRTonemap.Neutral) return TonemappingMode.Neutral;
if (fallbackMode.value == FallbackHDRTonemap.ACES) return TonemappingMode.ACES;
}
return mode.value;
}
///
/// Validates the format and size of the LUT texture set in .
///
/// true if the LUT is valid, false otherwise.
public bool ValidateLUT()
{
var hdAsset = HDRenderPipeline.currentAsset;
if (hdAsset == null || lutTexture.value == null)
return false;
if (lutTexture.value.width != hdAsset.currentPlatformRenderPipelineSettings.postProcessSettings.lutSize)
return false;
bool valid = false;
switch (lutTexture.value)
{
case Texture3D t:
valid |= t.width == t.height
&& t.height == t.depth;
break;
case RenderTexture rt:
valid |= rt.dimension == TextureDimension.Tex3D
&& rt.width == rt.height
&& rt.height == rt.volumeDepth;
break;
}
return valid;
}
}
///
/// 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) { }
}
}