3 namespace UnityEngine
.Rendering
.PostProcessing
6 /// A list of available render modes for the Vignette effect.
8 public enum VignetteMode
11 /// This mode offers parametric controls for the position, shape and intensity of the Vignette.
16 /// This mode multiplies a custom texture mask over the screen to create a Vignette effect.
22 /// A volume parameter holding a <see cref="VignetteMode"/> value.
25 public sealed class VignetteModeParameter
: ParameterOverride
<VignetteMode
> {}
28 /// This class holds settings for the Vignette effect.
31 [PostProcess(typeof(VignetteRenderer
), "Unity/Vignette")]
32 public sealed class Vignette
: PostProcessEffectSettings
35 /// Use the \"Classic\" mode for parametric controls. Use the \"Masked\" mode to use your own texture mask.
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 }
;
41 /// The color to use to tint the vignette.
43 [Tooltip("Vignette color.")]
44 public ColorParameter color
= new ColorParameter { value = new Color(0f, 0f, 0f, 1f) }
;
47 /// Sets the vignette center point (screen center is <c>[0.5,0.5]</c>).
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) }
;
53 /// The amount of vignetting on screen.
55 [Range(0f
, 1f
), Tooltip("Amount of vignetting on screen.")]
56 public FloatParameter intensity
= new FloatParameter { value = 0f }
;
59 /// The smoothness of the vignette borders.
61 [Range(0.01f
, 1f
), Tooltip("Smoothness of the vignette borders.")]
62 public FloatParameter smoothness
= new FloatParameter { value = 0.2f }
;
65 /// Lower values will make a square-ish vignette.
67 [Range(0f
, 1f
), Tooltip("Lower values will make a square-ish vignette.")]
68 public FloatParameter roundness
= new FloatParameter { value = 1f }
;
71 /// Should the vignette be perfectly round or be dependent on the current aspect ratio?
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 }
;
77 /// A black and white mask to use as a vignette.
79 [Tooltip("A black and white mask to use as a vignette.")]
80 public TextureParameter mask
= new TextureParameter { value = null }
;
85 [Range(0f
, 1f
), Tooltip("Mask opacity.")]
86 public FloatParameter opacity
= new FloatParameter { value = 1f }
;
89 public override bool IsEnabledAndSupported(PostProcessRenderContext context
)
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
]
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
));
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));