post processing
[WindSway-HDRP.git] / Library / PackageCache / com.unity.postprocessing@2.1.6 / PostProcessing / Runtime / Effects / LensDistortion.cs
blobbecf762ea00d9046554b6ae4ef3c476d4549b63b
1 using System;
3 namespace UnityEngine.Rendering.PostProcessing
5 /// <summary>
6 /// This class holds settings for the Lens Distortion effect.
7 /// </summary>
8 [Serializable]
9 [PostProcess(typeof(LensDistortionRenderer), "Unity/Lens Distortion")]
10 public sealed class LensDistortion : PostProcessEffectSettings
12 /// <summary>
13 /// The total amount of distortion to apply.
14 /// </summary>
15 [Range(-100f, 100f), Tooltip("Total distortion amount.")]
16 public FloatParameter intensity = new FloatParameter { value = 0f };
18 /// <summary>
19 /// Multiplies the intensity value on the x-axis. Setting this value to 0 will disable distortion on this axis.
20 /// </summary>
21 [Range(0f, 1f), DisplayName("X Multiplier"), Tooltip("Intensity multiplier on the x-axis. Set it to 0 to disable distortion on this axis.")]
22 public FloatParameter intensityX = new FloatParameter { value = 1f };
24 /// <summary>
25 /// Multiplies the intensity value on the y-axis. Setting this value to 0 will disable distortion on this axis.
26 /// </summary>
27 [Range(0f, 1f), DisplayName("Y Multiplier"), Tooltip("Intensity multiplier on the y-axis. Set it to 0 to disable distortion on this axis.")]
28 public FloatParameter intensityY = new FloatParameter { value = 1f };
30 /// <summary>
31 /// The center point for the distortion (x-axis).
32 /// </summary>
33 [Space]
34 [Range(-1f, 1f), Tooltip("Distortion center point (x-axis).")]
35 public FloatParameter centerX = new FloatParameter { value = 0f };
37 /// <summary>
38 /// The center point for the distortion (y-axis).
39 /// </summary>
40 [Range(-1f, 1f), Tooltip("Distortion center point (y-axis).")]
41 public FloatParameter centerY = new FloatParameter { value = 0f };
43 /// <summary>
44 /// A global screen scaling factor.
45 /// </summary>
46 [Space]
47 [Range(0.01f, 5f), Tooltip("Global screen scaling.")]
48 public FloatParameter scale = new FloatParameter { value = 1f };
50 /// <inheritdoc />
51 public override bool IsEnabledAndSupported(PostProcessRenderContext context)
53 return enabled.value
54 && !Mathf.Approximately(intensity, 0f)
55 && (intensityX > 0f || intensityY > 0f)
56 && !RuntimeUtilities.isVREnabled;
60 #if UNITY_2017_1_OR_NEWER
61 [UnityEngine.Scripting.Preserve]
62 #endif
63 internal sealed class LensDistortionRenderer : PostProcessEffectRenderer<LensDistortion>
65 public override void Render(PostProcessRenderContext context)
67 var sheet = context.uberSheet;
69 float amount = 1.6f * Math.Max(Mathf.Abs(settings.intensity.value), 1f);
70 float theta = Mathf.Deg2Rad * Math.Min(160f, amount);
71 float sigma = 2f * Mathf.Tan(theta * 0.5f);
72 var p0 = new Vector4(settings.centerX.value, settings.centerY.value, Mathf.Max(settings.intensityX.value, 1e-4f), Mathf.Max(settings.intensityY.value, 1e-4f));
73 var p1 = new Vector4(settings.intensity.value >= 0f ? theta : 1f / theta, sigma, 1f / settings.scale.value, settings.intensity.value);
75 sheet.EnableKeyword("DISTORT");
76 sheet.properties.SetVector(ShaderIDs.Distortion_CenterScale, p0);
77 sheet.properties.SetVector(ShaderIDs.Distortion_Amount, p1);