115 lines
4.5 KiB
C#
115 lines
4.5 KiB
C#
using System;
|
|
|
|
namespace UnityEngine.Rendering.Universal
|
|
{
|
|
/// <summary>
|
|
/// A volume component that holds settings for the Chromatic Aberration effect.
|
|
/// </summary>
|
|
/// <remarks>
|
|
/// You can add <see cref="VolumeComponent"/> to a <see cref="VolumeProfile"/> in the Editor to apply a Chromatic Aberration post-processing effect.
|
|
/// </remarks>
|
|
/// <example>
|
|
/// <para>This sample code shows how settings can be retrieved and modified in runtime:</para>
|
|
/// <code>
|
|
/// 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 ChromaticAberration m_VolumeComponent;
|
|
///
|
|
/// [Serializable]
|
|
/// private struct VolumeSettings
|
|
/// {
|
|
/// public bool active;
|
|
/// public ClampedFloatParameter intensity;
|
|
///
|
|
/// public void SetVolumeComponentSettings(ref ChromaticAberration volumeComponent)
|
|
/// {
|
|
/// volumeComponent.active = active;
|
|
/// volumeComponent.intensity = intensity;
|
|
/// }
|
|
///
|
|
/// public void GetVolumeComponentSettings(ref ChromaticAberration volumeComponent)
|
|
/// {
|
|
/// active = volumeComponent.active;
|
|
/// intensity = volumeComponent.intensity;
|
|
/// }
|
|
/// }
|
|
///
|
|
/// 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 ChromaticAberration volumeComponent)
|
|
/// {
|
|
/// if (volumeComponent != null)
|
|
/// return true;
|
|
///
|
|
/// if (volumeProfile == null)
|
|
/// {
|
|
/// Debug.LogError("ModifyVolumeComponent.GetVolumeComponent():\nvolumeProfile has not been assigned.");
|
|
/// return false;
|
|
/// }
|
|
///
|
|
/// volumeProfile.TryGet(out ChromaticAberration component);
|
|
/// if (component == null)
|
|
/// {
|
|
/// Debug.LogError($"ModifyVolumeComponent.GetVolumeComponent():\nMissing component in the \"{volumeProfile.name}\" VolumeProfile ");
|
|
/// return false;
|
|
/// }
|
|
///
|
|
/// volumeComponent = component;
|
|
/// return true;
|
|
/// }
|
|
/// }
|
|
/// </code>
|
|
/// </example>
|
|
/// <seealso cref="VolumeProfile"/>
|
|
/// <seealso cref="VolumeComponent"/>
|
|
/// <seealso cref="IPostProcessComponent"/>
|
|
/// <seealso cref="VolumeParameter{T}"/>
|
|
/// <seealso cref="ClampedFloatParameter"/>
|
|
[Serializable, VolumeComponentMenu("Post-processing/Chromatic Aberration")]
|
|
[SupportedOnRenderPipeline(typeof(UniversalRenderPipelineAsset))]
|
|
[URPHelpURL("post-processing-chromatic-aberration")]
|
|
public sealed class ChromaticAberration : VolumeComponent, IPostProcessComponent
|
|
{
|
|
/// <summary>
|
|
/// Controls the strength of the chromatic aberration effect.
|
|
/// </summary>
|
|
[Tooltip("Use the slider to set the strength of the Chromatic Aberration effect.")]
|
|
public ClampedFloatParameter intensity = new ClampedFloatParameter(0f, 0f, 1f);
|
|
|
|
/// <summary>
|
|
/// Tells if the post process needs to be rendered or not.
|
|
/// </summary>
|
|
/// <returns><c>true</c> if the effect should be rendered, <c>false</c> otherwise.</returns>
|
|
public bool IsActive() => intensity.value > 0f;
|
|
|
|
/// <summary>
|
|
/// Tells if the post process can run the effect on-tile or if it needs a full pass.
|
|
/// </summary>
|
|
/// <returns><c>true</c> if it can run on-tile, <c>false</c> otherwise.</returns>
|
|
[Obsolete("Unused #from(2023.1)", false)]
|
|
public bool IsTileCompatible() => false;
|
|
}
|
|
}
|