Class LensDistortion
A volume component that holds settings for the Lens Distortion effect.
Inherited Members
Namespace: UnityEngine .Rendering.Universal
Assembly: Unity.RenderPipelines.Universal.Runtime.dll
Syntax
[Serializable]
[VolumeComponentMenu("Post-processing/Lens Distortion")]
[SupportedOnRenderPipeline(typeof(UniversalRenderPipelineAsset))]
public sealed class LensDistortion : VolumeComponent, IApplyRevertPropertyContextMenuItemProvider, IPostProcessComponent
Remarks
You can add Unity
Examples
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;
}
}
Fields
center
Distortion center point. 0.5,0.5 is center of the screen
Declaration
[Tooltip("Distortion center point. 0.5,0.5 is center of the screen.")]
public Vector2Parameter center
Field Value
Type | Description |
---|---|
Vector2Parameter |
See Also
intensity
Total distortion amount.
Declaration
[Tooltip("Total distortion amount.")]
public ClampedFloatParameter intensity
Field Value
Type | Description |
---|---|
Clamped |
See Also
scale
Controls global screen scaling for the distortion effect. Use this to hide the screen borders when using high "Intensity."
Declaration
[Tooltip("Controls global screen scaling for the distortion effect. Use this to hide the screen borders when using high \"Intensity.\"")]
public ClampedFloatParameter scale
Field Value
Type | Description |
---|---|
Clamped |
See Also
xMultiplier
Intensity multiplier on X axis. Set it to 0 to disable distortion on this axis.
Declaration
[Tooltip("Intensity multiplier on X axis. Set it to 0 to disable distortion on this axis.")]
public ClampedFloatParameter xMultiplier
Field Value
Type | Description |
---|---|
Clamped |
See Also
yMultiplier
Intensity multiplier on Y axis. Set it to 0 to disable distortion on this axis.
Declaration
[Tooltip("Intensity multiplier on Y axis. Set it to 0 to disable distortion on this axis.")]
public ClampedFloatParameter yMultiplier
Field Value
Type | Description |
---|---|
Clamped |
See Also
Methods
IsActive()
Tells if the post process needs to be rendered or not.
Declaration
public bool IsActive()
Returns
Type | Description |
---|---|
bool |
|