RenderSettingsInspector.cs 43 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007
  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.OnToggled += x =>
  690. {
  691. properties.SetBool("shadows_Expanded", x);
  692. ToggleFoldoutFields();
  693. };
  694. layout.AddElement(shadowsFoldout);
  695. shadowsLayout = layout.AddLayoutX();
  696. {
  697. shadowsLayout.AddSpace(10);
  698. GUILayoutY contentsLayout = shadowsLayout.AddLayoutY();
  699. shadowsGUI = new ShadowSettingsGUI(settings.ShadowSettings, contentsLayout);
  700. shadowsGUI.OnChanged += x => { this.settings.ShadowSettings = x; MarkAsModified(); };
  701. shadowsGUI.OnConfirmed += ConfirmModify;
  702. }
  703. // Auto exposure
  704. enableAutoExposureField.OnChanged += x => { this.settings.EnableAutoExposure = x; MarkAsModified(); ConfirmModify(); };
  705. layout.AddElement(enableAutoExposureField);
  706. autoExposureFoldout.OnToggled += x =>
  707. {
  708. properties.SetBool("autoExposure_Expanded", x);
  709. ToggleFoldoutFields();
  710. };
  711. layout.AddElement(autoExposureFoldout);
  712. autoExposureLayout = layout.AddLayoutX();
  713. {
  714. autoExposureLayout.AddSpace(10);
  715. GUILayoutY contentsLayout = autoExposureLayout.AddLayoutY();
  716. autoExposureGUI = new AutoExposureSettingsGUI(settings.AutoExposure, contentsLayout);
  717. autoExposureGUI.OnChanged += x => { this.settings.AutoExposure = x; MarkAsModified(); };
  718. autoExposureGUI.OnConfirmed += ConfirmModify;
  719. }
  720. // Tonemapping
  721. enableToneMappingField.OnChanged += x => { this.settings.EnableTonemapping = x; MarkAsModified(); ConfirmModify(); };
  722. layout.AddElement(enableToneMappingField);
  723. //// Tonemapping settings
  724. toneMappingFoldout.OnToggled += x =>
  725. {
  726. properties.SetBool("toneMapping_Expanded", x);
  727. ToggleFoldoutFields();
  728. };
  729. layout.AddElement(toneMappingFoldout);
  730. toneMappingLayout = layout.AddLayoutX();
  731. {
  732. toneMappingLayout.AddSpace(10);
  733. GUILayoutY contentsLayout = toneMappingLayout.AddLayoutY();
  734. toneMappingGUI = new TonemappingSettingsGUI(settings.Tonemapping, contentsLayout);
  735. toneMappingGUI.OnChanged += x => { this.settings.Tonemapping = x; MarkAsModified(); };
  736. toneMappingGUI.OnConfirmed += ConfirmModify;
  737. }
  738. //// White balance settings
  739. whiteBalanceFoldout.OnToggled += x =>
  740. {
  741. properties.SetBool("whiteBalance_Expanded", x);
  742. ToggleFoldoutFields();
  743. };
  744. layout.AddElement(whiteBalanceFoldout);
  745. whiteBalanceLayout = layout.AddLayoutX();
  746. {
  747. whiteBalanceLayout.AddSpace(10);
  748. GUILayoutY contentsLayout = whiteBalanceLayout.AddLayoutY();
  749. whiteBalanceGUI = new WhiteBalanceSettingsGUI(settings.WhiteBalance, contentsLayout);
  750. whiteBalanceGUI.OnChanged += x => { this.settings.WhiteBalance = x; MarkAsModified(); };
  751. whiteBalanceGUI.OnConfirmed += ConfirmModify;
  752. }
  753. //// Color grading settings
  754. colorGradingFoldout.OnToggled += x =>
  755. {
  756. properties.SetBool("colorGrading_Expanded", x);
  757. ToggleFoldoutFields();
  758. };
  759. layout.AddElement(colorGradingFoldout);
  760. colorGradingLayout = layout.AddLayoutX();
  761. {
  762. colorGradingLayout.AddSpace(10);
  763. GUILayoutY contentsLayout = colorGradingLayout.AddLayoutY();
  764. colorGradingGUI = new ColorGradingSettingsGUI(settings.ColorGrading, contentsLayout);
  765. colorGradingGUI.OnChanged += x => { this.settings.ColorGrading = x; MarkAsModified(); };
  766. colorGradingGUI.OnConfirmed += ConfirmModify;
  767. }
  768. // Gamma
  769. gammaField.OnChanged += x => { this.settings.Gamma = x; MarkAsModified(); ConfirmModify(); };
  770. layout.AddElement(gammaField);
  771. // Exposure scale
  772. exposureScaleField.OnChanged += x => { this.settings.ExposureScale = x; MarkAsModified(); ConfirmModify(); };
  773. layout.AddElement(exposureScaleField);
  774. //// Depth of field settings
  775. depthOfFieldFoldout.OnToggled += x =>
  776. {
  777. properties.SetBool("depthOfField_Expanded", x);
  778. ToggleFoldoutFields();
  779. };
  780. layout.AddElement(depthOfFieldFoldout);
  781. depthOfFieldLayout = layout.AddLayoutX();
  782. {
  783. depthOfFieldLayout.AddSpace(10);
  784. GUILayoutY contentsLayout = depthOfFieldLayout.AddLayoutY();
  785. depthOfFieldGUI = new DepthOfFieldSettingsGUI(settings.DepthOfField, contentsLayout);
  786. depthOfFieldGUI.OnChanged += x => { this.settings.DepthOfField = x; MarkAsModified(); };
  787. depthOfFieldGUI.OnConfirmed += ConfirmModify;
  788. }
  789. //// Ambient occlusion settings
  790. ambientOcclusionFoldout.OnToggled += x =>
  791. {
  792. properties.SetBool("ambientOcclusion_Expanded", x);
  793. ToggleFoldoutFields();
  794. };
  795. layout.AddElement(ambientOcclusionFoldout);
  796. ambientOcclusionLayout = layout.AddLayoutX();
  797. {
  798. ambientOcclusionLayout.AddSpace(10);
  799. GUILayoutY contentsLayout = ambientOcclusionLayout.AddLayoutY();
  800. ambientOcclusionGUI = new AmbientOcclusionSettingsGUI(settings.AmbientOcclusion, contentsLayout);
  801. ambientOcclusionGUI.OnChanged += x => { this.settings.AmbientOcclusion = x; MarkAsModified(); };
  802. ambientOcclusionGUI.OnConfirmed += ConfirmModify;
  803. }
  804. //// Screen space reflections settings
  805. screenSpaceReflectionsFoldout.OnToggled += x =>
  806. {
  807. properties.SetBool("screenSpaceReflections_Expanded", x);
  808. ToggleFoldoutFields();
  809. };
  810. layout.AddElement(screenSpaceReflectionsFoldout);
  811. screenSpaceReflectionsLayout = layout.AddLayoutX();
  812. {
  813. screenSpaceReflectionsLayout.AddSpace(10);
  814. GUILayoutY contentsLayout = screenSpaceReflectionsLayout.AddLayoutY();
  815. screenSpaceReflectionsGUI = new ScreenSpaceReflectionsSettingsGUI(settings.ScreenSpaceReflections, contentsLayout);
  816. screenSpaceReflectionsGUI.OnChanged += x => { this.settings.ScreenSpaceReflections = x; MarkAsModified(); };
  817. screenSpaceReflectionsGUI.OnConfirmed += ConfirmModify;
  818. }
  819. // FXAA
  820. enableFXAAField.OnChanged += x => { this.settings.EnableFXAA = x; MarkAsModified(); ConfirmModify(); };
  821. layout.AddElement(enableFXAAField);
  822. ToggleFoldoutFields();
  823. }
  824. /// <summary>
  825. /// Marks the contents of the inspector as modified.
  826. /// </summary>
  827. private void MarkAsModified()
  828. {
  829. if (OnChanged != null)
  830. OnChanged(settings);
  831. }
  832. /// <summary>
  833. /// Confirms any queued modifications.
  834. /// </summary>
  835. private void ConfirmModify()
  836. {
  837. if (OnConfirmed != null)
  838. OnConfirmed();
  839. }
  840. /// <summary>
  841. /// Hides or shows settings property GUI elements depending on set values.
  842. /// </summary>
  843. private void ToggleFoldoutFields()
  844. {
  845. autoExposureLayout.Active = properties.GetBool("autoExposure_Expanded");
  846. toneMappingLayout.Active = properties.GetBool("toneMapping_Expanded");
  847. whiteBalanceLayout.Active = properties.GetBool("whiteBalance_Expanded");
  848. colorGradingLayout.Active = properties.GetBool("colorGrading_Expanded");
  849. depthOfFieldLayout.Active = properties.GetBool("depthOfField_Expanded");
  850. ambientOcclusionLayout.Active = properties.GetBool("ambientOcclusion_Expanded");
  851. screenSpaceReflectionsLayout.Active = properties.GetBool("screenSpaceReflections_Expanded");
  852. shadowsLayout.Active = properties.GetBool("shadows_Expanded");
  853. }
  854. }
  855. /** @} */
  856. }