ScreenSpaceReflectionModel.cs 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. using System;
  2. namespace UnityEngine.PostProcessing
  3. {
  4. [Serializable]
  5. public class ScreenSpaceReflectionModel : PostProcessingModel
  6. {
  7. public enum SSRResolution
  8. {
  9. High = 0,
  10. Low = 2
  11. }
  12. public enum SSRReflectionBlendType
  13. {
  14. PhysicallyBased,
  15. Additive
  16. }
  17. [Serializable]
  18. public struct IntensitySettings
  19. {
  20. [Tooltip("Nonphysical multiplier for the SSR reflections. 1.0 is physically based.")]
  21. [Range(0.0f, 2.0f)]
  22. public float reflectionMultiplier;
  23. [Tooltip("How far away from the maxDistance to begin fading SSR.")]
  24. [Range(0.0f, 1000.0f)]
  25. public float fadeDistance;
  26. [Tooltip("Amplify Fresnel fade out. Increase if floor reflections look good close to the surface and bad farther 'under' the floor.")]
  27. [Range(0.0f, 1.0f)]
  28. public float fresnelFade;
  29. [Tooltip("Higher values correspond to a faster Fresnel fade as the reflection changes from the grazing angle.")]
  30. [Range(0.1f, 10.0f)]
  31. public float fresnelFadePower;
  32. }
  33. [Serializable]
  34. public struct ReflectionSettings
  35. {
  36. // When enabled, we just add our reflections on top of the existing ones. This is physically incorrect, but several
  37. // popular demos and games have taken this approach, and it does hide some artifacts.
  38. [Tooltip("How the reflections are blended into the render.")]
  39. public SSRReflectionBlendType blendType;
  40. [Tooltip("Half resolution SSRR is much faster, but less accurate.")]
  41. public SSRResolution reflectionQuality;
  42. [Tooltip("Maximum reflection distance in world units.")]
  43. [Range(0.1f, 300.0f)]
  44. public float maxDistance;
  45. /// REFLECTIONS
  46. [Tooltip("Max raytracing length.")]
  47. [Range(16, 1024)]
  48. public int iterationCount;
  49. [Tooltip("Log base 2 of ray tracing coarse step size. Higher traces farther, lower gives better quality silhouettes.")]
  50. [Range(1, 16)]
  51. public int stepSize;
  52. [Tooltip("Typical thickness of columns, walls, furniture, and other objects that reflection rays might pass behind.")]
  53. [Range(0.01f, 10.0f)]
  54. public float widthModifier;
  55. [Tooltip("Blurriness of reflections.")]
  56. [Range(0.1f, 8.0f)]
  57. public float reflectionBlur;
  58. [Tooltip("Disable for a performance gain in scenes where most glossy objects are horizontal, like floors, water, and tables. Leave on for scenes with glossy vertical objects.")]
  59. public bool reflectBackfaces;
  60. }
  61. [Serializable]
  62. public struct ScreenEdgeMask
  63. {
  64. [Tooltip("Higher = fade out SSRR near the edge of the screen so that reflections don't pop under camera motion.")]
  65. [Range(0.0f, 1.0f)]
  66. public float intensity;
  67. }
  68. [Serializable]
  69. public struct Settings
  70. {
  71. public ReflectionSettings reflection;
  72. public IntensitySettings intensity;
  73. public ScreenEdgeMask screenEdgeMask;
  74. public static Settings defaultSettings
  75. {
  76. get
  77. {
  78. return new Settings
  79. {
  80. reflection = new ReflectionSettings
  81. {
  82. blendType = SSRReflectionBlendType.PhysicallyBased,
  83. reflectionQuality = SSRResolution.Low,
  84. maxDistance = 100f,
  85. iterationCount = 256,
  86. stepSize = 3,
  87. widthModifier = 0.5f,
  88. reflectionBlur = 1f,
  89. reflectBackfaces = false
  90. },
  91. intensity = new IntensitySettings
  92. {
  93. reflectionMultiplier = 1f,
  94. fadeDistance = 100f,
  95. fresnelFade = 1f,
  96. fresnelFadePower = 1f,
  97. },
  98. screenEdgeMask = new ScreenEdgeMask
  99. {
  100. intensity = 0.03f
  101. }
  102. };
  103. }
  104. }
  105. }
  106. [SerializeField]
  107. Settings m_Settings = Settings.defaultSettings;
  108. public Settings settings
  109. {
  110. get { return m_Settings; }
  111. set { m_Settings = value; }
  112. }
  113. public override void Reset()
  114. {
  115. m_Settings = Settings.defaultSettings;
  116. }
  117. }
  118. }