using System; namespace UnityEngine.Rendering.Universal { /// /// A volume component that holds settings for the Lens Distortion effect. /// /// /// You can add to a in the Editor to apply a Lens Distortion 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 LensDistortion m_VolumeComponent; /// /// [Serializable] /// private struct VolumeSettings /// { /// public bool active; /// public ClampedFloatParameter intensity; /// public ClampedFloatParameter xMultiplier; /// public ClampedFloatParameter yMultiplier; /// public Vector2Parameter center; /// public ClampedFloatParameter scale; /// /// public void SetVolumeComponentSettings(ref LensDistortion volumeComponent) /// { /// volumeComponent.active = active; /// volumeComponent.intensity = intensity; /// volumeComponent.xMultiplier = xMultiplier; /// volumeComponent.yMultiplier = yMultiplier; /// volumeComponent.center = center; /// volumeComponent.scale = scale; /// } /// /// public void GetVolumeComponentSettings(ref LensDistortion volumeComponent) /// { /// active = volumeComponent.active; /// intensity = volumeComponent.intensity; /// xMultiplier = volumeComponent.xMultiplier; /// yMultiplier = volumeComponent.yMultiplier; /// center = volumeComponent.center; /// scale = volumeComponent.scale; /// } /// } /// /// 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 LensDistortion volumeComponent) /// { /// if (volumeComponent != null) /// return true; /// /// if (volumeProfile == null) /// { /// Debug.LogError("ModifyVolumeComponent.GetVolumeComponent():\nvolumeProfile has not been assigned."); /// return false; /// } /// /// volumeProfile.TryGet(out LensDistortion 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/Lens Distortion")] [SupportedOnRenderPipeline(typeof(UniversalRenderPipelineAsset))] [URPHelpURL("Post-Processing-Lens-Distortion")] public sealed class LensDistortion : VolumeComponent, IPostProcessComponent { /// /// Total distortion amount. /// [Tooltip("Total distortion amount.")] public ClampedFloatParameter intensity = new ClampedFloatParameter(0f, -1f, 1f); /// /// Intensity multiplier on X axis. Set it to 0 to disable distortion on this axis. /// [Tooltip("Intensity multiplier on X axis. Set it to 0 to disable distortion on this axis.")] public ClampedFloatParameter xMultiplier = new ClampedFloatParameter(1f, 0f, 1f); /// /// Intensity multiplier on Y axis. Set it to 0 to disable distortion on this axis. /// [Tooltip("Intensity multiplier on Y axis. Set it to 0 to disable distortion on this axis.")] public ClampedFloatParameter yMultiplier = new ClampedFloatParameter(1f, 0f, 1f); /// /// Distortion center point. 0.5,0.5 is center of the screen /// [Tooltip("Distortion center point. 0.5,0.5 is center of the screen.")] public Vector2Parameter center = new Vector2Parameter(new Vector2(0.5f, 0.5f)); /// /// Controls global screen scaling for the distortion effect. Use this to hide the screen borders when using high \"Intensity.\" /// [Tooltip("Controls global screen scaling for the distortion effect. Use this to hide the screen borders when using high \"Intensity.\"")] public ClampedFloatParameter scale = new ClampedFloatParameter(1f, 0.01f, 5f); /// /// Tells if the post process needs to be rendered or not. /// /// true if the effect should be rendered, false otherwise. public bool IsActive() { return Mathf.Abs(intensity.value) > 0 && (xMultiplier.value > 0f || yMultiplier.value > 0f); } /// /// 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() => false; } }