No Description
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

ScreenSpaceLensFlare.cs 7.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. using System;
  2. namespace UnityEngine.Rendering.Universal
  3. {
  4. /// <summary>
  5. /// The resolution at which URP computes the Screen Space Lens Flare effect.
  6. /// </summary>
  7. public enum ScreenSpaceLensFlareResolution : int
  8. {
  9. /// <summary>
  10. /// Half Resolution.
  11. /// </summary>
  12. Half = 2,
  13. /// <summary>
  14. /// Quarter Resolution.
  15. /// </summary>
  16. Quarter = 4,
  17. /// <summary>
  18. /// Eigtht Resolution.
  19. /// </summary>
  20. Eighth = 8
  21. }
  22. /// <summary>
  23. /// A volume component that holds settings for the Screen Space Lens Flare effect.
  24. /// </summary>
  25. [Serializable, VolumeComponentMenu("Post-processing/Screen Space Lens Flare")]
  26. [SupportedOnRenderPipeline(typeof(UniversalRenderPipelineAsset))]
  27. [URPHelpURL("shared/lens-flare/lens-flare-component")]
  28. public class ScreenSpaceLensFlare : VolumeComponent, IPostProcessComponent
  29. {
  30. /// <summary>
  31. /// Sets the global intensity of the Screen Space Lens Flare effect. When set to 0, the pass is skipped.
  32. /// </summary>
  33. public MinFloatParameter intensity = new MinFloatParameter(0f, 0f);
  34. /// <summary>
  35. /// Sets the color used to tint all the flares.
  36. /// </summary>
  37. public ColorParameter tintColor = new ColorParameter(Color.white);
  38. /// <summary>
  39. /// Controls the bloom Mip used as a source for the Lens Flare effect. A high value will result in a blurrier result for all flares.
  40. /// </summary>
  41. [AdditionalProperty]
  42. public ClampedIntParameter bloomMip = new ClampedIntParameter(1, 0, 5);
  43. /// <summary>
  44. /// Controls the intensity of the Regular Flare sample. Those flares are sampled using scaled screen coordinates.
  45. /// </summary>
  46. [Header("Flares")]
  47. public MinFloatParameter firstFlareIntensity = new MinFloatParameter(1f, 0f);
  48. /// <summary>
  49. /// Controls the intensity of the Reversed Flare sample. Those flares are sampled using scaled and flipped screen coordinates.
  50. /// </summary>
  51. public MinFloatParameter secondaryFlareIntensity = new MinFloatParameter(1f, 0f);
  52. /// <summary>
  53. /// Controls the intensity of the Warped Flare sample. Those flares are sampled using polar screen coordinates.
  54. /// </summary>
  55. public MinFloatParameter warpedFlareIntensity = new MinFloatParameter(1f, 0f);
  56. /// <summary>
  57. /// Sets the scale of the warped flare. A value of 1,1 will keep this flare circular.
  58. /// </summary>
  59. [AdditionalProperty]
  60. public Vector2Parameter warpedFlareScale = new Vector2Parameter(new Vector2(1f, 1f));
  61. /// <summary>
  62. /// Controls the number of times the flare effect is repeated for each flare type (first, second, warped). This parameter has a strong impact on performance.
  63. /// </summary>
  64. public ClampedIntParameter samples = new ClampedIntParameter(1, 1, 3);
  65. /// <summary>
  66. /// Controls the value by which each additionnal sample is multiplied. A value of 1 keep the same intensities for all samples. A value of 0.7 multiplies the first sample by 1 (0.7 power 0), the second sample by 0.7 (0.7 power 1) and the third sample by 0.49 (0.7 power 2).
  67. /// </summary>
  68. [AdditionalProperty]
  69. public ClampedFloatParameter sampleDimmer = new ClampedFloatParameter(0.5f, 0.1f, 1f);
  70. /// <summary>
  71. /// Controls the intensity of the vignette effect to occlude the Lens Flare effect at the center of the screen.
  72. /// </summary>
  73. public ClampedFloatParameter vignetteEffect = new ClampedFloatParameter(1f, 0f, 1f);
  74. /// <summary>
  75. /// Controls the starting position of the flares in screen space relative to their source.
  76. /// </summary>
  77. public ClampedFloatParameter startingPosition = new ClampedFloatParameter(1.25f, 1f, 3f);
  78. /// <summary>
  79. /// Controls the scale at which the flare effect is sampled.
  80. /// </summary>
  81. public ClampedFloatParameter scale = new ClampedFloatParameter(1.5f, 1f, 4f);
  82. /// <summary>
  83. /// Controls the intensity of streaks effect. This effect has an impact on performance when above zero. When this intensity is zero, this effect is not evaluated to save costs.
  84. /// </summary>
  85. [Header("Streaks")]
  86. public MinFloatParameter streaksIntensity = new MinFloatParameter(0f, 0f);
  87. /// <summary>
  88. /// Controls the length of streaks effect. A value of one creates streaks about the width of the screen.
  89. /// </summary>
  90. public ClampedFloatParameter streaksLength = new ClampedFloatParameter(0.5f, 0f, 1f);
  91. /// <summary>
  92. /// Controls the orientation of streaks effect in degrees. A value of 0 produces horizontal streaks.
  93. /// </summary>
  94. public FloatParameter streaksOrientation = new FloatParameter(0f);
  95. /// <summary>
  96. /// Controls the threshold of horizontal streak effect. A high value makes the effect more localised on the high intensity areas of the screen.
  97. /// </summary>
  98. public ClampedFloatParameter streaksThreshold = new ClampedFloatParameter(0.25f, 0f, 1f);
  99. /// <summary>
  100. /// Specifies the resolution at which the streak effect is evaluated.
  101. /// </summary>
  102. [SerializeField]
  103. [AdditionalProperty]
  104. public ScreenSpaceLensFlareResolutionParameter resolution = new ScreenSpaceLensFlareResolutionParameter(ScreenSpaceLensFlareResolution.Quarter);
  105. /// <summary>
  106. /// Controls the strength of the Chromatic Aberration effect. The higher the value, the more light is dispersed on the sides of the screen
  107. /// </summary>
  108. [Header("Chromatic Abberation")]
  109. public ClampedFloatParameter chromaticAbberationIntensity = new ClampedFloatParameter(0.5f, 0f, 1f);
  110. /// <summary>
  111. /// Default constructor for the lens flare volume component.
  112. /// </summary>
  113. public ScreenSpaceLensFlare()
  114. {
  115. displayName = "Screen Space Lens Flare";
  116. }
  117. /// <summary>
  118. /// Mandatory function, cannot have an Override without it
  119. /// </summary>
  120. /// <returns></returns>
  121. public bool IsActive()
  122. {
  123. return intensity.value > 0;
  124. }
  125. /// <summary>
  126. /// Returns true is streakIntensity is above zero.
  127. /// </summary>
  128. /// <returns></returns>
  129. public bool IsStreaksActive()
  130. {
  131. return streaksIntensity.value > 0;
  132. }
  133. /// <inheritdoc/>
  134. [Obsolete("Unused #from(2023.1)", false)]
  135. public bool IsTileCompatible() => false;
  136. }
  137. /// <summary>
  138. /// A <see cref="VolumeParameter"/> that holds a <see cref="ScreenSpaceLensFlareResolution"/> value.
  139. /// </summary>
  140. [Serializable]
  141. public sealed class ScreenSpaceLensFlareResolutionParameter : VolumeParameter<ScreenSpaceLensFlareResolution>
  142. {
  143. /// <summary>
  144. /// Creates a new <see cref="ScreenSpaceLensFlareResolutionParameter"/> instance.
  145. /// </summary>
  146. /// <param name="value">The initial value to store in the parameter.</param>
  147. /// <param name="overrideState">The initial override state for the parameter.</param>
  148. public ScreenSpaceLensFlareResolutionParameter(ScreenSpaceLensFlareResolution value, bool overrideState = false) : base(value, overrideState) { }
  149. }
  150. }