Bez popisu
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

DebugDisplaySettingsMaterial.cs 21KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470
  1. using System.Collections.Generic;
  2. using UnityEngine;
  3. using NameAndTooltip = UnityEngine.Rendering.DebugUI.Widget.NameAndTooltip;
  4. namespace UnityEngine.Rendering.Universal
  5. {
  6. /// <summary>
  7. /// Material-related Rendering Debugger settings.
  8. /// </summary>
  9. public class DebugDisplaySettingsMaterial : IDebugDisplaySettingsData
  10. {
  11. #region Material validation
  12. /// <summary>
  13. /// Builtin presets for debug albedo validation.
  14. /// </summary>
  15. public enum AlbedoDebugValidationPreset
  16. {
  17. /// <summary> Use this for default luminance. </summary>
  18. DefaultLuminance,
  19. /// <summary> Use this for black acrylic paint. </summary>
  20. BlackAcrylicPaint,
  21. /// <summary> Use this for dark soil. </summary>
  22. DarkSoil,
  23. /// <summary> Use this for worn asphalt. </summary>
  24. WornAsphalt,
  25. /// <summary> Use this for dry clay soil. </summary>
  26. DryClaySoil,
  27. /// <summary> Use this for green grass. </summary>
  28. GreenGrass,
  29. /// <summary> Use this for old concrete. </summary>
  30. OldConcrete,
  31. /// <summary> Use this for red clay tile. </summary>
  32. RedClayTile,
  33. /// <summary> Use this for dry sand. </summary>
  34. DrySand,
  35. /// <summary> Use this for new concrete. </summary>
  36. NewConcrete,
  37. /// <summary> Use this for white acrylic paint. </summary>
  38. WhiteAcrylicPaint,
  39. /// <summary> Use this for fresh snow. </summary>
  40. FreshSnow,
  41. /// <summary> Use this for blue sky. </summary>
  42. BlueSky,
  43. /// <summary> Use this for foliage. </summary>
  44. Foliage,
  45. /// <summary> Use this for custom. </summary>
  46. Custom
  47. }
  48. struct AlbedoDebugValidationPresetData
  49. {
  50. public string name;
  51. public Color color;
  52. public float minLuminance;
  53. public float maxLuminance;
  54. }
  55. AlbedoDebugValidationPresetData[] m_AlbedoDebugValidationPresetData =
  56. {
  57. new AlbedoDebugValidationPresetData()
  58. {
  59. name = "Default Luminance",
  60. color = new Color(127f / 255f, 127f / 255f, 127f / 255f),
  61. minLuminance = 0.01f,
  62. maxLuminance = 0.90f
  63. },
  64. // colors taken from http://www.babelcolor.com/index_htm_files/ColorChecker_RGB_and_spectra.xls
  65. new AlbedoDebugValidationPresetData()
  66. {
  67. name = "Black Acrylic Paint",
  68. color = new Color(56f / 255f, 56f / 255f, 56f / 255f),
  69. minLuminance = 0.03f,
  70. maxLuminance = 0.07f
  71. },
  72. new AlbedoDebugValidationPresetData()
  73. {
  74. name = "Dark Soil",
  75. color = new Color(85f / 255f, 61f / 255f, 49f / 255f),
  76. minLuminance = 0.05f,
  77. maxLuminance = 0.14f
  78. },
  79. new AlbedoDebugValidationPresetData()
  80. {
  81. name = "Worn Asphalt",
  82. color = new Color(91f / 255f, 91f / 255f, 91f / 255f),
  83. minLuminance = 0.10f,
  84. maxLuminance = 0.15f
  85. },
  86. new AlbedoDebugValidationPresetData()
  87. {
  88. name = "Dry Clay Soil",
  89. color = new Color(137f / 255f, 120f / 255f, 102f / 255f),
  90. minLuminance = 0.15f,
  91. maxLuminance = 0.35f
  92. },
  93. new AlbedoDebugValidationPresetData()
  94. {
  95. name = "Green Grass",
  96. color = new Color(123f / 255f, 131f / 255f, 74f / 255f),
  97. minLuminance = 0.16f,
  98. maxLuminance = 0.26f
  99. },
  100. new AlbedoDebugValidationPresetData()
  101. {
  102. name = "Old Concrete",
  103. color = new Color(135f / 255f, 136f / 255f, 131f / 255f),
  104. minLuminance = 0.17f,
  105. maxLuminance = 0.30f
  106. },
  107. new AlbedoDebugValidationPresetData()
  108. {
  109. name = "Red Clay Tile",
  110. color = new Color(197f / 255f, 125f / 255f, 100f / 255f),
  111. minLuminance = 0.23f,
  112. maxLuminance = 0.33f
  113. },
  114. new AlbedoDebugValidationPresetData()
  115. {
  116. name = "Dry Sand",
  117. color = new Color(177f / 255f, 167f / 255f, 132f / 255f),
  118. minLuminance = 0.20f,
  119. maxLuminance = 0.45f
  120. },
  121. new AlbedoDebugValidationPresetData()
  122. {
  123. name = "New Concrete",
  124. color = new Color(185f / 255f, 182f / 255f, 175f / 255f),
  125. minLuminance = 0.32f,
  126. maxLuminance = 0.55f
  127. },
  128. new AlbedoDebugValidationPresetData()
  129. {
  130. name = "White Acrylic Paint",
  131. color = new Color(227f / 255f, 227f / 255f, 227f / 255f),
  132. minLuminance = 0.75f,
  133. maxLuminance = 0.85f
  134. },
  135. new AlbedoDebugValidationPresetData()
  136. {
  137. name = "Fresh Snow",
  138. color = new Color(243f / 255f, 243f / 255f, 243f / 255f),
  139. minLuminance = 0.85f,
  140. maxLuminance = 0.95f
  141. },
  142. new AlbedoDebugValidationPresetData()
  143. {
  144. name = "Blue Sky",
  145. color = new Color(93f / 255f, 123f / 255f, 157f / 255f),
  146. minLuminance = new Color(93f / 255f, 123f / 255f, 157f / 255f).linear.maxColorComponent - 0.05f,
  147. maxLuminance = new Color(93f / 255f, 123f / 255f, 157f / 255f).linear.maxColorComponent + 0.05f
  148. },
  149. new AlbedoDebugValidationPresetData()
  150. {
  151. name = "Foliage",
  152. color = new Color(91f / 255f, 108f / 255f, 65f / 255f),
  153. minLuminance = new Color(91f / 255f, 108f / 255f, 65f / 255f).linear.maxColorComponent - 0.05f,
  154. maxLuminance = new Color(91f / 255f, 108f / 255f, 65f / 255f).linear.maxColorComponent + 0.05f
  155. },
  156. new AlbedoDebugValidationPresetData()
  157. {
  158. name = "Custom",
  159. color = new Color(127f / 255f, 127f / 255f, 127f / 255f),
  160. minLuminance = 0.01f,
  161. maxLuminance = 0.90f
  162. },
  163. };
  164. AlbedoDebugValidationPreset m_AlbedoValidationPreset;
  165. /// <summary>
  166. /// Current albedo debug validation preset.
  167. /// </summary>
  168. public AlbedoDebugValidationPreset albedoValidationPreset
  169. {
  170. get => m_AlbedoValidationPreset;
  171. set
  172. {
  173. m_AlbedoValidationPreset = value;
  174. AlbedoDebugValidationPresetData presetData = m_AlbedoDebugValidationPresetData[(int)value];
  175. albedoMinLuminance = presetData.minLuminance;
  176. albedoMaxLuminance = presetData.maxLuminance;
  177. albedoCompareColor = presetData.color;
  178. }
  179. }
  180. /// <summary>
  181. /// Current minimum luminance threshold value for albedo validation.
  182. /// Any albedo luminance values below this value will be considered invalid and will appear red on screen.
  183. /// </summary>
  184. public float albedoMinLuminance { get; set; } = 0.01f;
  185. /// <summary>
  186. /// Current maximum luminance threshold value for albedo validation.
  187. /// Any albedo luminance values above this value will be considered invalid and will appear blue on screen.
  188. /// </summary>
  189. public float albedoMaxLuminance { get; set; } = 0.90f;
  190. float m_AlbedoHueTolerance = 0.104f;
  191. /// <summary>
  192. /// Current hue tolerance value for albedo validation.
  193. /// </summary>
  194. public float albedoHueTolerance
  195. {
  196. get => m_AlbedoValidationPreset == AlbedoDebugValidationPreset.DefaultLuminance ? 1.0f : m_AlbedoHueTolerance;
  197. set => m_AlbedoHueTolerance = value;
  198. }
  199. float m_AlbedoSaturationTolerance = 0.214f;
  200. /// <summary>
  201. /// Current saturation tolerance value for albedo validation.
  202. /// </summary>
  203. public float albedoSaturationTolerance
  204. {
  205. get => m_AlbedoValidationPreset == AlbedoDebugValidationPreset.DefaultLuminance ? 1.0f : m_AlbedoSaturationTolerance;
  206. set => m_AlbedoSaturationTolerance = value;
  207. }
  208. /// <summary>
  209. /// Current target color value for albedo validation.
  210. /// </summary>
  211. public Color albedoCompareColor { get; set; } = new Color(127f / 255f, 127f / 255f, 127f / 255f, 255f / 255f);
  212. /// <summary>
  213. /// Current minimum threshold value for metallic validation.
  214. /// Any metallic values below this value will be considered invalid and will appear red on screen.
  215. /// </summary>
  216. public float metallicMinValue { get; set; } = 0.0f;
  217. /// <summary>
  218. /// Current maximum threshold value for metallic validation.
  219. /// Any metallic values above this value will be considered invalid and will appear blue on screen.
  220. /// </summary>
  221. public float metallicMaxValue { get; set; } = 0.9f;
  222. /// <summary>
  223. /// Current material validation mode.
  224. /// </summary>
  225. public DebugMaterialValidationMode materialValidationMode { get; set; }
  226. #endregion
  227. /// <summary>
  228. /// Current debug material mode.
  229. /// </summary>
  230. public DebugMaterialMode materialDebugMode { get; set; }
  231. /// <summary>
  232. /// Current debug vertex attribute mode.
  233. /// </summary>
  234. public DebugVertexAttributeMode vertexAttributeDebugMode { get; set; }
  235. static class Strings
  236. {
  237. public const string AlbedoSettingsContainerName = "Albedo Settings";
  238. public const string MetallicSettingsContainerName = "Metallic Settings";
  239. public static readonly NameAndTooltip MaterialOverride = new() { name = "Material Override", tooltip = "Use the drop-down to select a Material property to visualize on every GameObject on screen." };
  240. public static readonly NameAndTooltip VertexAttribute = new() { name = "Vertex Attribute", tooltip = "Use the drop-down to select a 3D GameObject attribute, like Texture Coordinates or Vertex Color, to visualize on screen." };
  241. public static readonly NameAndTooltip MaterialValidationMode = new() { name = "Material Validation Mode", tooltip = "Debug and validate material properties." };
  242. public static readonly NameAndTooltip ValidationPreset = new() { name = "Validation Preset", tooltip = "Validate using a list of preset surfaces and inputs based on real-world surfaces." };
  243. public static readonly NameAndTooltip AlbedoCustomColor = new() { name = "Target Color", tooltip = "Custom target color for albedo validation." };
  244. public static readonly NameAndTooltip AlbedoMinLuminance = new() { name = "Min Luminance", tooltip = "Any values set below this field are invalid and appear red on screen." };
  245. public static readonly NameAndTooltip AlbedoMaxLuminance = new() { name = "Max Luminance", tooltip = "Any values set above this field are invalid and appear blue on screen." };
  246. public static readonly NameAndTooltip AlbedoHueTolerance = new() { name = "Hue Tolerance", tooltip = "Validate a material based on a specific hue." };
  247. public static readonly NameAndTooltip AlbedoSaturationTolerance = new() { name = "Saturation Tolerance", tooltip = "Validate a material based on a specific Saturation." };
  248. public static readonly NameAndTooltip MetallicMinValue = new() { name = "Min Value", tooltip = "Any values set below this field are invalid and appear red on screen." };
  249. public static readonly NameAndTooltip MetallicMaxValue = new() { name = "Max Value", tooltip = "Any values set above this field are invalid and appear blue on screen." };
  250. }
  251. internal static class WidgetFactory
  252. {
  253. internal static DebugUI.Widget CreateMaterialOverride(SettingsPanel panel) => new DebugUI.EnumField
  254. {
  255. nameAndTooltip = Strings.MaterialOverride,
  256. autoEnum = typeof(DebugMaterialMode),
  257. getter = () => (int)panel.data.materialDebugMode,
  258. setter = (value) => panel.data.materialDebugMode = (DebugMaterialMode)value,
  259. getIndex = () => (int)panel.data.materialDebugMode,
  260. setIndex = (value) => panel.data.materialDebugMode = (DebugMaterialMode)value
  261. };
  262. internal static DebugUI.Widget CreateVertexAttribute(SettingsPanel panel) => new DebugUI.EnumField
  263. {
  264. nameAndTooltip = Strings.VertexAttribute,
  265. autoEnum = typeof(DebugVertexAttributeMode),
  266. getter = () => (int)panel.data.vertexAttributeDebugMode,
  267. setter = (value) => panel.data.vertexAttributeDebugMode = (DebugVertexAttributeMode)value,
  268. getIndex = () => (int)panel.data.vertexAttributeDebugMode,
  269. setIndex = (value) => panel.data.vertexAttributeDebugMode = (DebugVertexAttributeMode)value
  270. };
  271. internal static DebugUI.Widget CreateMaterialValidationMode(SettingsPanel panel) => new DebugUI.EnumField
  272. {
  273. nameAndTooltip = Strings.MaterialValidationMode,
  274. autoEnum = typeof(DebugMaterialValidationMode),
  275. getter = () => (int)panel.data.materialValidationMode,
  276. setter = (value) => panel.data.materialValidationMode = (DebugMaterialValidationMode)value,
  277. getIndex = () => (int)panel.data.materialValidationMode,
  278. setIndex = (value) => panel.data.materialValidationMode = (DebugMaterialValidationMode)value,
  279. onValueChanged = (_, _) => DebugManager.instance.ReDrawOnScreenDebug()
  280. };
  281. internal static DebugUI.Widget CreateAlbedoPreset(SettingsPanel panel) => new DebugUI.EnumField
  282. {
  283. nameAndTooltip = Strings.ValidationPreset,
  284. autoEnum = typeof(AlbedoDebugValidationPreset),
  285. getter = () => (int)panel.data.albedoValidationPreset,
  286. setter = (value) => panel.data.albedoValidationPreset = (AlbedoDebugValidationPreset)value,
  287. getIndex = () => (int)panel.data.albedoValidationPreset,
  288. setIndex = (value) => panel.data.albedoValidationPreset = (AlbedoDebugValidationPreset)value,
  289. onValueChanged = (_, _) => DebugManager.instance.ReDrawOnScreenDebug()
  290. };
  291. internal static DebugUI.Widget CreateAlbedoCustomColor(SettingsPanel panel) => new DebugUI.ColorField()
  292. {
  293. nameAndTooltip = Strings.AlbedoCustomColor,
  294. getter = () => panel.data.albedoCompareColor,
  295. setter = (value) => panel.data.albedoCompareColor = value,
  296. isHiddenCallback = () => panel.data.albedoValidationPreset != AlbedoDebugValidationPreset.Custom
  297. };
  298. internal static DebugUI.Widget CreateAlbedoMinLuminance(SettingsPanel panel) => new DebugUI.FloatField
  299. {
  300. nameAndTooltip = Strings.AlbedoMinLuminance,
  301. getter = () => panel.data.albedoMinLuminance,
  302. setter = (value) => panel.data.albedoMinLuminance = value,
  303. incStep = 0.01f
  304. };
  305. internal static DebugUI.Widget CreateAlbedoMaxLuminance(SettingsPanel panel) => new DebugUI.FloatField
  306. {
  307. nameAndTooltip = Strings.AlbedoMaxLuminance,
  308. getter = () => panel.data.albedoMaxLuminance,
  309. setter = (value) => panel.data.albedoMaxLuminance = value,
  310. incStep = 0.01f
  311. };
  312. internal static DebugUI.Widget CreateAlbedoHueTolerance(SettingsPanel panel) => new DebugUI.FloatField
  313. {
  314. nameAndTooltip = Strings.AlbedoHueTolerance,
  315. getter = () => panel.data.albedoHueTolerance,
  316. setter = (value) => panel.data.albedoHueTolerance = value,
  317. incStep = 0.01f,
  318. isHiddenCallback = () => panel.data.albedoValidationPreset == AlbedoDebugValidationPreset.DefaultLuminance
  319. };
  320. internal static DebugUI.Widget CreateAlbedoSaturationTolerance(SettingsPanel panel) => new DebugUI.FloatField
  321. {
  322. nameAndTooltip = Strings.AlbedoSaturationTolerance,
  323. getter = () => panel.data.albedoSaturationTolerance,
  324. setter = (value) => panel.data.albedoSaturationTolerance = value,
  325. incStep = 0.01f,
  326. isHiddenCallback = () => panel.data.albedoValidationPreset == AlbedoDebugValidationPreset.DefaultLuminance
  327. };
  328. internal static DebugUI.Widget CreateMetallicMinValue(SettingsPanel panel) => new DebugUI.FloatField
  329. {
  330. nameAndTooltip = Strings.MetallicMinValue,
  331. getter = () => panel.data.metallicMinValue,
  332. setter = (value) => panel.data.metallicMinValue = value,
  333. incStep = 0.01f
  334. };
  335. internal static DebugUI.Widget CreateMetallicMaxValue(SettingsPanel panel) => new DebugUI.FloatField
  336. {
  337. nameAndTooltip = Strings.MetallicMaxValue,
  338. getter = () => panel.data.metallicMaxValue,
  339. setter = (value) => panel.data.metallicMaxValue = value,
  340. incStep = 0.01f
  341. };
  342. }
  343. [DisplayInfo(name = "Material", order = 2)]
  344. internal class SettingsPanel : DebugDisplaySettingsPanel<DebugDisplaySettingsMaterial>
  345. {
  346. public SettingsPanel(DebugDisplaySettingsMaterial data)
  347. : base(data)
  348. {
  349. AddWidget(new DebugUI.RuntimeDebugShadersMessageBox());
  350. AddWidget(new DebugUI.Foldout
  351. {
  352. displayName = "Material Filters",
  353. flags = DebugUI.Flags.FrequentlyUsed,
  354. isHeader = true,
  355. opened = true,
  356. children =
  357. {
  358. WidgetFactory.CreateMaterialOverride(this),
  359. WidgetFactory.CreateVertexAttribute(this)
  360. }
  361. });
  362. AddWidget(new DebugUI.Foldout
  363. {
  364. displayName = "Material Validation",
  365. isHeader = true,
  366. opened = true,
  367. children =
  368. {
  369. WidgetFactory.CreateMaterialValidationMode(this),
  370. new DebugUI.Container()
  371. {
  372. displayName = Strings.AlbedoSettingsContainerName,
  373. isHiddenCallback = () => data.materialValidationMode != DebugMaterialValidationMode.Albedo,
  374. children =
  375. {
  376. WidgetFactory.CreateAlbedoPreset(this),
  377. WidgetFactory.CreateAlbedoCustomColor(this),
  378. WidgetFactory.CreateAlbedoMinLuminance(this),
  379. WidgetFactory.CreateAlbedoMaxLuminance(this),
  380. WidgetFactory.CreateAlbedoHueTolerance(this),
  381. WidgetFactory.CreateAlbedoSaturationTolerance(this)
  382. }
  383. },
  384. new DebugUI.Container()
  385. {
  386. displayName = Strings.MetallicSettingsContainerName,
  387. isHiddenCallback = () => data.materialValidationMode != DebugMaterialValidationMode.Metallic,
  388. children =
  389. {
  390. WidgetFactory.CreateMetallicMinValue(this),
  391. WidgetFactory.CreateMetallicMaxValue(this)
  392. }
  393. }
  394. }
  395. });
  396. }
  397. }
  398. #region IDebugDisplaySettingsQuery
  399. /// <inheritdoc/>
  400. public bool AreAnySettingsActive =>
  401. (materialDebugMode != DebugMaterialMode.None) ||
  402. (vertexAttributeDebugMode != DebugVertexAttributeMode.None) ||
  403. (materialValidationMode != DebugMaterialValidationMode.None);
  404. /// <inheritdoc/>
  405. public bool IsPostProcessingAllowed => !AreAnySettingsActive;
  406. /// <inheritdoc/>
  407. public bool IsLightingActive => !AreAnySettingsActive;
  408. /// <inheritdoc/>
  409. IDebugDisplaySettingsPanelDisposable IDebugDisplaySettingsData.CreatePanel()
  410. {
  411. return new SettingsPanel(this);
  412. }
  413. #endregion
  414. }
  415. }