PostProcessSettings.cs 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344
  1. //********************************** Banshee Engine (www.banshee3d.com) **************************************************//
  2. //**************** Copyright (c) 2016 Marko Pintera ([email protected]). All rights reserved. **********************//
  3. using System;
  4. using System.Runtime.CompilerServices;
  5. namespace BansheeEngine
  6. {
  7. /// <summary>
  8. /// Settings that control automatic exposure (eye adaptation) post-process.
  9. /// </summary>
  10. struct AutoExposureSettings // Note: Must match C++ struct AutoExposureSettings
  11. {
  12. /// <summary>
  13. /// Determines minimum luminance value in the eye adaptation histogram. The histogram is used for calculating the
  14. /// average brightness of the scene.Any luminance value below this value will not be included in the histogram and
  15. /// ignored in scene brightness calculations. In log2 units (-8 = 1/256). In the range [-16, 0].
  16. /// </summary>
  17. public float HistogramLog2Min;
  18. /// <summary>
  19. /// Determines maximum luminance value in the eye adaptation histogram. The histogram is used for calculating the
  20. /// average brightness of the scene.Any luminance value above this value will not be included in the histogram and
  21. /// ignored in scene brightness calculations. In log2 units (4 = 16). In the range [0, 16].
  22. /// </summary>
  23. public float HistogramLog2Max;
  24. /// <summary>
  25. /// Percentage below which to ignore values in the eye adaptation histogram. The histogram is used for calculating
  26. /// the average brightness of the scene.Total luminance in the histogram will be summed up and multiplied by this
  27. /// value to calculate minimal luminance. Luminance values below the minimal luminance will be ignored and not used
  28. /// in scene brightness calculations.This allows you to remove outliers on the lower end of the histogram (e.g. a
  29. /// few very dark pixels in an otherwise bright image). In range [0.0f, 1.0f].
  30. /// </summary>
  31. public float HistogramPctLow;
  32. /// <summary>
  33. /// Percentage above which to ignore values in the eye adaptation histogram. The histogram is used for calculating
  34. /// the average brightness of the scene.Total luminance in the histogram will be summed up and multiplied by this
  35. /// value to calculate maximum luminance. Luminance values above the maximum luminance will be ignored and not used
  36. /// in scene brightness calculations.This allows you to remove outliers on the high end of the histogram (e.g. a few
  37. /// very bright pixels). In range [0.0f, 1.0f].
  38. /// </summary>
  39. public float HistogramPctHigh;
  40. /// <summary>
  41. /// Clamps the minimum eye adaptation scale to this value. This allows you to limit eye adaptation so that exposure
  42. /// is never too high (e.g. when in a very dark room you probably do not want the exposure to be so high that
  43. /// everything is still visible). In range [0.0f, 10.0f].
  44. /// </summary>
  45. public float MinEyeAdaptation;
  46. /// <summary>
  47. /// Clamps the maximum eye adaptation scale to this value. This allows you to limit eye adaptation so that exposure
  48. /// is never too low (e.g. when looking at a very bright light source you probably don't want the exposure to be so
  49. /// low that the rest of the scene is all white (overexposed). In range [0.0f, 10.0f].
  50. /// </summary>
  51. public float MaxEyeAdaptation;
  52. /// <summary>
  53. /// Determines how quickly does the eye adaptation adjust to larger values. This affects how quickly does the
  54. /// automatic exposure changes when the scene brightness increases. In range [0.01f, 20.0f].
  55. /// </summary>
  56. public float EyeAdaptationSpeedUp;
  57. /// <summary>
  58. /// Determines how quickly does the eye adaptation adjust to smaller values. This affects how quickly does the
  59. /// automatic exposure changes when the scene brightness decreases. In range [0.01f, 20.0f].
  60. /// </summary>
  61. public float EyeAdaptationSpeedDown;
  62. };
  63. /// <summary>
  64. /// Settings that control tonemap post-process.
  65. /// </summary>
  66. struct TonemappingSettings // Note: Must match C++ struct TonemappingSettings
  67. {
  68. /// <summary>
  69. /// Controls the shoulder (upper non-linear) section of the filmic curve used for tonemapping. Mostly affects bright
  70. /// areas of the image and allows you to reduce over-exposure.
  71. /// </summary>
  72. public float FilmicCurveShoulderStrength;
  73. /// <summary>
  74. /// Controls the linear (middle) section of the filmic curve used for tonemapping. Mostly affects mid-range areas of
  75. /// the image.
  76. /// </summary>
  77. public float FilmicCurveLinearStrength;
  78. /// <summary>
  79. /// Controls the linear (middle) section of the filmic curve used for tonemapping. Mostly affects mid-range areas of
  80. /// the image and allows you to control how quickly does the curve climb.
  81. /// </summary>
  82. public float FilmicCurveLinearAngle;
  83. /// <summary>
  84. /// Controls the toe (lower non-linear) section of the filmic curve used for tonemapping. Mostly affects dark areas
  85. /// of the image and allows you to reduce under-exposure.
  86. /// </summary>
  87. public float FilmicCurveToeStrength;
  88. /// <summary>
  89. /// Controls the toe (lower non-linear) section of the filmic curve. used for tonemapping. Affects low-range.
  90. /// </summary>
  91. public float FilmicCurveToeNumerator;
  92. /// <summary>
  93. /// Controls the toe (lower non-linear) section of the filmic curve used for tonemapping. Affects low-range.
  94. /// </summary>
  95. public float FilmicCurveToeDenominator;
  96. /// <summary>
  97. /// Controls the white point of the filmic curve used for tonemapping. Affects the entire curve.
  98. /// </summary>
  99. public float FilmicCurveLinearWhitePoint;
  100. };
  101. /// <summary>
  102. /// Settings that control white balance post-process.
  103. /// </summary>
  104. struct WhiteBalanceSettings // Note: Must match C++ struct WhiteBalanceSettings
  105. {
  106. /// <summary>
  107. /// Temperature used for white balancing, in Kelvins.
  108. ///
  109. /// Moves along the Planckian locus. In range [1500.0f, 15000.0f].
  110. /// </summary>
  111. public float Temperature;
  112. /// <summary>
  113. /// Additional tint to be applied during white balancing. Can be used to further tweak the white balancing effect by
  114. /// modifying the tint of the light.The tint is chosen on the Planckian locus isothermal, depending on the light
  115. /// temperature specified by <see cref="Temperature"/>.
  116. ///
  117. /// In range [-1.0f, 1.0f].
  118. /// </summary>
  119. public float Tint;
  120. };
  121. /// <summary>
  122. /// Settings that control color grading post-process.
  123. /// </summary>
  124. struct ColorGradingSettings // Note: Must match C++ struct ColorGradingSettings
  125. {
  126. /// <summary>
  127. /// Saturation to be applied during color grading. Larger values increase vibrancy of the image.
  128. /// In range [0.0f, 2.0f].
  129. /// </summary>
  130. public Vector3 Saturation;
  131. /// <summary>
  132. /// Contrast to be applied during color grading. Larger values increase difference between light and dark areas of
  133. /// the image. In range [0.0f, 2.0f].
  134. /// </summary>
  135. public Vector3 Contrast;
  136. /// <summary>
  137. /// Gain to be applied during color grading. Simply increases all color values by an equal scale.
  138. /// In range [0.0f, 2.0f].
  139. /// </summary>
  140. public Vector3 Gain;
  141. /// <summary>
  142. /// Gain to be applied during color grading. Simply offsets all color values by an equal amount.
  143. /// In range [-1.0f, 1.0f].
  144. /// </summary>
  145. public Vector3 Offset;
  146. };
  147. /// <summary>
  148. /// Settings that control the post-process operations.
  149. /// </summary>
  150. class PostProcessSettings : ScriptObject
  151. {
  152. public PostProcessSettings()
  153. {
  154. Internal_CreateInstance(this);
  155. }
  156. /// <summary>
  157. /// Determines should automatic exposure be applied to the HDR image. When turned on the average scene brightness
  158. /// will be calculated and used to automatically expose the image to the optimal range. Use the parameters provided
  159. /// by <see cref="AutoExposure"/> to customize the automatic exposure effect.You may also use
  160. /// <see cref="ExposureScale"/> to manually adjust the automatic exposure. When automatic exposure is turned off you
  161. /// can use <see cref="ExposureScale"/> to manually set the exposure.
  162. /// </summary>
  163. public bool EnableAutoExposure
  164. {
  165. get { return Internal_GetEnableAutoExposure(mCachedPtr); }
  166. set { Internal_SetEnableAutoExposure(mCachedPtr, value); }
  167. }
  168. /// <summary>
  169. /// Parameters used for customizing automatic scene exposure. <see cref="EnableAutoExposure"/>
  170. /// </summary>
  171. public AutoExposureSettings AutoExposure
  172. {
  173. get
  174. {
  175. AutoExposureSettings output;
  176. Internal_GetAutoExposureSettings(mCachedPtr, out output);
  177. return output;
  178. }
  179. set { Internal_SetAutoExposureSettings(mCachedPtr, ref value); }
  180. }
  181. /// <summary>
  182. /// Determines should the image be tonemapped. Tonemapping converts an HDR image into LDR image by applying
  183. /// a filmic curve to the image, simulating the effect of film cameras.Filmic curve improves image quality by
  184. /// tapering off lows and highs, preventing under- and over-exposure.This is useful if an image contains both
  185. /// very dark and very bright areas, in which case the global exposure parameter would leave some areas either over-
  186. /// or under-exposed.Use ::tonemapping to customize how tonemapping performed.
  187. ///
  188. /// If this is disabled, then color grading and white balancing will not be enabled either.Only relevant for HDR
  189. /// images.
  190. /// </summary>
  191. public bool EnableTonemapping
  192. {
  193. get { return Internal_GetEnableTonemapping(mCachedPtr); }
  194. set { Internal_SetEnableTonemapping(mCachedPtr, value); }
  195. }
  196. /// <summary>
  197. /// Parameters used for customizing tonemapping. <see cref="EnableTonemapping"/>
  198. /// </summary>
  199. public TonemappingSettings Tonemapping
  200. {
  201. get
  202. {
  203. TonemappingSettings output;
  204. Internal_GetTonemappingSettings(mCachedPtr, out output);
  205. return output;
  206. }
  207. set { Internal_SetTonemappingSettings(mCachedPtr, ref value); }
  208. }
  209. /// <summary>
  210. /// Parameters used for customizing white balancing. White balancing converts a scene illuminated by a light of the
  211. /// specified temperature into a scene illuminated by a standard D65 illuminant (average midday light) in order to
  212. /// simulate the effects of chromatic adaptation of the human visual system.
  213. /// </summary>
  214. public WhiteBalanceSettings WhiteBalance
  215. {
  216. get
  217. {
  218. WhiteBalanceSettings output;
  219. Internal_GetWhiteBalanceSettings(mCachedPtr, out output);
  220. return output;
  221. }
  222. set { Internal_SetWhiteBalanceSettings(mCachedPtr, ref value); }
  223. }
  224. /// <summary>
  225. /// Parameters used for customizing color grading.
  226. /// </summary>
  227. public ColorGradingSettings ColorGrading
  228. {
  229. get
  230. {
  231. ColorGradingSettings output;
  232. Internal_GetColorGradingSettings(mCachedPtr, out output);
  233. return output;
  234. }
  235. set { Internal_SetColorGradingSettings(mCachedPtr, ref value); }
  236. }
  237. /// <summary>
  238. /// Log2 value to scale the eye adaptation by (e.g. 2^0 = 1). Smaller values yield darker image, while larger yield
  239. /// brighter image.Allows you to customize exposure manually, applied on top of eye adaptation exposure (if
  240. /// enabled). In range [-8, 8].
  241. /// </summary>
  242. public float ExposureScale
  243. {
  244. get { return Internal_GetExposureScale(mCachedPtr); }
  245. set { Internal_SetExposureScale(mCachedPtr, value); }
  246. }
  247. /// <summary>
  248. /// Gamma value to adjust the image for. Larger values result in a brighter image. When tonemapping is turned
  249. /// on the best gamma curve for the output device is chosen automatically and this value can by used to merely tweak
  250. /// that curve. If tonemapping is turned off this is the exact value of the gamma curve that will be applied.
  251. /// </summary>
  252. public float Gamma
  253. {
  254. get { return Internal_GetGamma(mCachedPtr); }
  255. set { Internal_SetGamma(mCachedPtr, value); }
  256. }
  257. [MethodImpl(MethodImplOptions.InternalCall)]
  258. private static extern void Internal_CreateInstance(PostProcessSettings managedInstance);
  259. [MethodImpl(MethodImplOptions.InternalCall)]
  260. private static extern bool Internal_GetEnableAutoExposure(IntPtr thisPtr);
  261. [MethodImpl(MethodImplOptions.InternalCall)]
  262. private static extern void Internal_SetEnableAutoExposure(IntPtr thisPtr, bool value);
  263. [MethodImpl(MethodImplOptions.InternalCall)]
  264. private static extern void Internal_GetAutoExposureSettings(IntPtr thisPtr, out AutoExposureSettings value);
  265. [MethodImpl(MethodImplOptions.InternalCall)]
  266. private static extern void Internal_SetAutoExposureSettings(IntPtr thisPtr, ref AutoExposureSettings value);
  267. [MethodImpl(MethodImplOptions.InternalCall)]
  268. private static extern bool Internal_GetEnableTonemapping(IntPtr thisPtr);
  269. [MethodImpl(MethodImplOptions.InternalCall)]
  270. private static extern void Internal_SetEnableTonemapping(IntPtr thisPtr, bool value);
  271. [MethodImpl(MethodImplOptions.InternalCall)]
  272. private static extern void Internal_GetTonemappingSettings(IntPtr thisPtr, out TonemappingSettings value);
  273. [MethodImpl(MethodImplOptions.InternalCall)]
  274. private static extern void Internal_SetTonemappingSettings(IntPtr thisPtr, ref TonemappingSettings value);
  275. [MethodImpl(MethodImplOptions.InternalCall)]
  276. private static extern void Internal_GetWhiteBalanceSettings(IntPtr thisPtr, out WhiteBalanceSettings value);
  277. [MethodImpl(MethodImplOptions.InternalCall)]
  278. private static extern void Internal_SetWhiteBalanceSettings(IntPtr thisPtr, ref WhiteBalanceSettings value);
  279. [MethodImpl(MethodImplOptions.InternalCall)]
  280. private static extern void Internal_GetColorGradingSettings(IntPtr thisPtr, out ColorGradingSettings value);
  281. [MethodImpl(MethodImplOptions.InternalCall)]
  282. private static extern void Internal_SetColorGradingSettings(IntPtr thisPtr, ref ColorGradingSettings value);
  283. [MethodImpl(MethodImplOptions.InternalCall)]
  284. private static extern float Internal_GetExposureScale(IntPtr thisPtr);
  285. [MethodImpl(MethodImplOptions.InternalCall)]
  286. private static extern void Internal_SetExposureScale(IntPtr thisPtr, float value);
  287. [MethodImpl(MethodImplOptions.InternalCall)]
  288. private static extern float Internal_GetGamma(IntPtr thisPtr);
  289. [MethodImpl(MethodImplOptions.InternalCall)]
  290. private static extern void Internal_SetGamma(IntPtr thisPtr, float value);
  291. }
  292. }