using System;
namespace UnityEngine.Rendering.PostProcessing
{
///
/// A list of available render modes for the Vignette effect.
///
public enum VignetteMode
{
///
/// This mode offers parametric controls for the position, shape and intensity of the Vignette.
///
Classic,
///
/// This mode multiplies a custom texture mask over the screen to create a Vignette effect.
///
Masked
}
///
/// A volume parameter holding a value.
///
[Serializable]
public sealed class VignetteModeParameter : ParameterOverride { }
///
/// This class holds settings for the Vignette effect.
///
[Serializable]
[PostProcess(typeof(VignetteRenderer), "Unity/Vignette")]
public sealed class Vignette : PostProcessEffectSettings
{
///
/// Use the \"Classic\" mode for parametric controls. Use the \"Masked\" mode to use your own texture mask.
///
[Tooltip("Use the \"Classic\" mode for parametric controls. Use the \"Masked\" mode to use your own texture mask.")]
public VignetteModeParameter mode = new VignetteModeParameter { value = VignetteMode.Classic };
///
/// The color to use to tint the vignette.
///
[Tooltip("Vignette color.")]
public ColorParameter color = new ColorParameter { value = new Color(0f, 0f, 0f, 1f) };
///
/// Sets the vignette center point (screen center is [0.5,0.5]).
///
[Tooltip("Sets the vignette center point (screen center is [0.5, 0.5]).")]
public Vector2Parameter center = new Vector2Parameter { value = new Vector2(0.5f, 0.5f) };
///
/// The amount of vignetting on screen.
///
[Range(0f, 1f), Tooltip("Amount of vignetting on screen.")]
public FloatParameter intensity = new FloatParameter { value = 0f };
///
/// The smoothness of the vignette borders.
///
[Range(0.01f, 1f), Tooltip("Smoothness of the vignette borders.")]
public FloatParameter smoothness = new FloatParameter { value = 0.2f };
///
/// Lower values will make a square-ish vignette.
///
[Range(0f, 1f), Tooltip("Lower values will make a square-ish vignette.")]
public FloatParameter roundness = new FloatParameter { value = 1f };
///
/// Should the vignette be perfectly round or be dependent on the current aspect ratio?
///
[Tooltip("Set to true to mark the vignette to be perfectly round. False will make its shape dependent on the current aspect ratio.")]
public BoolParameter rounded = new BoolParameter { value = false };
///
/// A black and white mask to use as a vignette.
///
[Tooltip("A black and white mask to use as a vignette.")]
public TextureParameter mask = new TextureParameter { value = null };
///
/// Mask opacity.
///
[Range(0f, 1f), Tooltip("Mask opacity.")]
public FloatParameter opacity = new FloatParameter { value = 1f };
///
/// Returns true if the effect is currently enabled and supported.
///
/// The current post-processing render context
/// true if the effect is currently enabled and supported
public override bool IsEnabledAndSupported(PostProcessRenderContext context)
{
return enabled.value
&& ((mode.value == VignetteMode.Classic && intensity.value > 0f)
|| (mode.value == VignetteMode.Masked && opacity.value > 0f && mask.value != null));
}
}
[UnityEngine.Scripting.Preserve]
internal sealed class VignetteRenderer : PostProcessEffectRenderer
{
public override void Render(PostProcessRenderContext context)
{
var sheet = context.uberSheet;
sheet.EnableKeyword("VIGNETTE");
sheet.properties.SetColor(ShaderIDs.Vignette_Color, settings.color.value);
if (settings.mode == VignetteMode.Classic)
{
sheet.properties.SetFloat(ShaderIDs.Vignette_Mode, 0f);
sheet.properties.SetVector(ShaderIDs.Vignette_Center, settings.center.value);
float roundness = (1f - settings.roundness.value) * 6f + settings.roundness.value;
sheet.properties.SetVector(ShaderIDs.Vignette_Settings, new Vector4(settings.intensity.value * 3f, settings.smoothness.value * 5f, roundness, settings.rounded.value ? 1f : 0f));
}
else // Masked
{
sheet.properties.SetFloat(ShaderIDs.Vignette_Mode, 1f);
sheet.properties.SetTexture(ShaderIDs.Vignette_Mask, settings.mask.value);
sheet.properties.SetFloat(ShaderIDs.Vignette_Opacity, Mathf.Clamp01(settings.opacity.value));
}
}
}
}