PostProcessSettingsInspector.cs 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538
  1. //********************************** Banshee Engine (www.banshee3d.com) **************************************************//
  2. //**************** Copyright (c) 2016 Marko Pintera ([email protected]). All rights reserved. **********************//
  3. using System;
  4. using BansheeEngine;
  5. namespace BansheeEditor
  6. {
  7. /** @addtogroup Inspectors
  8. * @{
  9. */
  10. /// <summary>
  11. /// Draws GUI elements for inspecting an <see cref="AutoExposureSettings"/> object.
  12. /// </summary>
  13. internal class AutoExposureSettingsGUI
  14. {
  15. private AutoExposureSettings settings;
  16. private GUISliderField histogramLog2MinField = new GUISliderField(-16.0f, 0.0f, new LocEdString("Histogram min."));
  17. private GUISliderField histogramLog2MaxField = new GUISliderField(0.0f, 16.0f, new LocEdString("Histogram max."));
  18. private GUISliderField histogramPctLowField = new GUISliderField(0.0f, 1.0f, new LocEdString("Histogram % low"));
  19. private GUISliderField histogramPctHighField = new GUISliderField(0.0f, 1.0f, new LocEdString("Histogram % high"));
  20. private GUISliderField minEyeAdaptationField = new GUISliderField(0.0f, 10.0f, new LocEdString("Min. eye adapatation"));
  21. private GUISliderField maxEyeAdaptationField = new GUISliderField(0.0f, 10.0f, new LocEdString("Max. eye adapatation"));
  22. private GUISliderField eyeAdaptationSpeedUpField = new GUISliderField(0.01f, 20.0f, new LocEdString("Eye adaptation speed up"));
  23. private GUISliderField eyeAdaptationSpeedDownField = new GUISliderField(0.01f, 20.0f, new LocEdString("Eye adaptation speed down"));
  24. public Action<AutoExposureSettings> OnChanged;
  25. public Action OnConfirmed;
  26. /// <summary>
  27. /// Current value of the settings object.
  28. /// </summary>
  29. public AutoExposureSettings Settings
  30. {
  31. get { return settings; }
  32. set
  33. {
  34. settings = value;
  35. histogramLog2MinField.Value = value.HistogramLog2Min;
  36. histogramLog2MaxField.Value = value.HistogramLog2Max;
  37. histogramPctLowField.Value = value.HistogramPctLow;
  38. histogramPctHighField.Value = value.HistogramPctHigh;
  39. minEyeAdaptationField.Value = value.MinEyeAdaptation;
  40. maxEyeAdaptationField.Value = value.MaxEyeAdaptation;
  41. eyeAdaptationSpeedUpField.Value = value.EyeAdaptationSpeedUp;
  42. eyeAdaptationSpeedDownField.Value = value.EyeAdaptationSpeedDown;
  43. }
  44. }
  45. /// <summary>
  46. /// Constructs a new set of GUI elements for inspecting the auto exposure settings object.
  47. /// </summary>
  48. /// <param name="settings">Initial values to assign to the GUI elements.</param>
  49. /// <param name="layout">Layout to append the GUI elements to.</param>
  50. public AutoExposureSettingsGUI(AutoExposureSettings settings, GUILayout layout)
  51. {
  52. this.settings = settings;
  53. histogramLog2MinField.OnChanged += x => { this.settings.HistogramLog2Min = x; MarkAsModified(); ConfirmModify(); };
  54. histogramLog2MaxField.OnChanged += x => { this.settings.HistogramLog2Max = x; MarkAsModified(); ConfirmModify(); };
  55. histogramPctLowField.OnChanged += x => { this.settings.HistogramPctLow = x; MarkAsModified(); ConfirmModify(); };
  56. histogramPctHighField.OnChanged += x => { this.settings.HistogramPctHigh = x; MarkAsModified(); ConfirmModify(); };
  57. minEyeAdaptationField.OnChanged += x => { this.settings.MinEyeAdaptation = x; MarkAsModified(); ConfirmModify(); };
  58. maxEyeAdaptationField.OnChanged += x => { this.settings.MaxEyeAdaptation = x; MarkAsModified(); ConfirmModify(); };
  59. eyeAdaptationSpeedUpField.OnChanged += x => { this.settings.EyeAdaptationSpeedUp = x; MarkAsModified(); ConfirmModify(); };
  60. eyeAdaptationSpeedDownField.OnChanged += x => { this.settings.EyeAdaptationSpeedDown = x; MarkAsModified(); ConfirmModify(); };
  61. layout.AddElement(histogramLog2MinField);
  62. layout.AddElement(histogramLog2MaxField);
  63. layout.AddElement(histogramPctLowField);
  64. layout.AddElement(histogramPctHighField);
  65. layout.AddElement(minEyeAdaptationField);
  66. layout.AddElement(maxEyeAdaptationField);
  67. layout.AddElement(eyeAdaptationSpeedUpField);
  68. layout.AddElement(eyeAdaptationSpeedDownField);
  69. }
  70. /// <summary>
  71. /// Marks the contents of the inspector as modified.
  72. /// </summary>
  73. private void MarkAsModified()
  74. {
  75. if (OnChanged != null)
  76. OnChanged(settings);
  77. }
  78. /// <summary>
  79. /// Confirms any queued modifications.
  80. /// </summary>
  81. private void ConfirmModify()
  82. {
  83. if (OnConfirmed != null)
  84. OnConfirmed();
  85. }
  86. }
  87. /// <summary>
  88. /// Draws GUI elements for inspecting an <see cref="TonemappingSettings"/> object.
  89. /// </summary>
  90. internal class TonemappingSettingsGUI
  91. {
  92. private TonemappingSettings settings;
  93. private GUIFloatField shoulderStrengthField = new GUIFloatField(new LocEdString("Shoulder strength"));
  94. private GUIFloatField linearStrengthField = new GUIFloatField(new LocEdString("Linear strength"));
  95. private GUIFloatField linearAngleField = new GUIFloatField(new LocEdString("Linear angle"));
  96. private GUIFloatField toeStrengthField = new GUIFloatField(new LocEdString("Toe strength"));
  97. private GUIFloatField toeNumeratorField = new GUIFloatField(new LocEdString("Toe numerator"));
  98. private GUIFloatField toeDenominatorField = new GUIFloatField(new LocEdString("Toe denominator"));
  99. private GUIFloatField whitePointField = new GUIFloatField(new LocEdString("White point"));
  100. public Action<TonemappingSettings> OnChanged;
  101. public Action OnConfirmed;
  102. /// <summary>
  103. /// Current value of the settings object.
  104. /// </summary>
  105. public TonemappingSettings Settings
  106. {
  107. get { return settings; }
  108. set
  109. {
  110. settings = value;
  111. shoulderStrengthField.Value = value.FilmicCurveShoulderStrength;
  112. linearStrengthField.Value = value.FilmicCurveLinearStrength;
  113. linearAngleField.Value = value.FilmicCurveLinearAngle;
  114. toeStrengthField.Value = value.FilmicCurveToeStrength;
  115. toeNumeratorField.Value = value.FilmicCurveToeNumerator;
  116. toeDenominatorField.Value = value.FilmicCurveToeDenominator;
  117. whitePointField.Value = value.FilmicCurveLinearWhitePoint;
  118. }
  119. }
  120. /// <summary>
  121. /// Constructs a new set of GUI elements for inspecting the tone mapping settings object.
  122. /// </summary>
  123. /// <param name="settings">Initial values to assign to the GUI elements.</param>
  124. /// <param name="layout">Layout to append the GUI elements to.</param>
  125. public TonemappingSettingsGUI(TonemappingSettings settings, GUILayout layout)
  126. {
  127. this.settings = settings;
  128. shoulderStrengthField.OnChanged += x => { this.settings.FilmicCurveShoulderStrength = x; MarkAsModified(); };
  129. shoulderStrengthField.OnFocusLost += ConfirmModify;
  130. shoulderStrengthField.OnConfirmed += ConfirmModify;
  131. linearStrengthField.OnChanged += x => { this.settings.FilmicCurveLinearStrength = x; MarkAsModified(); };
  132. linearStrengthField.OnFocusLost += ConfirmModify;
  133. linearStrengthField.OnConfirmed += ConfirmModify;
  134. linearAngleField.OnChanged += x => { this.settings.FilmicCurveLinearAngle = x; MarkAsModified(); };
  135. linearAngleField.OnFocusLost += ConfirmModify;
  136. linearAngleField.OnConfirmed += ConfirmModify;
  137. toeStrengthField.OnChanged += x => { this.settings.FilmicCurveToeStrength = x; MarkAsModified(); };
  138. toeStrengthField.OnFocusLost += ConfirmModify;
  139. toeStrengthField.OnConfirmed += ConfirmModify;
  140. toeNumeratorField.OnChanged += x => { this.settings.FilmicCurveToeNumerator = x; MarkAsModified(); };
  141. toeNumeratorField.OnFocusLost += ConfirmModify;
  142. toeNumeratorField.OnConfirmed += ConfirmModify;
  143. toeDenominatorField.OnChanged += x => { this.settings.FilmicCurveToeDenominator = x; MarkAsModified(); };
  144. toeDenominatorField.OnFocusLost += ConfirmModify;
  145. toeDenominatorField.OnConfirmed += ConfirmModify;
  146. whitePointField.OnChanged += x => { this.settings.FilmicCurveLinearWhitePoint = x; MarkAsModified(); };
  147. whitePointField.OnFocusLost += ConfirmModify;
  148. whitePointField.OnConfirmed += ConfirmModify;
  149. layout.AddElement(shoulderStrengthField);
  150. layout.AddElement(linearStrengthField);
  151. layout.AddElement(linearAngleField);
  152. layout.AddElement(toeStrengthField);
  153. layout.AddElement(toeNumeratorField);
  154. layout.AddElement(toeDenominatorField);
  155. layout.AddElement(whitePointField);
  156. }
  157. /// <summary>
  158. /// Marks the contents of the inspector as modified.
  159. /// </summary>
  160. private void MarkAsModified()
  161. {
  162. if (OnChanged != null)
  163. OnChanged(settings);
  164. }
  165. /// <summary>
  166. /// Confirms any queued modifications.
  167. /// </summary>
  168. private void ConfirmModify()
  169. {
  170. if (OnConfirmed != null)
  171. OnConfirmed();
  172. }
  173. }
  174. /// <summary>
  175. /// Draws GUI elements for inspecting an <see cref="ColorGradingSettings"/> object.
  176. /// </summary>
  177. internal class ColorGradingSettingsGUI
  178. {
  179. private ColorGradingSettings settings;
  180. private GUIVector3Field saturationField = new GUIVector3Field(new LocEdString("Saturation"));
  181. private GUIVector3Field contrastField = new GUIVector3Field(new LocEdString("Contrast"));
  182. private GUIVector3Field gainField = new GUIVector3Field(new LocEdString("Gain"));
  183. private GUIVector3Field offsetField = new GUIVector3Field(new LocEdString("Offset"));
  184. public Action<ColorGradingSettings> OnChanged;
  185. public Action OnConfirmed;
  186. /// <summary>
  187. /// Current value of the settings object.
  188. /// </summary>
  189. public ColorGradingSettings Settings
  190. {
  191. get { return settings; }
  192. set
  193. {
  194. settings = value;
  195. saturationField.Value = value.Saturation;
  196. contrastField.Value = value.Contrast;
  197. gainField.Value = value.Gain;
  198. offsetField.Value = value.Offset;
  199. }
  200. }
  201. /// <summary>
  202. /// Constructs a new set of GUI elements for inspecting the color grading settings object.
  203. /// </summary>
  204. /// <param name="settings">Initial values to assign to the GUI elements.</param>
  205. /// <param name="layout">Layout to append the GUI elements to.</param>
  206. public ColorGradingSettingsGUI(ColorGradingSettings settings, GUILayout layout)
  207. {
  208. this.settings = settings;
  209. saturationField.OnChanged += x => { this.settings.Saturation = x; MarkAsModified(); };
  210. saturationField.OnFocusLost += ConfirmModify;
  211. saturationField.OnConfirmed += ConfirmModify;
  212. contrastField.OnChanged += x => { this.settings.Contrast = x; MarkAsModified(); };
  213. contrastField.OnFocusLost += ConfirmModify;
  214. contrastField.OnConfirmed += ConfirmModify;
  215. gainField.OnChanged += x => { this.settings.Gain = x; MarkAsModified(); };
  216. gainField.OnFocusLost += ConfirmModify;
  217. gainField.OnConfirmed += ConfirmModify;
  218. offsetField.OnChanged += x => { this.settings.Offset = x; MarkAsModified(); };
  219. offsetField.OnFocusLost += ConfirmModify;
  220. offsetField.OnConfirmed += ConfirmModify;
  221. layout.AddElement(saturationField);
  222. layout.AddElement(contrastField);
  223. layout.AddElement(gainField);
  224. layout.AddElement(offsetField);
  225. }
  226. /// <summary>
  227. /// Marks the contents of the inspector as modified.
  228. /// </summary>
  229. private void MarkAsModified()
  230. {
  231. if (OnChanged != null)
  232. OnChanged(settings);
  233. }
  234. /// <summary>
  235. /// Confirms any queued modifications.
  236. /// </summary>
  237. private void ConfirmModify()
  238. {
  239. if (OnConfirmed != null)
  240. OnConfirmed();
  241. }
  242. }
  243. /// <summary>
  244. /// Draws GUI elements for inspecting an <see cref="WhiteBalanceSettings"/> object.
  245. /// </summary>
  246. internal class WhiteBalanceSettingsGUI
  247. {
  248. private WhiteBalanceSettings settings;
  249. private GUISliderField temperatureField = new GUISliderField(1500.0f, 15000.0f, new LocEdString("Temperature"));
  250. private GUISliderField tintField = new GUISliderField(-1.0f, 1.0f, new LocEdString("Tint"));
  251. public Action<WhiteBalanceSettings> OnChanged;
  252. public Action OnConfirmed;
  253. /// <summary>
  254. /// Current value of the settings object.
  255. /// </summary>
  256. public WhiteBalanceSettings Settings
  257. {
  258. get { return settings; }
  259. set
  260. {
  261. settings = value;
  262. temperatureField.Value = value.Temperature;
  263. tintField.Value = value.Tint;
  264. }
  265. }
  266. /// <summary>
  267. /// Constructs a new set of GUI elements for inspecting the white balance settings object.
  268. /// </summary>
  269. /// <param name="settings">Initial values to assign to the GUI elements.</param>
  270. /// <param name="layout">Layout to append the GUI elements to.</param>
  271. public WhiteBalanceSettingsGUI(WhiteBalanceSettings settings, GUILayout layout)
  272. {
  273. this.settings = settings;
  274. temperatureField.OnChanged += x => { this.settings.Temperature = x; MarkAsModified(); ConfirmModify(); };
  275. tintField.OnChanged += x => { this.settings.Tint = x; MarkAsModified(); ConfirmModify(); };
  276. layout.AddElement(temperatureField);
  277. layout.AddElement(tintField);
  278. }
  279. /// <summary>
  280. /// Marks the contents of the inspector as modified.
  281. /// </summary>
  282. private void MarkAsModified()
  283. {
  284. if (OnChanged != null)
  285. OnChanged(settings);
  286. }
  287. /// <summary>
  288. /// Confirms any queued modifications.
  289. /// </summary>
  290. private void ConfirmModify()
  291. {
  292. if (OnConfirmed != null)
  293. OnConfirmed();
  294. }
  295. }
  296. /// <summary>
  297. /// Draws GUI elements for inspecting an <see cref="PostProcessSettings"/> object.
  298. /// </summary>
  299. internal class PostProcessSettingsGUI
  300. {
  301. private PostProcessSettings settings;
  302. private SerializableProperties properties;
  303. private GUIToggleField enableAutoExposureField = new GUIToggleField(new LocEdString("Enable auto exposure"));
  304. private GUIToggle autoExposureFoldout = new GUIToggle(new LocEdString("Auto exposure"), EditorStyles.Foldout);
  305. private AutoExposureSettingsGUI autoExposureGUI;
  306. private GUIToggleField enableToneMappingField = new GUIToggleField(new LocEdString("Enable tone mapping"));
  307. private GUIToggle toneMappingFoldout = new GUIToggle(new LocEdString("Tone mapping"), EditorStyles.Foldout);
  308. private TonemappingSettingsGUI toneMappingGUI;
  309. private GUIToggle whiteBalanceFoldout = new GUIToggle(new LocEdString("White balance"), EditorStyles.Foldout);
  310. private WhiteBalanceSettingsGUI whiteBalanceGUI;
  311. private GUIToggle colorGradingFoldout = new GUIToggle(new LocEdString("Color grading"), EditorStyles.Foldout);
  312. private ColorGradingSettingsGUI colorGradingGUI;
  313. private GUISliderField gammaField = new GUISliderField(1.0f, 3.0f, new LocEdString("Gamma"));
  314. private GUISliderField exposureScaleField = new GUISliderField(-8.0f, 8.0f, new LocEdString("Exposure scale"));
  315. private GUILayout autoExposureLayout;
  316. private GUILayout toneMappingLayout;
  317. private GUILayout whiteBalanceLayout;
  318. private GUILayout colorGradingLayout;
  319. public Action<PostProcessSettings> OnChanged;
  320. public Action OnConfirmed;
  321. /// <summary>
  322. /// Current value of the settings object.
  323. /// </summary>
  324. public PostProcessSettings Settings
  325. {
  326. get { return settings; }
  327. set
  328. {
  329. settings = value;
  330. enableAutoExposureField.Value = value.EnableAutoExposure;
  331. autoExposureGUI.Settings = value.AutoExposure;
  332. enableToneMappingField.Value = value.EnableTonemapping;
  333. toneMappingGUI.Settings = value.Tonemapping;
  334. whiteBalanceGUI.Settings = value.WhiteBalance;
  335. colorGradingGUI.Settings = value.ColorGrading;
  336. gammaField.Value = value.Gamma;
  337. exposureScaleField.Value = value.ExposureScale;
  338. }
  339. }
  340. /// <summary>
  341. /// Constructs a new set of GUI elements for inspecting the post process settings object.
  342. /// </summary>
  343. /// <param name="settings">Initial values to assign to the GUI elements.</param>
  344. /// <param name="layout">Layout to append the GUI elements to.</param>
  345. /// <param name="properties">A set of properties that are persisted by the parent inspector. Used for saving state.
  346. /// </param>
  347. public PostProcessSettingsGUI(PostProcessSettings settings, GUILayout layout, SerializableProperties properties)
  348. {
  349. this.settings = settings;
  350. this.properties = properties;
  351. // Auto exposure
  352. enableAutoExposureField.OnChanged += x => { this.settings.EnableAutoExposure = x; MarkAsModified(); ConfirmModify(); };
  353. layout.AddElement(enableAutoExposureField);
  354. autoExposureFoldout.OnToggled += x =>
  355. {
  356. properties.SetBool("autoExposure_Expanded", x);
  357. ToggleFoldoutFields();
  358. };
  359. layout.AddElement(autoExposureFoldout);
  360. autoExposureLayout = layout.AddLayoutX();
  361. {
  362. autoExposureLayout.AddSpace(10);
  363. GUILayoutY contentsLayout = autoExposureLayout.AddLayoutY();
  364. autoExposureGUI = new AutoExposureSettingsGUI(settings.AutoExposure, contentsLayout);
  365. autoExposureGUI.OnChanged += x => { this.settings.AutoExposure = x; MarkAsModified(); };
  366. autoExposureGUI.OnConfirmed += ConfirmModify;
  367. }
  368. // Tonemapping
  369. enableToneMappingField.OnChanged += x => { this.settings.EnableTonemapping = x; MarkAsModified(); ConfirmModify(); };
  370. layout.AddElement(enableToneMappingField);
  371. //// Tonemapping settings
  372. toneMappingFoldout.OnToggled += x =>
  373. {
  374. properties.SetBool("toneMapping_Expanded", x);
  375. ToggleFoldoutFields();
  376. };
  377. layout.AddElement(toneMappingFoldout);
  378. toneMappingLayout = layout.AddLayoutX();
  379. {
  380. toneMappingLayout.AddSpace(10);
  381. GUILayoutY contentsLayout = toneMappingLayout.AddLayoutY();
  382. toneMappingGUI = new TonemappingSettingsGUI(settings.Tonemapping, contentsLayout);
  383. toneMappingGUI.OnChanged += x => { this.settings.Tonemapping = x; MarkAsModified(); };
  384. toneMappingGUI.OnConfirmed += ConfirmModify;
  385. }
  386. //// White balance settings
  387. whiteBalanceFoldout.OnToggled += x =>
  388. {
  389. properties.SetBool("whiteBalance_Expanded", x);
  390. ToggleFoldoutFields();
  391. };
  392. layout.AddElement(whiteBalanceFoldout);
  393. whiteBalanceLayout = layout.AddLayoutX();
  394. {
  395. whiteBalanceLayout.AddSpace(10);
  396. GUILayoutY contentsLayout = whiteBalanceLayout.AddLayoutY();
  397. whiteBalanceGUI = new WhiteBalanceSettingsGUI(settings.WhiteBalance, contentsLayout);
  398. whiteBalanceGUI.OnChanged += x => { this.settings.WhiteBalance = x; MarkAsModified(); };
  399. whiteBalanceGUI.OnConfirmed += ConfirmModify;
  400. }
  401. //// Color grading settings
  402. colorGradingFoldout.OnToggled += x =>
  403. {
  404. properties.SetBool("colorGrading_Expanded", x);
  405. ToggleFoldoutFields();
  406. };
  407. layout.AddElement(colorGradingFoldout);
  408. colorGradingLayout = layout.AddLayoutX();
  409. {
  410. colorGradingLayout.AddSpace(10);
  411. GUILayoutY contentsLayout = colorGradingLayout.AddLayoutY();
  412. colorGradingGUI = new ColorGradingSettingsGUI(settings.ColorGrading, contentsLayout);
  413. colorGradingGUI.OnChanged += x => { this.settings.ColorGrading = x; MarkAsModified(); };
  414. colorGradingGUI.OnConfirmed += ConfirmModify;
  415. }
  416. // Gamma
  417. gammaField.OnChanged += x => { this.settings.Gamma = x; MarkAsModified(); ConfirmModify(); };
  418. layout.AddElement(gammaField);
  419. // Exposure scale
  420. exposureScaleField.OnChanged += x => { this.settings.ExposureScale = x; MarkAsModified(); ConfirmModify(); };
  421. layout.AddElement(exposureScaleField);
  422. ToggleFoldoutFields();
  423. }
  424. /// <summary>
  425. /// Marks the contents of the inspector as modified.
  426. /// </summary>
  427. private void MarkAsModified()
  428. {
  429. if (OnChanged != null)
  430. OnChanged(settings);
  431. }
  432. /// <summary>
  433. /// Confirms any queued modifications.
  434. /// </summary>
  435. private void ConfirmModify()
  436. {
  437. if (OnConfirmed != null)
  438. OnConfirmed();
  439. }
  440. /// <summary>
  441. /// Hides or shows settings property GUI elements depending on set values.
  442. /// </summary>
  443. private void ToggleFoldoutFields()
  444. {
  445. autoExposureLayout.Active = properties.GetBool("autoExposure_Expanded");
  446. toneMappingLayout.Active = properties.GetBool("toneMapping_Expanded");
  447. whiteBalanceLayout.Active = properties.GetBool("whiteBalance_Expanded");
  448. colorGradingLayout.Active = properties.GetBool("colorGrading_Expanded");
  449. }
  450. }
  451. /** @} */
  452. }