RenderSettingsInspector.cs 44 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015
  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="ShadowSettings"/> object.
  511. /// </summary>
  512. internal class ShadowSettingsGUI
  513. {
  514. private ShadowSettings settings;
  515. private GUIFloatField directionalShadowDistanceField = new GUIFloatField(new LocEdString("Directional shadow distance"));
  516. private GUIIntField numCascadesField = new GUIIntField(new LocEdString("Cascade count"));
  517. private GUIFloatField cascadeDistributionExponentField = new GUIFloatField(new LocEdString("Cascade distribution exponent"));
  518. private GUISliderField filteringQualityField = new GUISliderField(0, 4, new LocEdString("Filtering quality"));
  519. public Action<ShadowSettings> OnChanged;
  520. public Action OnConfirmed;
  521. /// <summary>
  522. /// Current value of the settings object.
  523. /// </summary>
  524. public ShadowSettings Settings
  525. {
  526. get { return settings; }
  527. set
  528. {
  529. settings = value;
  530. directionalShadowDistanceField.Value = value.DirectionalShadowDistance;
  531. numCascadesField.Value = (int)value.NumCascades;
  532. cascadeDistributionExponentField.Value = value.CascadeDistributionExponent;
  533. filteringQualityField.Value = value.ShadowFilteringQuality;
  534. }
  535. }
  536. /// <summary>
  537. /// Constructs a new set of GUI elements for inspecting the shadow settings object.
  538. /// </summary>
  539. /// <param name="settings">Initial values to assign to the GUI elements.</param>
  540. /// <param name="layout">Layout to append the GUI elements to.</param>
  541. public ShadowSettingsGUI(ShadowSettings settings, GUILayout layout)
  542. {
  543. this.settings = settings;
  544. directionalShadowDistanceField.OnChanged += x =>
  545. {
  546. this.settings.DirectionalShadowDistance = x;
  547. MarkAsModified();
  548. ConfirmModify();
  549. };
  550. numCascadesField.OnChanged += x =>
  551. {
  552. this.settings.NumCascades = (uint) x;
  553. MarkAsModified();
  554. ConfirmModify();
  555. };
  556. cascadeDistributionExponentField.OnChanged += x =>
  557. {
  558. this.settings.CascadeDistributionExponent = x;
  559. MarkAsModified();
  560. ConfirmModify();
  561. };
  562. filteringQualityField.OnChanged += x =>
  563. {
  564. this.settings.ShadowFilteringQuality = (uint)x;
  565. MarkAsModified();
  566. ConfirmModify();
  567. };
  568. filteringQualityField.Step = 1.0f;
  569. layout.AddElement(directionalShadowDistanceField);
  570. layout.AddElement(numCascadesField);
  571. layout.AddElement(cascadeDistributionExponentField);
  572. layout.AddElement(filteringQualityField);
  573. }
  574. /// <summary>
  575. /// Marks the contents of the inspector as modified.
  576. /// </summary>
  577. private void MarkAsModified()
  578. {
  579. if (OnChanged != null)
  580. OnChanged(settings);
  581. }
  582. /// <summary>
  583. /// Confirms any queued modifications.
  584. /// </summary>
  585. private void ConfirmModify()
  586. {
  587. if (OnConfirmed != null)
  588. OnConfirmed();
  589. }
  590. }
  591. /// <summary>
  592. /// Draws GUI elements for inspecting an <see cref="RenderSettings"/> object.
  593. /// </summary>
  594. internal class RenderSettingsGUI
  595. {
  596. private RenderSettings settings;
  597. private SerializableProperties properties;
  598. private GUIToggleField enableHDRField = new GUIToggleField(new LocEdString("Enable HDR"));
  599. private GUIToggleField enableLightingField = new GUIToggleField(new LocEdString("Enable lighting"));
  600. private GUIToggleField enableShadowsField = new GUIToggleField(new LocEdString("Enable shadows"));
  601. private GUIToggleField enableIndirectLightingField = new GUIToggleField(new LocEdString("Enable indirect lighting"));
  602. private GUIToggleField overlayOnlyField = new GUIToggleField(new LocEdString("Overlay only"));
  603. private GUIToggleField enableFXAAField = new GUIToggleField(new LocEdString("Enable FXAA"));
  604. private GUIToggleField enableAutoExposureField = new GUIToggleField(new LocEdString("Enable auto exposure"));
  605. private GUIToggle autoExposureFoldout = new GUIToggle(new LocEdString("Auto exposure"), EditorStyles.Foldout);
  606. private AutoExposureSettingsGUI autoExposureGUI;
  607. private GUIToggleField enableToneMappingField = new GUIToggleField(new LocEdString("Enable tone mapping"));
  608. private GUIToggle toneMappingFoldout = new GUIToggle(new LocEdString("Tone mapping"), EditorStyles.Foldout);
  609. private TonemappingSettingsGUI toneMappingGUI;
  610. private GUIToggle whiteBalanceFoldout = new GUIToggle(new LocEdString("White balance"), EditorStyles.Foldout);
  611. private WhiteBalanceSettingsGUI whiteBalanceGUI;
  612. private GUIToggle colorGradingFoldout = new GUIToggle(new LocEdString("Color grading"), EditorStyles.Foldout);
  613. private ColorGradingSettingsGUI colorGradingGUI;
  614. private GUIToggle depthOfFieldFoldout = new GUIToggle("Depth of field", EditorStyles.Foldout);
  615. private DepthOfFieldSettingsGUI depthOfFieldGUI;
  616. private GUIToggle ambientOcclusionFoldout = new GUIToggle("Ambient occlusion", EditorStyles.Foldout);
  617. private AmbientOcclusionSettingsGUI ambientOcclusionGUI;
  618. private GUIToggle screenSpaceReflectionsFoldout = new GUIToggle("Screen space reflections", EditorStyles.Foldout);
  619. private ScreenSpaceReflectionsSettingsGUI screenSpaceReflectionsGUI;
  620. private GUIToggle shadowsFoldout = new GUIToggle("Shadows", EditorStyles.Foldout);
  621. private ShadowSettingsGUI shadowsGUI;
  622. private GUISliderField gammaField = new GUISliderField(1.0f, 3.0f, new LocEdString("Gamma"));
  623. private GUISliderField exposureScaleField = new GUISliderField(-8.0f, 8.0f, new LocEdString("Exposure scale"));
  624. private GUILayout autoExposureLayout;
  625. private GUILayout toneMappingLayout;
  626. private GUILayout whiteBalanceLayout;
  627. private GUILayout colorGradingLayout;
  628. private GUILayout depthOfFieldLayout;
  629. private GUILayout ambientOcclusionLayout;
  630. private GUILayout screenSpaceReflectionsLayout;
  631. private GUILayout shadowsLayout;
  632. public Action<RenderSettings> OnChanged;
  633. public Action OnConfirmed;
  634. /// <summary>
  635. /// Current value of the settings object.
  636. /// </summary>
  637. public RenderSettings Settings
  638. {
  639. get { return settings; }
  640. set
  641. {
  642. settings = value;
  643. enableAutoExposureField.Value = value.EnableAutoExposure;
  644. autoExposureGUI.Settings = value.AutoExposure;
  645. enableToneMappingField.Value = value.EnableTonemapping;
  646. toneMappingGUI.Settings = value.Tonemapping;
  647. whiteBalanceGUI.Settings = value.WhiteBalance;
  648. colorGradingGUI.Settings = value.ColorGrading;
  649. depthOfFieldGUI.Settings = value.DepthOfField;
  650. ambientOcclusionGUI.Settings = value.AmbientOcclusion;
  651. screenSpaceReflectionsGUI.Settings = value.ScreenSpaceReflections;
  652. shadowsGUI.Settings = value.ShadowSettings;
  653. gammaField.Value = value.Gamma;
  654. exposureScaleField.Value = value.ExposureScale;
  655. enableHDRField.Value = value.EnableHDR;
  656. enableLightingField.Value = value.EnableLighting;
  657. enableIndirectLightingField.Value = value.EnableIndirectLighting;
  658. enableShadowsField.Value = value.EnableShadows;
  659. overlayOnlyField.Value = value.OverlayOnly;
  660. enableFXAAField.Value = value.EnableFXAA;
  661. }
  662. }
  663. /// <summary>
  664. /// Constructs a new set of GUI elements for inspecting the post process settings object.
  665. /// </summary>
  666. /// <param name="settings">Initial values to assign to the GUI elements.</param>
  667. /// <param name="layout">Layout to append the GUI elements to.</param>
  668. /// <param name="properties">A set of properties that are persisted by the parent inspector. Used for saving state.
  669. /// </param>
  670. public RenderSettingsGUI(RenderSettings settings, GUILayout layout, SerializableProperties properties)
  671. {
  672. this.settings = settings;
  673. this.properties = properties;
  674. // Enable HDR
  675. enableHDRField.OnChanged += x => { this.settings.EnableHDR = x; MarkAsModified(); ConfirmModify(); };
  676. layout.AddElement(enableHDRField);
  677. // Enable lighting
  678. enableLightingField.OnChanged += x => { this.settings.EnableLighting = x; MarkAsModified(); ConfirmModify(); };
  679. layout.AddElement(enableLightingField);
  680. // Enable indirect lighting
  681. enableIndirectLightingField.OnChanged += x => { this.settings.EnableIndirectLighting = x; MarkAsModified(); ConfirmModify(); };
  682. layout.AddElement(enableIndirectLightingField);
  683. // Overlay only
  684. overlayOnlyField.OnChanged += x => { this.settings.OverlayOnly = x; MarkAsModified(); ConfirmModify(); };
  685. layout.AddElement(overlayOnlyField);
  686. // Shadows
  687. enableShadowsField.OnChanged += x => { this.settings.EnableShadows = x; MarkAsModified(); ConfirmModify(); };
  688. layout.AddElement(enableShadowsField);
  689. shadowsFoldout.AcceptsKeyFocus = false;
  690. shadowsFoldout.OnToggled += x =>
  691. {
  692. properties.SetBool("shadows_Expanded", x);
  693. ToggleFoldoutFields();
  694. };
  695. layout.AddElement(shadowsFoldout);
  696. shadowsLayout = layout.AddLayoutX();
  697. {
  698. shadowsLayout.AddSpace(10);
  699. GUILayoutY contentsLayout = shadowsLayout.AddLayoutY();
  700. shadowsGUI = new ShadowSettingsGUI(settings.ShadowSettings, contentsLayout);
  701. shadowsGUI.OnChanged += x => { this.settings.ShadowSettings = x; MarkAsModified(); };
  702. shadowsGUI.OnConfirmed += ConfirmModify;
  703. }
  704. // Auto exposure
  705. enableAutoExposureField.OnChanged += x => { this.settings.EnableAutoExposure = x; MarkAsModified(); ConfirmModify(); };
  706. layout.AddElement(enableAutoExposureField);
  707. autoExposureFoldout.AcceptsKeyFocus = false;
  708. autoExposureFoldout.OnToggled += x =>
  709. {
  710. properties.SetBool("autoExposure_Expanded", x);
  711. ToggleFoldoutFields();
  712. };
  713. layout.AddElement(autoExposureFoldout);
  714. autoExposureLayout = layout.AddLayoutX();
  715. {
  716. autoExposureLayout.AddSpace(10);
  717. GUILayoutY contentsLayout = autoExposureLayout.AddLayoutY();
  718. autoExposureGUI = new AutoExposureSettingsGUI(settings.AutoExposure, contentsLayout);
  719. autoExposureGUI.OnChanged += x => { this.settings.AutoExposure = x; MarkAsModified(); };
  720. autoExposureGUI.OnConfirmed += ConfirmModify;
  721. }
  722. // Tonemapping
  723. enableToneMappingField.OnChanged += x => { this.settings.EnableTonemapping = x; MarkAsModified(); ConfirmModify(); };
  724. layout.AddElement(enableToneMappingField);
  725. //// Tonemapping settings
  726. toneMappingFoldout.AcceptsKeyFocus = false;
  727. toneMappingFoldout.OnToggled += x =>
  728. {
  729. properties.SetBool("toneMapping_Expanded", x);
  730. ToggleFoldoutFields();
  731. };
  732. layout.AddElement(toneMappingFoldout);
  733. toneMappingLayout = layout.AddLayoutX();
  734. {
  735. toneMappingLayout.AddSpace(10);
  736. GUILayoutY contentsLayout = toneMappingLayout.AddLayoutY();
  737. toneMappingGUI = new TonemappingSettingsGUI(settings.Tonemapping, contentsLayout);
  738. toneMappingGUI.OnChanged += x => { this.settings.Tonemapping = x; MarkAsModified(); };
  739. toneMappingGUI.OnConfirmed += ConfirmModify;
  740. }
  741. //// White balance settings
  742. whiteBalanceFoldout.AcceptsKeyFocus = false;
  743. whiteBalanceFoldout.OnToggled += x =>
  744. {
  745. properties.SetBool("whiteBalance_Expanded", x);
  746. ToggleFoldoutFields();
  747. };
  748. layout.AddElement(whiteBalanceFoldout);
  749. whiteBalanceLayout = layout.AddLayoutX();
  750. {
  751. whiteBalanceLayout.AddSpace(10);
  752. GUILayoutY contentsLayout = whiteBalanceLayout.AddLayoutY();
  753. whiteBalanceGUI = new WhiteBalanceSettingsGUI(settings.WhiteBalance, contentsLayout);
  754. whiteBalanceGUI.OnChanged += x => { this.settings.WhiteBalance = x; MarkAsModified(); };
  755. whiteBalanceGUI.OnConfirmed += ConfirmModify;
  756. }
  757. //// Color grading settings
  758. colorGradingFoldout.AcceptsKeyFocus = false;
  759. colorGradingFoldout.OnToggled += x =>
  760. {
  761. properties.SetBool("colorGrading_Expanded", x);
  762. ToggleFoldoutFields();
  763. };
  764. layout.AddElement(colorGradingFoldout);
  765. colorGradingLayout = layout.AddLayoutX();
  766. {
  767. colorGradingLayout.AddSpace(10);
  768. GUILayoutY contentsLayout = colorGradingLayout.AddLayoutY();
  769. colorGradingGUI = new ColorGradingSettingsGUI(settings.ColorGrading, contentsLayout);
  770. colorGradingGUI.OnChanged += x => { this.settings.ColorGrading = x; MarkAsModified(); };
  771. colorGradingGUI.OnConfirmed += ConfirmModify;
  772. }
  773. // Gamma
  774. gammaField.OnChanged += x => { this.settings.Gamma = x; MarkAsModified(); ConfirmModify(); };
  775. layout.AddElement(gammaField);
  776. // Exposure scale
  777. exposureScaleField.OnChanged += x => { this.settings.ExposureScale = x; MarkAsModified(); ConfirmModify(); };
  778. layout.AddElement(exposureScaleField);
  779. //// Depth of field settings
  780. depthOfFieldFoldout.AcceptsKeyFocus = false;
  781. depthOfFieldFoldout.OnToggled += x =>
  782. {
  783. properties.SetBool("depthOfField_Expanded", x);
  784. ToggleFoldoutFields();
  785. };
  786. layout.AddElement(depthOfFieldFoldout);
  787. depthOfFieldLayout = layout.AddLayoutX();
  788. {
  789. depthOfFieldLayout.AddSpace(10);
  790. GUILayoutY contentsLayout = depthOfFieldLayout.AddLayoutY();
  791. depthOfFieldGUI = new DepthOfFieldSettingsGUI(settings.DepthOfField, contentsLayout);
  792. depthOfFieldGUI.OnChanged += x => { this.settings.DepthOfField = x; MarkAsModified(); };
  793. depthOfFieldGUI.OnConfirmed += ConfirmModify;
  794. }
  795. //// Ambient occlusion settings
  796. ambientOcclusionFoldout.AcceptsKeyFocus = false;
  797. ambientOcclusionFoldout.OnToggled += x =>
  798. {
  799. properties.SetBool("ambientOcclusion_Expanded", x);
  800. ToggleFoldoutFields();
  801. };
  802. layout.AddElement(ambientOcclusionFoldout);
  803. ambientOcclusionLayout = layout.AddLayoutX();
  804. {
  805. ambientOcclusionLayout.AddSpace(10);
  806. GUILayoutY contentsLayout = ambientOcclusionLayout.AddLayoutY();
  807. ambientOcclusionGUI = new AmbientOcclusionSettingsGUI(settings.AmbientOcclusion, contentsLayout);
  808. ambientOcclusionGUI.OnChanged += x => { this.settings.AmbientOcclusion = x; MarkAsModified(); };
  809. ambientOcclusionGUI.OnConfirmed += ConfirmModify;
  810. }
  811. //// Screen space reflections settings
  812. screenSpaceReflectionsFoldout.AcceptsKeyFocus = false;
  813. screenSpaceReflectionsFoldout.OnToggled += x =>
  814. {
  815. properties.SetBool("screenSpaceReflections_Expanded", x);
  816. ToggleFoldoutFields();
  817. };
  818. layout.AddElement(screenSpaceReflectionsFoldout);
  819. screenSpaceReflectionsLayout = layout.AddLayoutX();
  820. {
  821. screenSpaceReflectionsLayout.AddSpace(10);
  822. GUILayoutY contentsLayout = screenSpaceReflectionsLayout.AddLayoutY();
  823. screenSpaceReflectionsGUI = new ScreenSpaceReflectionsSettingsGUI(settings.ScreenSpaceReflections, contentsLayout);
  824. screenSpaceReflectionsGUI.OnChanged += x => { this.settings.ScreenSpaceReflections = x; MarkAsModified(); };
  825. screenSpaceReflectionsGUI.OnConfirmed += ConfirmModify;
  826. }
  827. // FXAA
  828. enableFXAAField.OnChanged += x => { this.settings.EnableFXAA = x; MarkAsModified(); ConfirmModify(); };
  829. layout.AddElement(enableFXAAField);
  830. ToggleFoldoutFields();
  831. }
  832. /// <summary>
  833. /// Marks the contents of the inspector as modified.
  834. /// </summary>
  835. private void MarkAsModified()
  836. {
  837. if (OnChanged != null)
  838. OnChanged(settings);
  839. }
  840. /// <summary>
  841. /// Confirms any queued modifications.
  842. /// </summary>
  843. private void ConfirmModify()
  844. {
  845. if (OnConfirmed != null)
  846. OnConfirmed();
  847. }
  848. /// <summary>
  849. /// Hides or shows settings property GUI elements depending on set values.
  850. /// </summary>
  851. private void ToggleFoldoutFields()
  852. {
  853. autoExposureLayout.Active = properties.GetBool("autoExposure_Expanded");
  854. toneMappingLayout.Active = properties.GetBool("toneMapping_Expanded");
  855. whiteBalanceLayout.Active = properties.GetBool("whiteBalance_Expanded");
  856. colorGradingLayout.Active = properties.GetBool("colorGrading_Expanded");
  857. depthOfFieldLayout.Active = properties.GetBool("depthOfField_Expanded");
  858. ambientOcclusionLayout.Active = properties.GetBool("ambientOcclusion_Expanded");
  859. screenSpaceReflectionsLayout.Active = properties.GetBool("screenSpaceReflections_Expanded");
  860. shadowsLayout.Active = properties.GetBool("shadows_Expanded");
  861. }
  862. }
  863. /** @} */
  864. }