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.

DepthOfField.cs 5.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. using System;
  2. namespace UnityEngine.Rendering.Universal
  3. {
  4. /// <summary>
  5. /// Focusing modes for the depth of field effect.
  6. /// </summary>
  7. public enum DepthOfFieldMode
  8. {
  9. /// <summary>
  10. /// Disables depth of field.
  11. /// </summary>
  12. Off,
  13. /// <summary>
  14. /// Use this for faster but non physical depth of field.
  15. /// </summary>
  16. Gaussian, // Non physical, fast, small radius, far blur only
  17. /// <summary>
  18. /// Use this for a more realistic but slower depth of field.
  19. /// </summary>
  20. Bokeh
  21. }
  22. /// <summary>
  23. /// A volume component that holds settings for the Depth Of Field effect.
  24. /// </summary>
  25. [Serializable, VolumeComponentMenu("Post-processing/Depth Of Field")]
  26. [SupportedOnRenderPipeline(typeof(UniversalRenderPipelineAsset))]
  27. [URPHelpURL("post-processing-depth-of-field")]
  28. public sealed class DepthOfField : VolumeComponent, IPostProcessComponent
  29. {
  30. /// <summary>
  31. /// Use this to select Focusing modes for the depth of field effect.
  32. /// </summary>
  33. [Tooltip("Use \"Gaussian\" for a faster but non physical depth of field; \"Bokeh\" for a more realistic but slower depth of field.")]
  34. public DepthOfFieldModeParameter mode = new DepthOfFieldModeParameter(DepthOfFieldMode.Off);
  35. /// <summary>
  36. /// The distance at which the blurring will start.
  37. /// </summary>
  38. [Tooltip("The distance at which the blurring will start.")]
  39. public MinFloatParameter gaussianStart = new MinFloatParameter(10f, 0f);
  40. /// <summary>
  41. /// The distance at which the blurring will reach its maximum radius.
  42. /// </summary>
  43. [Tooltip("The distance at which the blurring will reach its maximum radius.")]
  44. public MinFloatParameter gaussianEnd = new MinFloatParameter(30f, 0f);
  45. /// <summary>
  46. /// The maximum radius of the gaussian blur. Values above 1 may show under-sampling artifacts.
  47. /// </summary>
  48. [Tooltip("The maximum radius of the gaussian blur. Values above 1 may show under-sampling artifacts.")]
  49. public ClampedFloatParameter gaussianMaxRadius = new ClampedFloatParameter(1f, 0.5f, 1.5f);
  50. /// <summary>
  51. /// Use higher quality sampling to reduce flickering and improve the overall blur smoothness.
  52. /// </summary>
  53. [Tooltip("Use higher quality sampling to reduce flickering and improve the overall blur smoothness.")]
  54. public BoolParameter highQualitySampling = new BoolParameter(false);
  55. /// <summary>
  56. /// The distance to the point of focus.
  57. /// </summary>
  58. [Tooltip("The distance to the point of focus.")]
  59. public MinFloatParameter focusDistance = new MinFloatParameter(10f, 0.1f);
  60. /// <summary>
  61. /// The ratio of aperture (known as f-stop or f-number). The smaller the value is, the shallower the depth of field is.
  62. /// </summary>
  63. [Tooltip("The ratio of aperture (known as f-stop or f-number). The smaller the value is, the shallower the depth of field is.")]
  64. public ClampedFloatParameter aperture = new ClampedFloatParameter(5.6f, 1f, 32f);
  65. /// <summary>
  66. /// The distance between the lens and the film. The larger the value is, the shallower the depth of field is.
  67. /// </summary>
  68. [Tooltip("The distance between the lens and the film. The larger the value is, the shallower the depth of field is.")]
  69. public ClampedFloatParameter focalLength = new ClampedFloatParameter(50f, 1f, 300f);
  70. /// <summary>
  71. /// The number of aperture blades.
  72. /// </summary>
  73. [Tooltip("The number of aperture blades.")]
  74. public ClampedIntParameter bladeCount = new ClampedIntParameter(5, 3, 9);
  75. /// <summary>
  76. /// The curvature of aperture blades. The smaller the value is, the more visible aperture blades are. A value of 1 will make the bokeh perfectly circular.
  77. /// </summary>
  78. [Tooltip("The curvature of aperture blades. The smaller the value is, the more visible aperture blades are. A value of 1 will make the bokeh perfectly circular.")]
  79. public ClampedFloatParameter bladeCurvature = new ClampedFloatParameter(1f, 0f, 1f);
  80. /// <summary>
  81. /// The rotation of aperture blades in degrees.
  82. /// </summary>
  83. [Tooltip("The rotation of aperture blades in degrees.")]
  84. public ClampedFloatParameter bladeRotation = new ClampedFloatParameter(0f, -180f, 180f);
  85. /// <inheritdoc/>
  86. public bool IsActive()
  87. {
  88. if (mode.value == DepthOfFieldMode.Off || SystemInfo.graphicsShaderLevel < 35)
  89. return false;
  90. return mode.value != DepthOfFieldMode.Gaussian || SystemInfo.supportedRenderTargetCount > 1;
  91. }
  92. /// <inheritdoc/>
  93. [Obsolete("Unused #from(2023.1)", false)]
  94. public bool IsTileCompatible() => false;
  95. }
  96. /// <summary>
  97. /// A <see cref="VolumeParameter"/> that holds a <see cref="DepthOfFieldMode"/> value.
  98. /// </summary>
  99. [Serializable]
  100. public sealed class DepthOfFieldModeParameter : VolumeParameter<DepthOfFieldMode>
  101. {
  102. /// <summary>
  103. /// Creates a new <see cref="DepthOfFieldModeParameter"/> instance.
  104. /// </summary>
  105. /// <param name="value">The initial value to store in the parameter.</param>
  106. /// <param name="overrideState">The initial override state for the parameter.</param>
  107. public DepthOfFieldModeParameter(DepthOfFieldMode value, bool overrideState = false) : base(value, overrideState) { }
  108. }
  109. }