RenderSettingsInspector.cs 39 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890
  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="DepthOfFieldSettings"/> object.
  298. /// </summary>
  299. internal class DepthOfFieldSettingsGUI
  300. {
  301. private DepthOfFieldSettings settings;
  302. private GUIToggleField enabledField = new GUIToggleField(new LocEdString("Enabled"));
  303. private GUIFloatField focalDistanceField = new GUIFloatField(new LocEdString("Focal distance"));
  304. private GUIFloatField focalRangeField = new GUIFloatField(new LocEdString("Focal range"));
  305. private GUIFloatField nearTransitionRangeField = new GUIFloatField(new LocEdString("Near transition range"));
  306. private GUIFloatField farTransitionRangeField = new GUIFloatField(new LocEdString("Far transition range"));
  307. private GUIFloatField nearBlurAmount = new GUIFloatField(new LocEdString("Near blur amount"));
  308. private GUIFloatField farBlurAmount = new GUIFloatField(new LocEdString("Far blur amount"));
  309. public Action<DepthOfFieldSettings> OnChanged;
  310. public Action OnConfirmed;
  311. /// <summary>
  312. /// Current value of the settings object.
  313. /// </summary>
  314. public DepthOfFieldSettings Settings
  315. {
  316. get { return settings; }
  317. set
  318. {
  319. settings = value;
  320. enabledField.Value = value.Enabled;
  321. focalDistanceField.Value = value.FocalDistance;
  322. focalRangeField.Value = value.FocalRange;
  323. nearTransitionRangeField.Value = value.NearTransitionRange;
  324. farTransitionRangeField.Value = value.FarTransitionRange;
  325. nearBlurAmount.Value = value.NearBlurAmount;
  326. farBlurAmount.Value = value.FarBlurAmount;
  327. }
  328. }
  329. /// <summary>
  330. /// Constructs a new set of GUI elements for inspecting the depth of field settings object.
  331. /// </summary>
  332. /// <param name="settings">Initial values to assign to the GUI elements.</param>
  333. /// <param name="layout">Layout to append the GUI elements to.</param>
  334. public DepthOfFieldSettingsGUI(DepthOfFieldSettings settings, GUILayout layout)
  335. {
  336. this.settings = settings;
  337. enabledField.OnChanged += x => { this.settings.Enabled = x; MarkAsModified(); ConfirmModify(); };
  338. focalDistanceField.OnChanged += x => { this.settings.FocalDistance = x; MarkAsModified(); ConfirmModify(); };
  339. focalRangeField.OnChanged += x => { this.settings.FocalRange = x; MarkAsModified(); ConfirmModify(); };
  340. nearTransitionRangeField.OnChanged += x => { this.settings.NearTransitionRange = x; MarkAsModified(); ConfirmModify(); };
  341. farTransitionRangeField.OnChanged += x => { this.settings.FarTransitionRange = x; MarkAsModified(); ConfirmModify(); };
  342. nearBlurAmount.OnChanged += x => { this.settings.NearBlurAmount = x; MarkAsModified(); ConfirmModify(); };
  343. farBlurAmount.OnChanged += x => { this.settings.FarBlurAmount = x; MarkAsModified(); ConfirmModify(); };
  344. layout.AddElement(enabledField);
  345. layout.AddElement(focalDistanceField);
  346. layout.AddElement(focalRangeField);
  347. layout.AddElement(nearTransitionRangeField);
  348. layout.AddElement(farTransitionRangeField);
  349. layout.AddElement(nearBlurAmount);
  350. layout.AddElement(farBlurAmount);
  351. }
  352. /// <summary>
  353. /// Marks the contents of the inspector as modified.
  354. /// </summary>
  355. private void MarkAsModified()
  356. {
  357. if (OnChanged != null)
  358. OnChanged(settings);
  359. }
  360. /// <summary>
  361. /// Confirms any queued modifications.
  362. /// </summary>
  363. private void ConfirmModify()
  364. {
  365. if (OnConfirmed != null)
  366. OnConfirmed();
  367. }
  368. }
  369. /// <summary>
  370. /// Draws GUI elements for inspecting an <see cref="AmbientOcclusionSettings"/> object.
  371. /// </summary>
  372. internal class AmbientOcclusionSettingsGUI
  373. {
  374. private AmbientOcclusionSettings settings;
  375. private GUIToggleField enabledField = new GUIToggleField(new LocEdString("Enabled"));
  376. private GUISliderField radiusField = new GUISliderField(0.01f, 10.0f, new LocEdString("Radius"));
  377. private GUISliderField biasField = new GUISliderField(0, 500, new LocEdString("Bias"));
  378. private GUIFloatField fadeDistanceField = new GUIFloatField(new LocEdString("Fade distance"));
  379. private GUIFloatField fadeRangeField = new GUIFloatField(new LocEdString("Fade range"));
  380. private GUISliderField intensityField = new GUISliderField(0.1f, 3.0f, new LocEdString("Intensity"));
  381. private GUISliderField powerField = new GUISliderField(1, 5, new LocEdString("Power"));
  382. private GUISliderField qualityField = new GUISliderField(0, 4, new LocEdString("Quality"));
  383. public Action<AmbientOcclusionSettings> OnChanged;
  384. public Action OnConfirmed;
  385. /// <summary>
  386. /// Current value of the settings object.
  387. /// </summary>
  388. public AmbientOcclusionSettings Settings
  389. {
  390. get { return settings; }
  391. set
  392. {
  393. settings = value;
  394. enabledField.Value = value.Enabled;
  395. radiusField.Value = value.Radius;
  396. biasField.Value = value.Bias;
  397. fadeDistanceField.Value = value.FadeDistance;
  398. fadeRangeField.Value = value.FadeRange;
  399. intensityField.Value = value.Intensity;
  400. powerField.Value = value.Power;
  401. qualityField.Value = value.Quality;
  402. }
  403. }
  404. /// <summary>
  405. /// Constructs a new set of GUI elements for inspecting the ambient occlusion settings object.
  406. /// </summary>
  407. /// <param name="settings">Initial values to assign to the GUI elements.</param>
  408. /// <param name="layout">Layout to append the GUI elements to.</param>
  409. public AmbientOcclusionSettingsGUI(AmbientOcclusionSettings settings, GUILayout layout)
  410. {
  411. this.settings = settings;
  412. enabledField.OnChanged += x => { this.settings.Enabled = x; MarkAsModified(); ConfirmModify(); };
  413. radiusField.OnChanged += x => { this.settings.Radius = x; MarkAsModified(); ConfirmModify(); };
  414. biasField.OnChanged += x => { this.settings.Bias = x; MarkAsModified(); ConfirmModify(); };
  415. fadeDistanceField.OnChanged += x => { this.settings.FadeDistance = x; MarkAsModified(); ConfirmModify(); };
  416. fadeRangeField.OnChanged += x => { this.settings.FadeRange = x; MarkAsModified(); ConfirmModify(); };
  417. intensityField.OnChanged += x => { this.settings.Intensity = x; MarkAsModified(); ConfirmModify(); };
  418. powerField.OnChanged += x => { this.settings.Power = x; MarkAsModified(); ConfirmModify(); };
  419. qualityField.OnChanged += x => { this.settings.Quality = (uint)x; MarkAsModified(); ConfirmModify(); };
  420. qualityField.Step = 1.0f;
  421. layout.AddElement(enabledField);
  422. layout.AddElement(radiusField);
  423. layout.AddElement(biasField);
  424. layout.AddElement(fadeDistanceField);
  425. layout.AddElement(fadeRangeField);
  426. layout.AddElement(intensityField);
  427. layout.AddElement(powerField);
  428. layout.AddElement(qualityField);
  429. }
  430. /// <summary>
  431. /// Marks the contents of the inspector as modified.
  432. /// </summary>
  433. private void MarkAsModified()
  434. {
  435. if (OnChanged != null)
  436. OnChanged(settings);
  437. }
  438. /// <summary>
  439. /// Confirms any queued modifications.
  440. /// </summary>
  441. private void ConfirmModify()
  442. {
  443. if (OnConfirmed != null)
  444. OnConfirmed();
  445. }
  446. }
  447. /// <summary>
  448. /// Draws GUI elements for inspecting an <see cref="ScreenSpaceReflectionsSettings"/> object.
  449. /// </summary>
  450. internal class ScreenSpaceReflectionsSettingsGUI
  451. {
  452. private ScreenSpaceReflectionsSettings settings;
  453. private GUIToggleField enabledField = new GUIToggleField(new LocEdString("Enabled"));
  454. private GUISliderField qualityField = new GUISliderField(0, 4, new LocEdString("Quality"));
  455. private GUISliderField intensityField = new GUISliderField(0.0f, 1.0f, new LocEdString("Intensity"));
  456. private GUISliderField maxRoughnessField = new GUISliderField(0.0f, 1.0f, new LocEdString("Max. roughness"));
  457. public Action<ScreenSpaceReflectionsSettings> OnChanged;
  458. public Action OnConfirmed;
  459. /// <summary>
  460. /// Current value of the settings object.
  461. /// </summary>
  462. public ScreenSpaceReflectionsSettings Settings
  463. {
  464. get { return settings; }
  465. set
  466. {
  467. settings = value;
  468. enabledField.Value = value.Enabled;
  469. qualityField.Value = value.Quality;
  470. intensityField.Value = value.Intensity;
  471. maxRoughnessField.Value = value.MaxRoughness;
  472. }
  473. }
  474. /// <summary>
  475. /// Constructs a new set of GUI elements for inspecting the screen space reflections settings object.
  476. /// </summary>
  477. /// <param name="settings">Initial values to assign to the GUI elements.</param>
  478. /// <param name="layout">Layout to append the GUI elements to.</param>
  479. public ScreenSpaceReflectionsSettingsGUI(ScreenSpaceReflectionsSettings settings, GUILayout layout)
  480. {
  481. this.settings = settings;
  482. enabledField.OnChanged += x => { this.settings.Enabled = x; MarkAsModified(); ConfirmModify(); };
  483. qualityField.OnChanged += x => { this.settings.Quality = (uint)x; MarkAsModified(); ConfirmModify(); };
  484. intensityField.OnChanged += x => { this.settings.Intensity = x; MarkAsModified(); ConfirmModify(); };
  485. maxRoughnessField.OnChanged += x => { this.settings.MaxRoughness = x; MarkAsModified(); ConfirmModify(); };
  486. qualityField.Step = 1.0f;
  487. layout.AddElement(enabledField);
  488. layout.AddElement(qualityField);
  489. layout.AddElement(intensityField);
  490. layout.AddElement(maxRoughnessField);
  491. }
  492. /// <summary>
  493. /// Marks the contents of the inspector as modified.
  494. /// </summary>
  495. private void MarkAsModified()
  496. {
  497. if (OnChanged != null)
  498. OnChanged(settings);
  499. }
  500. /// <summary>
  501. /// Confirms any queued modifications.
  502. /// </summary>
  503. private void ConfirmModify()
  504. {
  505. if (OnConfirmed != null)
  506. OnConfirmed();
  507. }
  508. }
  509. /// <summary>
  510. /// Draws GUI elements for inspecting an <see cref="RenderSettings"/> object.
  511. /// </summary>
  512. internal class RenderSettingsGUI
  513. {
  514. private RenderSettings settings;
  515. private SerializableProperties properties;
  516. private GUIToggleField enableHDRField = new GUIToggleField(new LocEdString("Enable HDR"));
  517. private GUIToggleField enableLightingField = new GUIToggleField(new LocEdString("Enable lighting"));
  518. private GUIToggleField enableShadowsField = new GUIToggleField(new LocEdString("Enable shadows"));
  519. private GUIToggleField enableIndirectLightingField = new GUIToggleField(new LocEdString("Enable indirect lighting"));
  520. private GUIToggleField overlayOnlyField = new GUIToggleField(new LocEdString("Overlay only"));
  521. private GUIToggleField enableFXAAField = new GUIToggleField(new LocEdString("Enable FXAA"));
  522. private GUIToggleField enableAutoExposureField = new GUIToggleField(new LocEdString("Enable auto exposure"));
  523. private GUIToggle autoExposureFoldout = new GUIToggle(new LocEdString("Auto exposure"), EditorStyles.Foldout);
  524. private AutoExposureSettingsGUI autoExposureGUI;
  525. private GUIToggleField enableToneMappingField = new GUIToggleField(new LocEdString("Enable tone mapping"));
  526. private GUIToggle toneMappingFoldout = new GUIToggle(new LocEdString("Tone mapping"), EditorStyles.Foldout);
  527. private TonemappingSettingsGUI toneMappingGUI;
  528. private GUIToggle whiteBalanceFoldout = new GUIToggle(new LocEdString("White balance"), EditorStyles.Foldout);
  529. private WhiteBalanceSettingsGUI whiteBalanceGUI;
  530. private GUIToggle colorGradingFoldout = new GUIToggle(new LocEdString("Color grading"), EditorStyles.Foldout);
  531. private ColorGradingSettingsGUI colorGradingGUI;
  532. private GUIToggle depthOfFieldFoldout = new GUIToggle("Depth of field", EditorStyles.Foldout);
  533. private DepthOfFieldSettingsGUI depthOfFieldGUI;
  534. private GUIToggle ambientOcclusionFoldout = new GUIToggle("Ambient occlusion", EditorStyles.Foldout);
  535. private AmbientOcclusionSettingsGUI ambientOcclusionGUI;
  536. private GUIToggle screenSpaceReflectionsFoldout = new GUIToggle("Screen space reflections", EditorStyles.Foldout);
  537. private ScreenSpaceReflectionsSettingsGUI screenSpaceReflectionsGUI;
  538. private GUISliderField gammaField = new GUISliderField(1.0f, 3.0f, new LocEdString("Gamma"));
  539. private GUISliderField exposureScaleField = new GUISliderField(-8.0f, 8.0f, new LocEdString("Exposure scale"));
  540. private GUILayout autoExposureLayout;
  541. private GUILayout toneMappingLayout;
  542. private GUILayout whiteBalanceLayout;
  543. private GUILayout colorGradingLayout;
  544. private GUILayout depthOfFieldLayout;
  545. private GUILayout ambientOcclusionLayout;
  546. private GUILayout screenSpaceReflectionsLayout;
  547. public Action<RenderSettings> OnChanged;
  548. public Action OnConfirmed;
  549. /// <summary>
  550. /// Current value of the settings object.
  551. /// </summary>
  552. public RenderSettings Settings
  553. {
  554. get { return settings; }
  555. set
  556. {
  557. settings = value;
  558. enableAutoExposureField.Value = value.EnableAutoExposure;
  559. autoExposureGUI.Settings = value.AutoExposure;
  560. enableToneMappingField.Value = value.EnableTonemapping;
  561. toneMappingGUI.Settings = value.Tonemapping;
  562. whiteBalanceGUI.Settings = value.WhiteBalance;
  563. colorGradingGUI.Settings = value.ColorGrading;
  564. depthOfFieldGUI.Settings = value.DepthOfField;
  565. ambientOcclusionGUI.Settings = value.AmbientOcclusion;
  566. screenSpaceReflectionsGUI.Settings = value.ScreenSpaceReflections;
  567. gammaField.Value = value.Gamma;
  568. exposureScaleField.Value = value.ExposureScale;
  569. enableHDRField.Value = value.EnableHDR;
  570. enableLightingField.Value = value.EnableLighting;
  571. enableIndirectLightingField.Value = value.EnableIndirectLighting;
  572. enableShadowsField.Value = value.EnableShadows;
  573. overlayOnlyField.Value = value.OverlayOnly;
  574. enableFXAAField.Value = value.EnableFXAA;
  575. }
  576. }
  577. /// <summary>
  578. /// Constructs a new set of GUI elements for inspecting the post process settings object.
  579. /// </summary>
  580. /// <param name="settings">Initial values to assign to the GUI elements.</param>
  581. /// <param name="layout">Layout to append the GUI elements to.</param>
  582. /// <param name="properties">A set of properties that are persisted by the parent inspector. Used for saving state.
  583. /// </param>
  584. public RenderSettingsGUI(RenderSettings settings, GUILayout layout, SerializableProperties properties)
  585. {
  586. this.settings = settings;
  587. this.properties = properties;
  588. // Enable HDR
  589. enableHDRField.OnChanged += x => { this.settings.EnableHDR = x; MarkAsModified(); ConfirmModify(); };
  590. layout.AddElement(enableHDRField);
  591. // Enable lighting
  592. enableLightingField.OnChanged += x => { this.settings.EnableLighting = x; MarkAsModified(); ConfirmModify(); };
  593. layout.AddElement(enableLightingField);
  594. // Enable shadows
  595. enableShadowsField.OnChanged += x => { this.settings.EnableShadows = x; MarkAsModified(); ConfirmModify(); };
  596. layout.AddElement(enableShadowsField);
  597. // Enable indirect lighting
  598. enableIndirectLightingField.OnChanged += x => { this.settings.EnableIndirectLighting = x; MarkAsModified(); ConfirmModify(); };
  599. layout.AddElement(enableIndirectLightingField);
  600. // Overlay only
  601. overlayOnlyField.OnChanged += x => { this.settings.OverlayOnly = x; MarkAsModified(); ConfirmModify(); };
  602. layout.AddElement(overlayOnlyField);
  603. // Auto exposure
  604. enableAutoExposureField.OnChanged += x => { this.settings.EnableAutoExposure = x; MarkAsModified(); ConfirmModify(); };
  605. layout.AddElement(enableAutoExposureField);
  606. autoExposureFoldout.OnToggled += x =>
  607. {
  608. properties.SetBool("autoExposure_Expanded", x);
  609. ToggleFoldoutFields();
  610. };
  611. layout.AddElement(autoExposureFoldout);
  612. autoExposureLayout = layout.AddLayoutX();
  613. {
  614. autoExposureLayout.AddSpace(10);
  615. GUILayoutY contentsLayout = autoExposureLayout.AddLayoutY();
  616. autoExposureGUI = new AutoExposureSettingsGUI(settings.AutoExposure, contentsLayout);
  617. autoExposureGUI.OnChanged += x => { this.settings.AutoExposure = x; MarkAsModified(); };
  618. autoExposureGUI.OnConfirmed += ConfirmModify;
  619. }
  620. // Tonemapping
  621. enableToneMappingField.OnChanged += x => { this.settings.EnableTonemapping = x; MarkAsModified(); ConfirmModify(); };
  622. layout.AddElement(enableToneMappingField);
  623. //// Tonemapping settings
  624. toneMappingFoldout.OnToggled += x =>
  625. {
  626. properties.SetBool("toneMapping_Expanded", x);
  627. ToggleFoldoutFields();
  628. };
  629. layout.AddElement(toneMappingFoldout);
  630. toneMappingLayout = layout.AddLayoutX();
  631. {
  632. toneMappingLayout.AddSpace(10);
  633. GUILayoutY contentsLayout = toneMappingLayout.AddLayoutY();
  634. toneMappingGUI = new TonemappingSettingsGUI(settings.Tonemapping, contentsLayout);
  635. toneMappingGUI.OnChanged += x => { this.settings.Tonemapping = x; MarkAsModified(); };
  636. toneMappingGUI.OnConfirmed += ConfirmModify;
  637. }
  638. //// White balance settings
  639. whiteBalanceFoldout.OnToggled += x =>
  640. {
  641. properties.SetBool("whiteBalance_Expanded", x);
  642. ToggleFoldoutFields();
  643. };
  644. layout.AddElement(whiteBalanceFoldout);
  645. whiteBalanceLayout = layout.AddLayoutX();
  646. {
  647. whiteBalanceLayout.AddSpace(10);
  648. GUILayoutY contentsLayout = whiteBalanceLayout.AddLayoutY();
  649. whiteBalanceGUI = new WhiteBalanceSettingsGUI(settings.WhiteBalance, contentsLayout);
  650. whiteBalanceGUI.OnChanged += x => { this.settings.WhiteBalance = x; MarkAsModified(); };
  651. whiteBalanceGUI.OnConfirmed += ConfirmModify;
  652. }
  653. //// Color grading settings
  654. colorGradingFoldout.OnToggled += x =>
  655. {
  656. properties.SetBool("colorGrading_Expanded", x);
  657. ToggleFoldoutFields();
  658. };
  659. layout.AddElement(colorGradingFoldout);
  660. colorGradingLayout = layout.AddLayoutX();
  661. {
  662. colorGradingLayout.AddSpace(10);
  663. GUILayoutY contentsLayout = colorGradingLayout.AddLayoutY();
  664. colorGradingGUI = new ColorGradingSettingsGUI(settings.ColorGrading, contentsLayout);
  665. colorGradingGUI.OnChanged += x => { this.settings.ColorGrading = x; MarkAsModified(); };
  666. colorGradingGUI.OnConfirmed += ConfirmModify;
  667. }
  668. // Gamma
  669. gammaField.OnChanged += x => { this.settings.Gamma = x; MarkAsModified(); ConfirmModify(); };
  670. layout.AddElement(gammaField);
  671. // Exposure scale
  672. exposureScaleField.OnChanged += x => { this.settings.ExposureScale = x; MarkAsModified(); ConfirmModify(); };
  673. layout.AddElement(exposureScaleField);
  674. //// Depth of field settings
  675. depthOfFieldFoldout.OnToggled += x =>
  676. {
  677. properties.SetBool("depthOfField_Expanded", x);
  678. ToggleFoldoutFields();
  679. };
  680. layout.AddElement(depthOfFieldFoldout);
  681. depthOfFieldLayout = layout.AddLayoutX();
  682. {
  683. depthOfFieldLayout.AddSpace(10);
  684. GUILayoutY contentsLayout = depthOfFieldLayout.AddLayoutY();
  685. depthOfFieldGUI = new DepthOfFieldSettingsGUI(settings.DepthOfField, contentsLayout);
  686. depthOfFieldGUI.OnChanged += x => { this.settings.DepthOfField = x; MarkAsModified(); };
  687. depthOfFieldGUI.OnConfirmed += ConfirmModify;
  688. }
  689. //// Ambient occlusion settings
  690. ambientOcclusionFoldout.OnToggled += x =>
  691. {
  692. properties.SetBool("ambientOcclusion_Expanded", x);
  693. ToggleFoldoutFields();
  694. };
  695. layout.AddElement(ambientOcclusionFoldout);
  696. ambientOcclusionLayout = layout.AddLayoutX();
  697. {
  698. ambientOcclusionLayout.AddSpace(10);
  699. GUILayoutY contentsLayout = ambientOcclusionLayout.AddLayoutY();
  700. ambientOcclusionGUI = new AmbientOcclusionSettingsGUI(settings.AmbientOcclusion, contentsLayout);
  701. ambientOcclusionGUI.OnChanged += x => { this.settings.AmbientOcclusion = x; MarkAsModified(); };
  702. ambientOcclusionGUI.OnConfirmed += ConfirmModify;
  703. }
  704. //// Screen space reflections settings
  705. screenSpaceReflectionsFoldout.OnToggled += x =>
  706. {
  707. properties.SetBool("screenSpaceReflections_Expanded", x);
  708. ToggleFoldoutFields();
  709. };
  710. layout.AddElement(screenSpaceReflectionsFoldout);
  711. screenSpaceReflectionsLayout = layout.AddLayoutX();
  712. {
  713. screenSpaceReflectionsLayout.AddSpace(10);
  714. GUILayoutY contentsLayout = screenSpaceReflectionsLayout.AddLayoutY();
  715. screenSpaceReflectionsGUI = new ScreenSpaceReflectionsSettingsGUI(settings.ScreenSpaceReflections, contentsLayout);
  716. screenSpaceReflectionsGUI.OnChanged += x => { this.settings.ScreenSpaceReflections = x; MarkAsModified(); };
  717. screenSpaceReflectionsGUI.OnConfirmed += ConfirmModify;
  718. }
  719. // FXAA
  720. enableFXAAField.OnChanged += x => { this.settings.EnableFXAA = x; MarkAsModified(); ConfirmModify(); };
  721. layout.AddElement(enableFXAAField);
  722. ToggleFoldoutFields();
  723. }
  724. /// <summary>
  725. /// Marks the contents of the inspector as modified.
  726. /// </summary>
  727. private void MarkAsModified()
  728. {
  729. if (OnChanged != null)
  730. OnChanged(settings);
  731. }
  732. /// <summary>
  733. /// Confirms any queued modifications.
  734. /// </summary>
  735. private void ConfirmModify()
  736. {
  737. if (OnConfirmed != null)
  738. OnConfirmed();
  739. }
  740. /// <summary>
  741. /// Hides or shows settings property GUI elements depending on set values.
  742. /// </summary>
  743. private void ToggleFoldoutFields()
  744. {
  745. autoExposureLayout.Active = properties.GetBool("autoExposure_Expanded");
  746. toneMappingLayout.Active = properties.GetBool("toneMapping_Expanded");
  747. whiteBalanceLayout.Active = properties.GetBool("whiteBalance_Expanded");
  748. colorGradingLayout.Active = properties.GetBool("colorGrading_Expanded");
  749. depthOfFieldLayout.Active = properties.GetBool("depthOfField_Expanded");
  750. ambientOcclusionLayout.Active = properties.GetBool("ambientOcclusion_Expanded");
  751. screenSpaceReflectionsLayout.Active = properties.GetBool("screenSpaceReflections_Expanded");
  752. }
  753. }
  754. /** @} */
  755. }