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,
///
/// Close approximation of the reference ACES tonemapper for a more filmic look.
///
ACES,
///
/// A tweakable, artist-friendly tonemapping curve.
///
Custom,
///
/// Specifies a custom lookup table.
///
///
///
External
}
///
/// A volume component that holds settings for the Tonemapping effect.
///
[Serializable, VolumeComponentMenu("Post-processing/Tonemapping")]
[HelpURL(Documentation.baseURL + Documentation.version + Documentation.subURL + "Post-Processing-Tonemapping" + Documentation.endURL)]
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);
///
/// 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 TextureParameter lutTexture = new TextureParameter(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);
///
/// 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;
}
///
/// 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) {}
}
}