AntialiasingModel.cs 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242
  1. using System;
  2. namespace UnityEngine.PostProcessing
  3. {
  4. [Serializable]
  5. public class AntialiasingModel : PostProcessingModel
  6. {
  7. public enum Method
  8. {
  9. Fxaa,
  10. Taa
  11. }
  12. // Most settings aren't exposed to the user anymore, presets are enough. Still, I'm leaving
  13. // the tooltip attributes in case an user wants to customize each preset.
  14. #region FXAA Settings
  15. public enum FxaaPreset
  16. {
  17. ExtremePerformance,
  18. Performance,
  19. Default,
  20. Quality,
  21. ExtremeQuality
  22. }
  23. [Serializable]
  24. public struct FxaaQualitySettings
  25. {
  26. [Tooltip("The amount of desired sub-pixel aliasing removal. Effects the sharpeness of the output.")]
  27. [Range(0f, 1f)]
  28. public float subpixelAliasingRemovalAmount;
  29. [Tooltip("The minimum amount of local contrast required to qualify a region as containing an edge.")]
  30. [Range(0.063f, 0.333f)]
  31. public float edgeDetectionThreshold;
  32. [Tooltip("Local contrast adaptation value to disallow the algorithm from executing on the darker regions.")]
  33. [Range(0f, 0.0833f)]
  34. public float minimumRequiredLuminance;
  35. public static FxaaQualitySettings[] presets =
  36. {
  37. // ExtremePerformance
  38. new FxaaQualitySettings
  39. {
  40. subpixelAliasingRemovalAmount = 0f,
  41. edgeDetectionThreshold = 0.333f,
  42. minimumRequiredLuminance = 0.0833f
  43. },
  44. // Performance
  45. new FxaaQualitySettings
  46. {
  47. subpixelAliasingRemovalAmount = 0.25f,
  48. edgeDetectionThreshold = 0.25f,
  49. minimumRequiredLuminance = 0.0833f
  50. },
  51. // Default
  52. new FxaaQualitySettings
  53. {
  54. subpixelAliasingRemovalAmount = 0.75f,
  55. edgeDetectionThreshold = 0.166f,
  56. minimumRequiredLuminance = 0.0833f
  57. },
  58. // Quality
  59. new FxaaQualitySettings
  60. {
  61. subpixelAliasingRemovalAmount = 1f,
  62. edgeDetectionThreshold = 0.125f,
  63. minimumRequiredLuminance = 0.0625f
  64. },
  65. // ExtremeQuality
  66. new FxaaQualitySettings
  67. {
  68. subpixelAliasingRemovalAmount = 1f,
  69. edgeDetectionThreshold = 0.063f,
  70. minimumRequiredLuminance = 0.0312f
  71. }
  72. };
  73. }
  74. [Serializable]
  75. public struct FxaaConsoleSettings
  76. {
  77. [Tooltip("The amount of spread applied to the sampling coordinates while sampling for subpixel information.")]
  78. [Range(0.33f, 0.5f)]
  79. public float subpixelSpreadAmount;
  80. [Tooltip("This value dictates how sharp the edges in the image are kept; a higher value implies sharper edges.")]
  81. [Range(2f, 8f)]
  82. public float edgeSharpnessAmount;
  83. [Tooltip("The minimum amount of local contrast required to qualify a region as containing an edge.")]
  84. [Range(0.125f, 0.25f)]
  85. public float edgeDetectionThreshold;
  86. [Tooltip("Local contrast adaptation value to disallow the algorithm from executing on the darker regions.")]
  87. [Range(0.04f, 0.06f)]
  88. public float minimumRequiredLuminance;
  89. public static FxaaConsoleSettings[] presets =
  90. {
  91. // ExtremePerformance
  92. new FxaaConsoleSettings
  93. {
  94. subpixelSpreadAmount = 0.33f,
  95. edgeSharpnessAmount = 8f,
  96. edgeDetectionThreshold = 0.25f,
  97. minimumRequiredLuminance = 0.06f
  98. },
  99. // Performance
  100. new FxaaConsoleSettings
  101. {
  102. subpixelSpreadAmount = 0.33f,
  103. edgeSharpnessAmount = 8f,
  104. edgeDetectionThreshold = 0.125f,
  105. minimumRequiredLuminance = 0.06f
  106. },
  107. // Default
  108. new FxaaConsoleSettings
  109. {
  110. subpixelSpreadAmount = 0.5f,
  111. edgeSharpnessAmount = 8f,
  112. edgeDetectionThreshold = 0.125f,
  113. minimumRequiredLuminance = 0.05f
  114. },
  115. // Quality
  116. new FxaaConsoleSettings
  117. {
  118. subpixelSpreadAmount = 0.5f,
  119. edgeSharpnessAmount = 4f,
  120. edgeDetectionThreshold = 0.125f,
  121. minimumRequiredLuminance = 0.04f
  122. },
  123. // ExtremeQuality
  124. new FxaaConsoleSettings
  125. {
  126. subpixelSpreadAmount = 0.5f,
  127. edgeSharpnessAmount = 2f,
  128. edgeDetectionThreshold = 0.125f,
  129. minimumRequiredLuminance = 0.04f
  130. }
  131. };
  132. }
  133. [Serializable]
  134. public struct FxaaSettings
  135. {
  136. public FxaaPreset preset;
  137. public static FxaaSettings defaultSettings
  138. {
  139. get
  140. {
  141. return new FxaaSettings
  142. {
  143. preset = FxaaPreset.Default
  144. };
  145. }
  146. }
  147. }
  148. #endregion
  149. #region TAA Settings
  150. [Serializable]
  151. public struct TaaSettings
  152. {
  153. [Tooltip("The diameter (in texels) inside which jitter samples are spread. Smaller values result in crisper but more aliased output, while larger values result in more stable but blurrier output.")]
  154. [Range(0.1f, 1f)]
  155. public float jitterSpread;
  156. [Tooltip("Controls the amount of sharpening applied to the color buffer.")]
  157. [Range(0f, 3f)]
  158. public float sharpen;
  159. [Tooltip("The blend coefficient for a stationary fragment. Controls the percentage of history sample blended into the final color.")]
  160. [Range(0f, 0.99f)]
  161. public float stationaryBlending;
  162. [Tooltip("The blend coefficient for a fragment with significant motion. Controls the percentage of history sample blended into the final color.")]
  163. [Range(0f, 0.99f)]
  164. public float motionBlending;
  165. public static TaaSettings defaultSettings
  166. {
  167. get
  168. {
  169. return new TaaSettings
  170. {
  171. jitterSpread = 0.75f,
  172. sharpen = 0.3f,
  173. stationaryBlending = 0.95f,
  174. motionBlending = 0.85f
  175. };
  176. }
  177. }
  178. }
  179. #endregion
  180. [Serializable]
  181. public struct Settings
  182. {
  183. public Method method;
  184. public FxaaSettings fxaaSettings;
  185. public TaaSettings taaSettings;
  186. public static Settings defaultSettings
  187. {
  188. get
  189. {
  190. return new Settings
  191. {
  192. method = Method.Fxaa,
  193. fxaaSettings = FxaaSettings.defaultSettings,
  194. taaSettings = TaaSettings.defaultSettings
  195. };
  196. }
  197. }
  198. }
  199. [SerializeField]
  200. Settings m_Settings = Settings.defaultSettings;
  201. public Settings settings
  202. {
  203. get { return m_Settings; }
  204. set { m_Settings = value; }
  205. }
  206. public override void Reset()
  207. {
  208. m_Settings = Settings.defaultSettings;
  209. }
  210. }
  211. }