BsRenderSettings.h 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559
  1. //********************************** Banshee Engine (www.banshee3d.com) **************************************************//
  2. //**************** Copyright (c) 2016 Marko Pintera ([email protected]). All rights reserved. **********************//
  3. #pragma once
  4. #include "BsCorePrerequisites.h"
  5. #include "Reflection/BsIReflectable.h"
  6. #include "Math/BsVector3.h"
  7. namespace bs
  8. {
  9. /** @addtogroup Renderer
  10. * @{
  11. */
  12. /** Settings that control automatic exposure (eye adaptation) post-process. */
  13. struct BS_CORE_EXPORT BS_SCRIPT_EXPORT(m:Rendering) AutoExposureSettings : public IReflectable
  14. {
  15. BS_SCRIPT_EXPORT()
  16. AutoExposureSettings();
  17. /**
  18. * Determines minimum luminance value in the eye adaptation histogram. The histogram is used for calculating the
  19. * average brightness of the scene. Any luminance value below this value will not be included in the histogram and
  20. * ignored in scene brightness calculations. In log2 units (-8 = 1/256). In the range [-16, 0].
  21. */
  22. BS_SCRIPT_EXPORT()
  23. float histogramLog2Min;
  24. /**
  25. * Determines maximum luminance value in the eye adaptation histogram. The histogram is used for calculating the
  26. * average brightness of the scene. Any luminance value above this value will not be included in the histogram and
  27. * ignored in scene brightness calculations. In log2 units (4 = 16). In the range [0, 16].
  28. */
  29. BS_SCRIPT_EXPORT()
  30. float histogramLog2Max;
  31. /**
  32. * Percentage below which to ignore values in the eye adaptation histogram. The histogram is used for calculating
  33. * the average brightness of the scene. Total luminance in the histogram will be summed up and multiplied by this
  34. * value to calculate minimal luminance. Luminance values below the minimal luminance will be ignored and not used
  35. * in scene brightness calculations. This allows you to remove outliers on the lower end of the histogram (for
  36. * example a few very dark pixels in an otherwise bright image). In range [0.0f, 1.0f].
  37. */
  38. BS_SCRIPT_EXPORT()
  39. float histogramPctLow;
  40. /**
  41. * Percentage above which to ignore values in the eye adaptation histogram. The histogram is used for calculating
  42. * the average brightness of the scene. Total luminance in the histogram will be summed up and multiplied by this
  43. * value to calculate maximum luminance. Luminance values above the maximum luminance will be ignored and not used
  44. * in scene brightness calculations. This allows you to remove outliers on the high end of the histogram (for
  45. * example a few very bright pixels). In range [0.0f, 1.0f].
  46. */
  47. BS_SCRIPT_EXPORT()
  48. float histogramPctHigh;
  49. /**
  50. * Clamps the minimum eye adaptation scale to this value. This allows you to limit eye adaptation so that exposure
  51. * is never too high (for example when in a very dark room you probably do not want the exposure to be so high that
  52. * everything is still visible). In range [0.0f, 10.0f].
  53. */
  54. BS_SCRIPT_EXPORT()
  55. float minEyeAdaptation;
  56. /**
  57. * Clamps the maximum eye adaptation scale to this value. This allows you to limit eye adaptation so that exposure
  58. * is never too low (for example when looking at a very bright light source you probably don't want the exposure to
  59. * be so low that the rest of the scene is all white (overexposed). In range [0.0f, 10.0f].
  60. */
  61. BS_SCRIPT_EXPORT()
  62. float maxEyeAdaptation;
  63. /**
  64. * Determines how quickly does the eye adaptation adjust to larger values. This affects how quickly does the
  65. * automatic exposure changes when the scene brightness increases. In range [0.01f, 20.0f].
  66. */
  67. BS_SCRIPT_EXPORT()
  68. float eyeAdaptationSpeedUp;
  69. /**
  70. * Determines how quickly does the eye adaptation adjust to smaller values. This affects how quickly does the
  71. * automatic exposure changes when the scene brightness decreases. In range [0.01f, 20.0f].
  72. */
  73. BS_SCRIPT_EXPORT()
  74. float eyeAdaptationSpeedDown;
  75. /************************************************************************/
  76. /* RTTI */
  77. /************************************************************************/
  78. public:
  79. friend class AutoExposureSettingsRTTI;
  80. static RTTITypeBase* getRTTIStatic();
  81. RTTITypeBase* getRTTI() const override;
  82. };
  83. /** Settings that control tonemap post-process. */
  84. struct BS_CORE_EXPORT BS_SCRIPT_EXPORT(m:Rendering) TonemappingSettings : public IReflectable
  85. {
  86. BS_SCRIPT_EXPORT()
  87. TonemappingSettings();
  88. /**
  89. * Controls the shoulder (upper non-linear) section of the filmic curve used for tonemapping. Mostly affects bright
  90. * areas of the image and allows you to reduce over-exposure.
  91. */
  92. BS_SCRIPT_EXPORT()
  93. float filmicCurveShoulderStrength;
  94. /**
  95. * Controls the linear (middle) section of the filmic curve used for tonemapping. Mostly affects mid-range areas of
  96. * the image.
  97. */
  98. BS_SCRIPT_EXPORT()
  99. float filmicCurveLinearStrength;
  100. /**
  101. * Controls the linear (middle) section of the filmic curve used for tonemapping. Mostly affects mid-range areas of
  102. * the image and allows you to control how quickly does the curve climb.
  103. */
  104. BS_SCRIPT_EXPORT()
  105. float filmicCurveLinearAngle;
  106. /**
  107. * Controls the toe (lower non-linear) section of the filmic curve used for tonemapping. Mostly affects dark areas
  108. * of the image and allows you to reduce under-exposure.
  109. */
  110. BS_SCRIPT_EXPORT()
  111. float filmicCurveToeStrength;
  112. /** Controls the toe (lower non-linear) section of the filmic curve. used for tonemapping. Affects low-range. */
  113. BS_SCRIPT_EXPORT()
  114. float filmicCurveToeNumerator;
  115. /** Controls the toe (lower non-linear) section of the filmic curve used for tonemapping. Affects low-range. */
  116. BS_SCRIPT_EXPORT()
  117. float filmicCurveToeDenominator;
  118. /** Controls the white point of the filmic curve used for tonemapping. Affects the entire curve. */
  119. BS_SCRIPT_EXPORT()
  120. float filmicCurveLinearWhitePoint;
  121. /************************************************************************/
  122. /* RTTI */
  123. /************************************************************************/
  124. public:
  125. friend class TonemappingSettingsRTTI;
  126. static RTTITypeBase* getRTTIStatic();
  127. RTTITypeBase* getRTTI() const override;
  128. };
  129. /** Settings that control white balance post-process. */
  130. struct BS_CORE_EXPORT BS_SCRIPT_EXPORT(m:Rendering) WhiteBalanceSettings : public IReflectable
  131. {
  132. BS_SCRIPT_EXPORT()
  133. WhiteBalanceSettings();
  134. /**
  135. * Temperature used for white balancing, in Kelvins.
  136. *
  137. * Moves along the Planckian locus. In range [1500.0f, 15000.0f].
  138. */
  139. BS_SCRIPT_EXPORT()
  140. float temperature;
  141. /**
  142. * Additional tint to be applied during white balancing. Can be used to further tweak the white balancing effect by
  143. * modifying the tint of the light. The tint is chosen on the Planckian locus isothermal, depending on the light
  144. * temperature specified by #temperature.
  145. *
  146. * In range [-1.0f, 1.0f].
  147. */
  148. BS_SCRIPT_EXPORT()
  149. float tint;
  150. /************************************************************************/
  151. /* RTTI */
  152. /************************************************************************/
  153. public:
  154. friend class WhiteBalanceSettingsRTTI;
  155. static RTTITypeBase* getRTTIStatic();
  156. RTTITypeBase* getRTTI() const override;
  157. };
  158. /** Settings that control color grading post-process. */
  159. struct BS_CORE_EXPORT BS_SCRIPT_EXPORT() ColorGradingSettings : public IReflectable
  160. {
  161. ColorGradingSettings();
  162. /**
  163. * Saturation to be applied during color grading. Larger values increase vibrancy of the image.
  164. * In range [0.0f, 2.0f].
  165. */
  166. BS_SCRIPT_EXPORT()
  167. Vector3 saturation;
  168. /**
  169. * Contrast to be applied during color grading. Larger values increase difference between light and dark areas of
  170. * the image. In range [0.0f, 2.0f].
  171. */
  172. BS_SCRIPT_EXPORT()
  173. Vector3 contrast;
  174. /**
  175. * Gain to be applied during color grading. Simply increases all color values by an equal scale.
  176. * In range [0.0f, 2.0f].
  177. */
  178. BS_SCRIPT_EXPORT()
  179. Vector3 gain;
  180. /**
  181. * Gain to be applied during color grading. Simply offsets all color values by an equal amount.
  182. * In range [-1.0f, 1.0f].
  183. */
  184. BS_SCRIPT_EXPORT()
  185. Vector3 offset;
  186. /************************************************************************/
  187. /* RTTI */
  188. /************************************************************************/
  189. public:
  190. friend class ColorGradingSettingsRTTI;
  191. static RTTITypeBase* getRTTIStatic();
  192. RTTITypeBase* getRTTI() const override;
  193. };
  194. /** Settings that control screen space ambient occlusion. */
  195. struct BS_CORE_EXPORT BS_SCRIPT_EXPORT(m:Rendering) AmbientOcclusionSettings : public IReflectable
  196. {
  197. BS_SCRIPT_EXPORT()
  198. AmbientOcclusionSettings();
  199. /** Enables or disabled the screen space ambient occlusion effect. */
  200. BS_SCRIPT_EXPORT()
  201. bool enabled;
  202. /**
  203. * Radius (in world space, in meters) over which occluders are searched for. Smaller radius ensures better sampling
  204. * precision but can miss occluders. Larger radius ensures far away occluders are considered but can yield lower
  205. * quality or noise because of low sampling precision. Usually best to keep at around a meter, valid range
  206. * is roughly [0.05, 5.0].
  207. */
  208. BS_SCRIPT_EXPORT()
  209. float radius;
  210. /**
  211. * Bias used to reduce false occlusion artifacts. Higher values reduce the amount of artifacts but will cause
  212. * details to be lost in areas where occlusion isn't high. Value is in millimeters. Usually best to keep at a few
  213. * dozen millimeters, valid range is roughly [0, 200].
  214. */
  215. BS_SCRIPT_EXPORT()
  216. float bias;
  217. /**
  218. * Distance (in view space, in meters) after which AO starts fading out. The fade process will happen over the
  219. * range as specified by @p fadeRange.
  220. */
  221. BS_SCRIPT_EXPORT()
  222. float fadeDistance;
  223. /**
  224. * Range (in view space, in meters) in which AO fades out from 100% to 0%. AO starts fading out after the distance
  225. * specified in @p fadeDistance.
  226. */
  227. BS_SCRIPT_EXPORT()
  228. float fadeRange;
  229. /**
  230. * Linearly scales the intensity of the AO effect. Values less than 1 make the AO effect less pronounced, and vice
  231. * versa. Valid range is roughly [0.2, 2].
  232. */
  233. BS_SCRIPT_EXPORT()
  234. float intensity;
  235. /**
  236. * Controls how quickly does the AO darkening effect increase with higher occlusion percent. This is a non-linear
  237. * control and will cause the darkening to ramp up exponentially. Valid range is roughly [1, 4], where 1 means no
  238. * extra darkening will occur.
  239. */
  240. BS_SCRIPT_EXPORT()
  241. float power;
  242. /**
  243. * Quality level of generated ambient occlusion. In range [0, 4]. Higher levels yield higher quality AO at the cost
  244. * of performance.
  245. */
  246. BS_SCRIPT_EXPORT()
  247. UINT32 quality;
  248. /************************************************************************/
  249. /* RTTI */
  250. /************************************************************************/
  251. public:
  252. friend class AmbientOcclusionSettingsRTTI;
  253. static RTTITypeBase* getRTTIStatic();
  254. RTTITypeBase* getRTTI() const override;
  255. };
  256. /** Settings that control the depth-of-field effect. */
  257. struct BS_CORE_EXPORT BS_SCRIPT_EXPORT() DepthOfFieldSettings : public IReflectable
  258. {
  259. BS_SCRIPT_EXPORT()
  260. DepthOfFieldSettings();
  261. /** Enables or disables the depth of field effect. */
  262. BS_SCRIPT_EXPORT()
  263. bool enabled;
  264. /**
  265. * Distance from the camera at which the focal plane is located in. Objects at this distance will be fully in focus.
  266. */
  267. BS_SCRIPT_EXPORT()
  268. float focalDistance;
  269. /**
  270. * Range within which the objects remain fully in focus. This range is applied relative to the focal distance.
  271. * Only relevant if Gaussian depth of field is used as other methods don't use a constant in-focus range.
  272. */
  273. BS_SCRIPT_EXPORT()
  274. float focalRange;
  275. /**
  276. * Determines the size of the range within which objects transition from focused to fully unfocused, at the near
  277. * plane. Only relevant for Gaussian depth of field.
  278. */
  279. BS_SCRIPT_EXPORT()
  280. float nearTransitionRange;
  281. /**
  282. * Determines the size of the range within which objects transition from focused to fully unfocused, at the far
  283. * plane. Only relevant for Gaussian depth of field.
  284. */
  285. BS_SCRIPT_EXPORT()
  286. float farTransitionRange;
  287. /**
  288. * Determines the amount of blur to apply to fully unfocused objects that are closer to camera than the in-focus
  289. * zone. Set to zero to disable near-field blur. Only relevant for Gaussian depth of field.
  290. */
  291. BS_SCRIPT_EXPORT()
  292. float nearBlurAmount;
  293. /**
  294. * Determines the amount of blur to apply to fully unfocused objects that are farther away from camera than the
  295. * in-focus zone. Set to zero to disable far-field blur. Only relevant for Gaussian depth of field.
  296. */
  297. BS_SCRIPT_EXPORT()
  298. float farBlurAmount;
  299. /************************************************************************/
  300. /* RTTI */
  301. /************************************************************************/
  302. public:
  303. friend class DepthOfFieldSettingsRTTI;
  304. static RTTITypeBase* getRTTIStatic();
  305. RTTITypeBase* getRTTI() const override;
  306. };
  307. /**
  308. * Settings that control the screen space reflections effect. Screen space reflections provide high quality mirror-like
  309. * reflections at low performance cost. They should be used together with reflection probes as the effects complement
  310. * each other. As the name implies, the reflections are only limited to geometry drawn on the screen and the system will
  311. * fall back to refl. probes when screen space data is unavailable. Similarly the system will fall back to refl. probes
  312. * for rougher (more glossy rather than mirror-like) surfaces. Those surfaces require a higher number of samples to
  313. * achieve the glossy look, so we instead fall back to refl. probes which are pre-filtered and can be quickly sampled.
  314. */
  315. struct BS_CORE_EXPORT BS_SCRIPT_EXPORT(m:Rendering) ScreenSpaceReflectionsSettings : public IReflectable
  316. {
  317. BS_SCRIPT_EXPORT()
  318. ScreenSpaceReflectionsSettings();
  319. /** Enables or disables the SSR effect. */
  320. BS_SCRIPT_EXPORT()
  321. bool enabled;
  322. /**
  323. * Quality of the SSR effect. Higher values cast more sample rays, and march those rays are lower increments for
  324. * better precision. This results in higher quality, as well as a higher performance requirement. Valid range is
  325. * [0, 4], default is 2.
  326. */
  327. BS_SCRIPT_EXPORT()
  328. UINT32 quality;
  329. /** Intensity of the screen space reflections. Valid range is [0, 1]. Default is 1 (100%). */
  330. BS_SCRIPT_EXPORT()
  331. float intensity;
  332. /**
  333. * Roughness at which screen space reflections start fading out and become replaced with refl. probes. Valid range
  334. * is [0, 1]. Default is 0.8.
  335. */
  336. BS_SCRIPT_EXPORT()
  337. float maxRoughness;
  338. /************************************************************************/
  339. /* RTTI */
  340. /************************************************************************/
  341. public:
  342. friend class ScreenSpaceReflectionsRTTI;
  343. static RTTITypeBase* getRTTIStatic();
  344. RTTITypeBase* getRTTI() const override;
  345. };
  346. /** Settings that control rendering for a specific camera (view). */
  347. struct BS_CORE_EXPORT BS_SCRIPT_EXPORT(m:Rendering) RenderSettings : public IReflectable
  348. {
  349. BS_SCRIPT_EXPORT()
  350. RenderSettings();
  351. virtual ~RenderSettings() { }
  352. /**
  353. * Determines should automatic exposure be applied to the HDR image. When turned on the average scene brightness
  354. * will be calculated and used to automatically expose the image to the optimal range. Use the parameters provided
  355. * by autoExposure to customize the automatic exposure effect. You may also use exposureScale to
  356. * manually adjust the automatic exposure. When automatic exposure is turned off you can use exposureScale to
  357. * manually set the exposure.
  358. */
  359. BS_SCRIPT_EXPORT()
  360. bool enableAutoExposure;
  361. /**
  362. * Parameters used for customizing automatic scene exposure.
  363. *
  364. * @see enableAutoExposure
  365. */
  366. BS_SCRIPT_EXPORT()
  367. AutoExposureSettings autoExposure;
  368. /**
  369. * Determines should the image be tonemapped. Tonemapping converts an HDR image into LDR image by applying
  370. * a filmic curve to the image, simulating the effect of film cameras. Filmic curve improves image quality by
  371. * tapering off lows and highs, preventing under- and over-exposure. This is useful if an image contains both
  372. * very dark and very bright areas, in which case the global exposure parameter would leave some areas either over-
  373. * or under-exposed. Use #tonemapping to customize how tonemapping performed.
  374. *
  375. * If this is disabled, then color grading and white balancing will not be enabled either. Only relevant for HDR
  376. * images.
  377. */
  378. BS_SCRIPT_EXPORT()
  379. bool enableTonemapping;
  380. /**
  381. * Parameters used for customizing tonemapping.
  382. *
  383. * @see enableTonemapping
  384. */
  385. BS_SCRIPT_EXPORT()
  386. TonemappingSettings tonemapping;
  387. /**
  388. * Parameters used for customizing white balancing. White balancing converts a scene illuminated by a light of the
  389. * specified temperature into a scene illuminated by a standard D65 illuminant (average midday light) in order to
  390. * simulate the effects of chromatic adaptation of the human visual system.
  391. */
  392. BS_SCRIPT_EXPORT()
  393. WhiteBalanceSettings whiteBalance;
  394. /** Parameters used for customizing color grading. */
  395. BS_SCRIPT_EXPORT()
  396. ColorGradingSettings colorGrading;
  397. /** Parameters used for customizing the depth of field effect. */
  398. BS_SCRIPT_EXPORT()
  399. DepthOfFieldSettings depthOfField;
  400. /** Parameters used for customizing screen space ambient occlusion. */
  401. BS_SCRIPT_EXPORT()
  402. AmbientOcclusionSettings ambientOcclusion;
  403. /** Parameters used for customizing screen space reflections. */
  404. BS_SCRIPT_EXPORT()
  405. ScreenSpaceReflectionsSettings screenSpaceReflections;
  406. /** Enables the fast approximate anti-aliasing effect. */
  407. BS_SCRIPT_EXPORT()
  408. bool enableFXAA;
  409. /**
  410. * Log2 value to scale the eye adaptation by (for example 2^0 = 1). Smaller values yield darker image, while larger
  411. * yield brighter image. Allows you to customize exposure manually, applied on top of eye adaptation exposure (if
  412. * enabled). In range [-8, 8].
  413. */
  414. BS_SCRIPT_EXPORT()
  415. float exposureScale;
  416. /**
  417. * Gamma value to adjust the image for. Larger values result in a brighter image. When tonemapping is turned
  418. * on the best gamma curve for the output device is chosen automatically and this value can by used to merely tweak
  419. * that curve. If tonemapping is turned off this is the exact value of the gamma curve that will be applied.
  420. */
  421. BS_SCRIPT_EXPORT()
  422. float gamma;
  423. /**
  424. * High dynamic range allows light intensity to be more correctly recorded when rendering by allowing for a larger
  425. * range of values. The stored light is then converted into visible color range using exposure and a tone mapping
  426. * operator.
  427. */
  428. BS_SCRIPT_EXPORT()
  429. bool enableHDR;
  430. /**
  431. * Determines if scene objects will be lit by lights. If disabled everything will be rendered using their albedo
  432. * texture with no lighting applied.
  433. */
  434. BS_SCRIPT_EXPORT()
  435. bool enableLighting;
  436. /** Determines if shadows cast by lights should be rendered. Only relevant if lighting is turned on. */
  437. BS_SCRIPT_EXPORT()
  438. bool enableShadows;
  439. /** Determines if indirect lighting (e.g. from light probes or the sky) is rendered. */
  440. BS_SCRIPT_EXPORT()
  441. bool enableIndirectLighting;
  442. /**
  443. * Signals the renderer to only render overlays (like GUI), and not scene objects. Such rendering doesn't require
  444. * depth buffer or multi-sampled render targets and will not render any scene objects. This can improve performance
  445. * and memory usage for overlay-only views.
  446. */
  447. BS_SCRIPT_EXPORT()
  448. bool overlayOnly;
  449. /** @name Internal
  450. * @{
  451. */
  452. /**
  453. * Populates the provided buffer with data that can be used for syncing between two versions of this object.
  454. * Apply the retrieved buffer via _setSyncData().
  455. *
  456. * @param[in] buffer Pre-allocated buffer to store the sync data in. Set to null to calculate the size
  457. * of the required buffer.
  458. * @param[in, out] size Size of the provided allocated buffer. Or if the buffer is null, this parameter will
  459. * contain the required buffer size when the method executes.
  460. */
  461. void _getSyncData(UINT8* buffer, UINT32& size);
  462. /**
  463. * Updates the stored data from the provided buffer, allowing changes to be transfered between two versions of this
  464. * object. Buffer must be retrieved from _getSyncData().
  465. *
  466. * @param[in] buffer Buffer containing the dirty data.
  467. * @param[in, out] size Size of the provided buffer.
  468. */
  469. void _setSyncData(UINT8* buffer, UINT32 size);
  470. /** @} */
  471. /************************************************************************/
  472. /* RTTI */
  473. /************************************************************************/
  474. public:
  475. friend class RenderSettingsRTTI;
  476. static RTTITypeBase* getRTTIStatic();
  477. RTTITypeBase* getRTTI() const override;
  478. };
  479. /** @} */
  480. }