experiments with fresnel and shadergraph
[WindSway-HDRP.git] / Library / PackageCache / com.unity.postprocessing@2.1.6 / PostProcessing / Runtime / Effects / Vignette.cs
blobd1f4ad0186ea68e07730018f79b376e7fd844ba6
1 using System;
3 namespace UnityEngine.Rendering.PostProcessing
5 /// <summary>
6 /// A list of available render modes for the Vignette effect.
7 /// </summary>
8 public enum VignetteMode
10 /// <summary>
11 /// This mode offers parametric controls for the position, shape and intensity of the Vignette.
12 /// </summary>
13 Classic,
15 /// <summary>
16 /// This mode multiplies a custom texture mask over the screen to create a Vignette effect.
17 /// </summary>
18 Masked
21 /// <summary>
22 /// A volume parameter holding a <see cref="VignetteMode"/> value.
23 /// </summary>
24 [Serializable]
25 public sealed class VignetteModeParameter : ParameterOverride<VignetteMode> {}
27 /// <summary>
28 /// This class holds settings for the Vignette effect.
29 /// </summary>
30 [Serializable]
31 [PostProcess(typeof(VignetteRenderer), "Unity/Vignette")]
32 public sealed class Vignette : PostProcessEffectSettings
34 /// <summary>
35 /// Use the \"Classic\" mode for parametric controls. Use the \"Masked\" mode to use your own texture mask.
36 /// </summary>
37 [Tooltip("Use the \"Classic\" mode for parametric controls. Use the \"Masked\" mode to use your own texture mask.")]
38 public VignetteModeParameter mode = new VignetteModeParameter { value = VignetteMode.Classic };
40 /// <summary>
41 /// The color to use to tint the vignette.
42 /// </summary>
43 [Tooltip("Vignette color.")]
44 public ColorParameter color = new ColorParameter { value = new Color(0f, 0f, 0f, 1f) };
46 /// <summary>
47 /// Sets the vignette center point (screen center is <c>[0.5,0.5]</c>).
48 /// </summary>
49 [Tooltip("Sets the vignette center point (screen center is [0.5, 0.5]).")]
50 public Vector2Parameter center = new Vector2Parameter { value = new Vector2(0.5f, 0.5f) };
52 /// <summary>
53 /// The amount of vignetting on screen.
54 /// </summary>
55 [Range(0f, 1f), Tooltip("Amount of vignetting on screen.")]
56 public FloatParameter intensity = new FloatParameter { value = 0f };
58 /// <summary>
59 /// The smoothness of the vignette borders.
60 /// </summary>
61 [Range(0.01f, 1f), Tooltip("Smoothness of the vignette borders.")]
62 public FloatParameter smoothness = new FloatParameter { value = 0.2f };
64 /// <summary>
65 /// Lower values will make a square-ish vignette.
66 /// </summary>
67 [Range(0f, 1f), Tooltip("Lower values will make a square-ish vignette.")]
68 public FloatParameter roundness = new FloatParameter { value = 1f };
70 /// <summary>
71 /// Should the vignette be perfectly round or be dependent on the current aspect ratio?
72 /// </summary>
73 [Tooltip("Set to true to mark the vignette to be perfectly round. False will make its shape dependent on the current aspect ratio.")]
74 public BoolParameter rounded = new BoolParameter { value = false };
76 /// <summary>
77 /// A black and white mask to use as a vignette.
78 /// </summary>
79 [Tooltip("A black and white mask to use as a vignette.")]
80 public TextureParameter mask = new TextureParameter { value = null };
82 /// <summary>
83 /// Mask opacity.
84 /// </summary>
85 [Range(0f, 1f), Tooltip("Mask opacity.")]
86 public FloatParameter opacity = new FloatParameter { value = 1f };
88 /// <inheritdoc />
89 public override bool IsEnabledAndSupported(PostProcessRenderContext context)
91 return enabled.value
92 && ((mode.value == VignetteMode.Classic && intensity.value > 0f)
93 || (mode.value == VignetteMode.Masked && opacity.value > 0f && mask.value != null));
97 #if UNITY_2017_1_OR_NEWER
98 [UnityEngine.Scripting.Preserve]
99 #endif
100 internal sealed class VignetteRenderer : PostProcessEffectRenderer<Vignette>
102 public override void Render(PostProcessRenderContext context)
104 var sheet = context.uberSheet;
105 sheet.EnableKeyword("VIGNETTE");
106 sheet.properties.SetColor(ShaderIDs.Vignette_Color, settings.color.value);
108 if (settings.mode == VignetteMode.Classic)
110 sheet.properties.SetFloat(ShaderIDs.Vignette_Mode, 0f);
111 sheet.properties.SetVector(ShaderIDs.Vignette_Center, settings.center.value);
112 float roundness = (1f - settings.roundness.value) * 6f + settings.roundness.value;
113 sheet.properties.SetVector(ShaderIDs.Vignette_Settings, new Vector4(settings.intensity.value * 3f, settings.smoothness.value * 5f, roundness, settings.rounded.value ? 1f : 0f));
115 else // Masked
117 sheet.properties.SetFloat(ShaderIDs.Vignette_Mode, 1f);
118 sheet.properties.SetTexture(ShaderIDs.Vignette_Mask, settings.mask.value);
119 sheet.properties.SetFloat(ShaderIDs.Vignette_Opacity, Mathf.Clamp01(settings.opacity.value));