using System;
namespace UnityEngine.Rendering.Universal
{
///
/// This controls the size of the bloom texture.
///
public enum BloomDownscaleMode
{
///
/// Use this to select half size as the starting resolution.
///
Half,
///
/// Use this to select quarter size as the starting resolution.
///
Quarter,
}
///
/// A volume component that holds settings for the Bloom effect.
///
///
/// You can add to a in the Editor to apply a Bloom post-processing effect.
///
///
/// 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 Bloom m_VolumeComponent;
///
/// [Serializable]
/// private struct VolumeSettings
/// {
/// public bool active;
/// public MinFloatParameter threshold;
/// public MinFloatParameter intensity;
/// public ClampedFloatParameter scatter;
/// public MinFloatParameter clamp;
/// public ColorParameter tint;
/// public BoolParameter highQualityFiltering;
/// public DownscaleParameter downscale;
/// public ClampedIntParameter maxIterations;
/// public TextureParameter dirtTexture;
/// public MinFloatParameter dirtIntensity;
///
/// public void SetVolumeComponentSettings(ref Bloom volumeComponent)
/// {
/// volumeComponent.active = active;
/// volumeComponent.threshold = threshold;
/// volumeComponent.intensity = intensity;
/// volumeComponent.scatter = scatter;
/// volumeComponent.clamp = clamp;
/// volumeComponent.tint = tint;
/// volumeComponent.highQualityFiltering = highQualityFiltering;
/// volumeComponent.downscale = downscale;
/// volumeComponent.maxIterations = maxIterations;
/// volumeComponent.dirtTexture = dirtTexture;
/// volumeComponent.dirtIntensity = dirtIntensity;
/// }
///
/// public void GetVolumeComponentSettings(ref Bloom volumeComponent)
/// {
/// active = volumeComponent.active;
/// threshold = volumeComponent.threshold;
/// intensity = volumeComponent.intensity;
/// scatter = volumeComponent.scatter;
/// clamp = volumeComponent.clamp;
/// tint = volumeComponent.tint;
/// highQualityFiltering = volumeComponent.highQualityFiltering;
/// downscale = volumeComponent.downscale;
/// maxIterations = volumeComponent.maxIterations;
/// dirtTexture = volumeComponent.dirtTexture;
/// dirtIntensity = volumeComponent.dirtIntensity;
/// }
/// }
///
/// 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 Bloom volumeComponent)
/// {
/// if (volumeComponent != null)
/// return true;
///
/// if (volumeProfile == null)
/// {
/// Debug.LogError("ModifyVolumeComponent.GetVolumeComponent():\nvolumeProfile has not been assigned.");
/// return false;
/// }
///
/// volumeProfile.TryGet(out Bloom component);
/// if (component == null)
/// {
/// Debug.LogError($"ModifyVolumeComponent.GetVolumeComponent():\nMissing component in the \"{volumeProfile.name}\" VolumeProfile ");
/// return false;
/// }
///
/// volumeComponent = component;
/// return true;
/// }
/// }
///
///
///
///
///
///
///
///
///
///
///
///
///
[Serializable, VolumeComponentMenu("Post-processing/Bloom")]
[SupportedOnRenderPipeline(typeof(UniversalRenderPipelineAsset))]
[URPHelpURL("post-processing-bloom")]
public sealed partial class Bloom : VolumeComponent, IPostProcessComponent
{
///
/// Set the level of brightness to filter out pixels under this level.
/// This value is expressed in gamma-space.
/// A value above 0 will disregard energy conservation rules.
///
[Header("Bloom")]
[Tooltip("Filters out pixels under this level of brightness. Value is in gamma-space.")]
public MinFloatParameter threshold = new MinFloatParameter(0.9f, 0f);
///
/// Controls the strength of the bloom filter.
///
[Tooltip("Strength of the bloom filter.")]
public MinFloatParameter intensity = new MinFloatParameter(0f, 0f);
///
/// Controls the extent of the veiling effect.
///
[Tooltip("Set the radius of the bloom effect.")]
public ClampedFloatParameter scatter = new ClampedFloatParameter(0.7f, 0f, 1f);
///
/// Set the maximum intensity that Unity uses to calculate Bloom.
/// If pixels in your Scene are more intense than this, URP renders them at their current intensity, but uses this intensity value for the purposes of Bloom calculations.
///
[Tooltip("Set the maximum intensity that Unity uses to calculate Bloom. If pixels in your Scene are more intense than this, URP renders them at their current intensity, but uses this intensity value for the purposes of Bloom calculations.")]
public MinFloatParameter clamp = new MinFloatParameter(65472f, 0f);
///
/// Specifies the tint of the bloom filter.
///
[Tooltip("Use the color picker to select a color for the Bloom effect to tint to.")]
public ColorParameter tint = new ColorParameter(Color.white, false, false, true);
///
/// Controls whether to use bicubic sampling instead of bilinear sampling for the upsampling passes.
/// This is slightly more expensive but helps getting smoother visuals.
///
[Tooltip("Use bicubic sampling instead of bilinear sampling for the upsampling passes. This is slightly more expensive but helps getting smoother visuals.")]
public BoolParameter highQualityFiltering = new BoolParameter(false);
///
/// Controls the starting resolution that this effect begins processing.
///
[Tooltip("The starting resolution that this effect begins processing."), AdditionalProperty]
public DownscaleParameter downscale = new DownscaleParameter(BloomDownscaleMode.Half);
///
/// Controls the maximum number of iterations in the effect processing sequence.
///
[Tooltip("The maximum number of iterations in the effect processing sequence."), AdditionalProperty]
public ClampedIntParameter maxIterations = new ClampedIntParameter(6, 2, 8);
///
/// Specifies a Texture to add smudges or dust to the bloom effect.
///
[Header("Lens Dirt")]
[Tooltip("Dirtiness texture to add smudges or dust to the bloom effect.")]
public TextureParameter dirtTexture = new TextureParameter(null);
///
/// Controls the strength of the lens dirt.
///
[Tooltip("Amount of dirtiness.")]
public MinFloatParameter dirtIntensity = new MinFloatParameter(0f, 0f);
///
/// Tells if the post process needs to be rendered or not.
///
/// true if the effect should be rendered, false otherwise.
public bool IsActive() => intensity.value > 0f;
///
/// Tells if the post process can run the effect on-tile or if it needs a full pass.
///
/// true if it can run on-tile, false otherwise.
[Obsolete("Unused #from(2023.1)", false)]
public bool IsTileCompatible() => false;
}
///
/// A that holds a value.
///
[Serializable]
public sealed class DownscaleParameter : VolumeParameter
{
///
/// Creates a new instance.
///
/// The initial value to store in the parameter.
/// The initial override state for the parameter.
public DownscaleParameter(BloomDownscaleMode value, bool overrideState = false) : base(value, overrideState) { }
}
}