using System;
namespace UnityEngine.Rendering.Universal
{
///
/// A volume component that holds settings for the Shadows, Midtones, Highlights effect.
///
///
/// You can add to a in the Editor to apply a Shadows, Midtones, Highlights 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 ShadowsMidtonesHighlights m_VolumeComponent;
///
/// [Serializable]
/// private struct VolumeSettings
/// {
/// public bool active;
/// public Vector4Parameter shadows;
/// public Vector4Parameter midtones;
/// public Vector4Parameter highlights;
/// public MinFloatParameter shadowsStart;
/// public MinFloatParameter shadowsEnd;
/// public MinFloatParameter highlightsStart;
/// public MinFloatParameter highlightsEnd;
///
///
/// public void SetVolumeComponentSettings(ref ShadowsMidtonesHighlights volumeComponent)
/// {
/// volumeComponent.active = active;
/// volumeComponent.shadows = shadows;
/// volumeComponent.midtones = midtones;
/// volumeComponent.highlights = highlights;
/// volumeComponent.shadowsStart = shadowsStart;
/// volumeComponent.shadowsEnd = shadowsEnd;
/// volumeComponent.highlightsStart = highlightsStart;
/// volumeComponent.highlightsEnd = highlightsEnd;
/// }
///
/// public void GetVolumeComponentSettings(ref ShadowsMidtonesHighlights volumeComponent)
/// {
/// active = volumeComponent.active;
/// shadows = volumeComponent.shadows;
/// midtones = volumeComponent.midtones;
/// highlights = volumeComponent.highlights;
/// shadowsStart = volumeComponent.shadowsStart;
/// shadowsEnd = volumeComponent.shadowsEnd;
/// highlightsStart = volumeComponent.highlightsStart;
/// highlightsEnd = volumeComponent.highlightsEnd;
/// }
/// }
///
/// 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 ShadowsMidtonesHighlights volumeComponent)
/// {
/// if (volumeComponent != null)
/// return true;
///
/// if (volumeProfile == null)
/// {
/// Debug.LogError("ModifyVolumeComponent.GetVolumeComponent():\nvolumeProfile has not been assigned.");
/// return false;
/// }
///
/// volumeProfile.TryGet(out ShadowsMidtonesHighlights 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/Shadows, Midtones, Highlights")]
[SupportedOnRenderPipeline(typeof(UniversalRenderPipelineAsset))]
[URPHelpURL("Post-Processing-Shadows-Midtones-Highlights")]
public sealed class ShadowsMidtonesHighlights : VolumeComponent, IPostProcessComponent
{
///
/// Use this to control and apply a hue to the shadows.
///
public Vector4Parameter shadows = new Vector4Parameter(new Vector4(1f, 1f, 1f, 0f));
///
/// Use this to control and apply a hue to the midtones.
///
public Vector4Parameter midtones = new Vector4Parameter(new Vector4(1f, 1f, 1f, 0f));
///
/// Use this to control and apply a hue to the highlights.
///
public Vector4Parameter highlights = new Vector4Parameter(new Vector4(1f, 1f, 1f, 0f));
///
/// Start point of the transition between shadows and midtones.
///
[Header("Shadow Limits")]
[Tooltip("Start point of the transition between shadows and midtones.")]
public MinFloatParameter shadowsStart = new MinFloatParameter(0f, 0f);
///
/// End point of the transition between shadows and midtones.
///
[Tooltip("End point of the transition between shadows and midtones.")]
public MinFloatParameter shadowsEnd = new MinFloatParameter(0.3f, 0f);
///
/// Start point of the transition between midtones and highlights
///
[Header("Highlight Limits")]
[Tooltip("Start point of the transition between midtones and highlights.")]
public MinFloatParameter highlightsStart = new MinFloatParameter(0.55f, 0f);
///
/// End point of the transition between midtones and highlights.
///
[Tooltip("End point of the transition between midtones and highlights.")]
public MinFloatParameter highlightsEnd = new MinFloatParameter(1f, 0f);
///
/// Tells if the post process needs to be rendered or not.
///
/// true if the effect should be rendered, false otherwise.
public bool IsActive()
{
var defaultState = new Vector4(1f, 1f, 1f, 0f);
return shadows != defaultState
|| midtones != defaultState
|| highlights != defaultState;
}
///
/// 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;
}
}