DepthOfField.cs 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. using System;
  2. namespace UnityEngine.Rendering.Universal
  3. {
  4. public enum DepthOfFieldMode
  5. {
  6. Off,
  7. Gaussian, // Non physical, fast, small radius, far blur only
  8. Bokeh
  9. }
  10. [Serializable, VolumeComponentMenu("Post-processing/Depth Of Field")]
  11. public sealed class DepthOfField : VolumeComponent, IPostProcessComponent
  12. {
  13. [Tooltip("Use \"Gaussian\" for a faster but non physical depth of field; \"Bokeh\" for a more realistic but slower depth of field.")]
  14. public DepthOfFieldModeParameter mode = new DepthOfFieldModeParameter(DepthOfFieldMode.Off);
  15. [Tooltip("The distance at which the blurring will start.")]
  16. public MinFloatParameter gaussianStart = new MinFloatParameter(10f, 0f);
  17. [Tooltip("The distance at which the blurring will reach its maximum radius.")]
  18. public MinFloatParameter gaussianEnd = new MinFloatParameter(30f, 0f);
  19. [Tooltip("The maximum radius of the gaussian blur. Values above 1 may show under-sampling artifacts.")]
  20. public ClampedFloatParameter gaussianMaxRadius = new ClampedFloatParameter(1f, 0.5f, 1.5f);
  21. [Tooltip("Use higher quality sampling to reduce flickering and improve the overall blur smoothness.")]
  22. public BoolParameter highQualitySampling = new BoolParameter(false);
  23. [Tooltip("The distance to the point of focus.")]
  24. public MinFloatParameter focusDistance = new MinFloatParameter(10f, 0.1f);
  25. [Tooltip("The ratio of aperture (known as f-stop or f-number). The smaller the value is, the shallower the depth of field is.")]
  26. public ClampedFloatParameter aperture = new ClampedFloatParameter(5.6f, 1f, 32f);
  27. [Tooltip("The distance between the lens and the film. The larger the value is, the shallower the depth of field is.")]
  28. public ClampedFloatParameter focalLength = new ClampedFloatParameter(50f, 1f, 300f);
  29. [Tooltip("The number of aperture blades.")]
  30. public ClampedIntParameter bladeCount = new ClampedIntParameter(5, 3, 9);
  31. [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.")]
  32. public ClampedFloatParameter bladeCurvature = new ClampedFloatParameter(1f, 0f, 1f);
  33. [Tooltip("The rotation of aperture blades in degrees.")]
  34. public ClampedFloatParameter bladeRotation = new ClampedFloatParameter(0f, -180f, 180f);
  35. public bool IsActive()
  36. {
  37. if (mode.value == DepthOfFieldMode.Off || SystemInfo.graphicsShaderLevel < 35)
  38. return false;
  39. return mode.value != DepthOfFieldMode.Gaussian || SystemInfo.supportedRenderTargetCount > 1;
  40. }
  41. public bool IsTileCompatible() => false;
  42. }
  43. [Serializable]
  44. public sealed class DepthOfFieldModeParameter : VolumeParameter<DepthOfFieldMode> { public DepthOfFieldModeParameter(DepthOfFieldMode value, bool overrideState = false) : base(value, overrideState) { } }
  45. }