123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470 |
- using System.Collections.Generic;
- using UnityEngine;
- using NameAndTooltip = UnityEngine.Rendering.DebugUI.Widget.NameAndTooltip;
-
- namespace UnityEngine.Rendering.Universal
- {
- /// <summary>
- /// Material-related Rendering Debugger settings.
- /// </summary>
- public class DebugDisplaySettingsMaterial : IDebugDisplaySettingsData
- {
- #region Material validation
-
- /// <summary>
- /// Builtin presets for debug albedo validation.
- /// </summary>
- public enum AlbedoDebugValidationPreset
- {
- /// <summary> Use this for default luminance. </summary>
- DefaultLuminance,
-
- /// <summary> Use this for black acrylic paint. </summary>
- BlackAcrylicPaint,
-
- /// <summary> Use this for dark soil. </summary>
- DarkSoil,
-
- /// <summary> Use this for worn asphalt. </summary>
- WornAsphalt,
-
- /// <summary> Use this for dry clay soil. </summary>
- DryClaySoil,
-
- /// <summary> Use this for green grass. </summary>
- GreenGrass,
-
- /// <summary> Use this for old concrete. </summary>
- OldConcrete,
-
- /// <summary> Use this for red clay tile. </summary>
- RedClayTile,
-
- /// <summary> Use this for dry sand. </summary>
- DrySand,
-
- /// <summary> Use this for new concrete. </summary>
- NewConcrete,
-
- /// <summary> Use this for white acrylic paint. </summary>
- WhiteAcrylicPaint,
-
- /// <summary> Use this for fresh snow. </summary>
- FreshSnow,
-
- /// <summary> Use this for blue sky. </summary>
- BlueSky,
-
- /// <summary> Use this for foliage. </summary>
- Foliage,
-
- /// <summary> Use this for custom. </summary>
- Custom
- }
-
- struct AlbedoDebugValidationPresetData
- {
- public string name;
- public Color color;
- public float minLuminance;
- public float maxLuminance;
- }
-
- AlbedoDebugValidationPresetData[] m_AlbedoDebugValidationPresetData =
- {
- new AlbedoDebugValidationPresetData()
- {
- name = "Default Luminance",
- color = new Color(127f / 255f, 127f / 255f, 127f / 255f),
- minLuminance = 0.01f,
- maxLuminance = 0.90f
- },
- // colors taken from http://www.babelcolor.com/index_htm_files/ColorChecker_RGB_and_spectra.xls
- new AlbedoDebugValidationPresetData()
- {
- name = "Black Acrylic Paint",
- color = new Color(56f / 255f, 56f / 255f, 56f / 255f),
- minLuminance = 0.03f,
- maxLuminance = 0.07f
- },
- new AlbedoDebugValidationPresetData()
- {
- name = "Dark Soil",
- color = new Color(85f / 255f, 61f / 255f, 49f / 255f),
- minLuminance = 0.05f,
- maxLuminance = 0.14f
- },
-
- new AlbedoDebugValidationPresetData()
- {
- name = "Worn Asphalt",
- color = new Color(91f / 255f, 91f / 255f, 91f / 255f),
- minLuminance = 0.10f,
- maxLuminance = 0.15f
- },
- new AlbedoDebugValidationPresetData()
- {
- name = "Dry Clay Soil",
- color = new Color(137f / 255f, 120f / 255f, 102f / 255f),
- minLuminance = 0.15f,
- maxLuminance = 0.35f
- },
- new AlbedoDebugValidationPresetData()
- {
- name = "Green Grass",
- color = new Color(123f / 255f, 131f / 255f, 74f / 255f),
- minLuminance = 0.16f,
- maxLuminance = 0.26f
- },
- new AlbedoDebugValidationPresetData()
- {
- name = "Old Concrete",
- color = new Color(135f / 255f, 136f / 255f, 131f / 255f),
- minLuminance = 0.17f,
- maxLuminance = 0.30f
- },
- new AlbedoDebugValidationPresetData()
- {
- name = "Red Clay Tile",
- color = new Color(197f / 255f, 125f / 255f, 100f / 255f),
- minLuminance = 0.23f,
- maxLuminance = 0.33f
- },
- new AlbedoDebugValidationPresetData()
- {
- name = "Dry Sand",
- color = new Color(177f / 255f, 167f / 255f, 132f / 255f),
- minLuminance = 0.20f,
- maxLuminance = 0.45f
- },
- new AlbedoDebugValidationPresetData()
- {
- name = "New Concrete",
- color = new Color(185f / 255f, 182f / 255f, 175f / 255f),
- minLuminance = 0.32f,
- maxLuminance = 0.55f
- },
- new AlbedoDebugValidationPresetData()
- {
- name = "White Acrylic Paint",
- color = new Color(227f / 255f, 227f / 255f, 227f / 255f),
- minLuminance = 0.75f,
- maxLuminance = 0.85f
- },
- new AlbedoDebugValidationPresetData()
- {
- name = "Fresh Snow",
- color = new Color(243f / 255f, 243f / 255f, 243f / 255f),
- minLuminance = 0.85f,
- maxLuminance = 0.95f
- },
- new AlbedoDebugValidationPresetData()
- {
- name = "Blue Sky",
- color = new Color(93f / 255f, 123f / 255f, 157f / 255f),
- minLuminance = new Color(93f / 255f, 123f / 255f, 157f / 255f).linear.maxColorComponent - 0.05f,
- maxLuminance = new Color(93f / 255f, 123f / 255f, 157f / 255f).linear.maxColorComponent + 0.05f
- },
- new AlbedoDebugValidationPresetData()
- {
- name = "Foliage",
- color = new Color(91f / 255f, 108f / 255f, 65f / 255f),
- minLuminance = new Color(91f / 255f, 108f / 255f, 65f / 255f).linear.maxColorComponent - 0.05f,
- maxLuminance = new Color(91f / 255f, 108f / 255f, 65f / 255f).linear.maxColorComponent + 0.05f
- },
- new AlbedoDebugValidationPresetData()
- {
- name = "Custom",
- color = new Color(127f / 255f, 127f / 255f, 127f / 255f),
- minLuminance = 0.01f,
- maxLuminance = 0.90f
- },
- };
-
- AlbedoDebugValidationPreset m_AlbedoValidationPreset;
-
- /// <summary>
- /// Current albedo debug validation preset.
- /// </summary>
- public AlbedoDebugValidationPreset albedoValidationPreset
- {
- get => m_AlbedoValidationPreset;
- set
- {
- m_AlbedoValidationPreset = value;
- AlbedoDebugValidationPresetData presetData = m_AlbedoDebugValidationPresetData[(int)value];
- albedoMinLuminance = presetData.minLuminance;
- albedoMaxLuminance = presetData.maxLuminance;
- albedoCompareColor = presetData.color;
- }
- }
-
- /// <summary>
- /// Current minimum luminance threshold value for albedo validation.
- /// Any albedo luminance values below this value will be considered invalid and will appear red on screen.
- /// </summary>
- public float albedoMinLuminance { get; set; } = 0.01f;
-
- /// <summary>
- /// Current maximum luminance threshold value for albedo validation.
- /// Any albedo luminance values above this value will be considered invalid and will appear blue on screen.
- /// </summary>
- public float albedoMaxLuminance { get; set; } = 0.90f;
-
- float m_AlbedoHueTolerance = 0.104f;
-
- /// <summary>
- /// Current hue tolerance value for albedo validation.
- /// </summary>
- public float albedoHueTolerance
- {
- get => m_AlbedoValidationPreset == AlbedoDebugValidationPreset.DefaultLuminance ? 1.0f : m_AlbedoHueTolerance;
- set => m_AlbedoHueTolerance = value;
- }
-
- float m_AlbedoSaturationTolerance = 0.214f;
-
- /// <summary>
- /// Current saturation tolerance value for albedo validation.
- /// </summary>
- public float albedoSaturationTolerance
- {
- get => m_AlbedoValidationPreset == AlbedoDebugValidationPreset.DefaultLuminance ? 1.0f : m_AlbedoSaturationTolerance;
- set => m_AlbedoSaturationTolerance = value;
- }
-
- /// <summary>
- /// Current target color value for albedo validation.
- /// </summary>
- public Color albedoCompareColor { get; set; } = new Color(127f / 255f, 127f / 255f, 127f / 255f, 255f / 255f);
-
- /// <summary>
- /// Current minimum threshold value for metallic validation.
- /// Any metallic values below this value will be considered invalid and will appear red on screen.
- /// </summary>
- public float metallicMinValue { get; set; } = 0.0f;
-
- /// <summary>
- /// Current maximum threshold value for metallic validation.
- /// Any metallic values above this value will be considered invalid and will appear blue on screen.
- /// </summary>
- public float metallicMaxValue { get; set; } = 0.9f;
-
- /// <summary>
- /// Current material validation mode.
- /// </summary>
- public DebugMaterialValidationMode materialValidationMode { get; set; }
-
- #endregion
-
- /// <summary>
- /// Current debug material mode.
- /// </summary>
- public DebugMaterialMode materialDebugMode { get; set; }
-
- /// <summary>
- /// Current debug vertex attribute mode.
- /// </summary>
- public DebugVertexAttributeMode vertexAttributeDebugMode { get; set; }
-
- static class Strings
- {
- public const string AlbedoSettingsContainerName = "Albedo Settings";
- public const string MetallicSettingsContainerName = "Metallic Settings";
-
- 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." };
- 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." };
- public static readonly NameAndTooltip MaterialValidationMode = new() { name = "Material Validation Mode", tooltip = "Debug and validate material properties." };
- public static readonly NameAndTooltip ValidationPreset = new() { name = "Validation Preset", tooltip = "Validate using a list of preset surfaces and inputs based on real-world surfaces." };
- public static readonly NameAndTooltip AlbedoCustomColor = new() { name = "Target Color", tooltip = "Custom target color for albedo validation." };
- public static readonly NameAndTooltip AlbedoMinLuminance = new() { name = "Min Luminance", tooltip = "Any values set below this field are invalid and appear red on screen." };
- public static readonly NameAndTooltip AlbedoMaxLuminance = new() { name = "Max Luminance", tooltip = "Any values set above this field are invalid and appear blue on screen." };
- public static readonly NameAndTooltip AlbedoHueTolerance = new() { name = "Hue Tolerance", tooltip = "Validate a material based on a specific hue." };
- public static readonly NameAndTooltip AlbedoSaturationTolerance = new() { name = "Saturation Tolerance", tooltip = "Validate a material based on a specific Saturation." };
- public static readonly NameAndTooltip MetallicMinValue = new() { name = "Min Value", tooltip = "Any values set below this field are invalid and appear red on screen." };
- public static readonly NameAndTooltip MetallicMaxValue = new() { name = "Max Value", tooltip = "Any values set above this field are invalid and appear blue on screen." };
- }
-
- internal static class WidgetFactory
- {
- internal static DebugUI.Widget CreateMaterialOverride(SettingsPanel panel) => new DebugUI.EnumField
- {
- nameAndTooltip = Strings.MaterialOverride,
- autoEnum = typeof(DebugMaterialMode),
- getter = () => (int)panel.data.materialDebugMode,
- setter = (value) => panel.data.materialDebugMode = (DebugMaterialMode)value,
- getIndex = () => (int)panel.data.materialDebugMode,
- setIndex = (value) => panel.data.materialDebugMode = (DebugMaterialMode)value
- };
-
- internal static DebugUI.Widget CreateVertexAttribute(SettingsPanel panel) => new DebugUI.EnumField
- {
- nameAndTooltip = Strings.VertexAttribute,
- autoEnum = typeof(DebugVertexAttributeMode),
- getter = () => (int)panel.data.vertexAttributeDebugMode,
- setter = (value) => panel.data.vertexAttributeDebugMode = (DebugVertexAttributeMode)value,
- getIndex = () => (int)panel.data.vertexAttributeDebugMode,
- setIndex = (value) => panel.data.vertexAttributeDebugMode = (DebugVertexAttributeMode)value
- };
-
- internal static DebugUI.Widget CreateMaterialValidationMode(SettingsPanel panel) => new DebugUI.EnumField
- {
- nameAndTooltip = Strings.MaterialValidationMode,
- autoEnum = typeof(DebugMaterialValidationMode),
- getter = () => (int)panel.data.materialValidationMode,
- setter = (value) => panel.data.materialValidationMode = (DebugMaterialValidationMode)value,
- getIndex = () => (int)panel.data.materialValidationMode,
- setIndex = (value) => panel.data.materialValidationMode = (DebugMaterialValidationMode)value,
- onValueChanged = (_, _) => DebugManager.instance.ReDrawOnScreenDebug()
- };
-
- internal static DebugUI.Widget CreateAlbedoPreset(SettingsPanel panel) => new DebugUI.EnumField
- {
- nameAndTooltip = Strings.ValidationPreset,
- autoEnum = typeof(AlbedoDebugValidationPreset),
- getter = () => (int)panel.data.albedoValidationPreset,
- setter = (value) => panel.data.albedoValidationPreset = (AlbedoDebugValidationPreset)value,
- getIndex = () => (int)panel.data.albedoValidationPreset,
- setIndex = (value) => panel.data.albedoValidationPreset = (AlbedoDebugValidationPreset)value,
- onValueChanged = (_, _) => DebugManager.instance.ReDrawOnScreenDebug()
- };
-
- internal static DebugUI.Widget CreateAlbedoCustomColor(SettingsPanel panel) => new DebugUI.ColorField()
- {
- nameAndTooltip = Strings.AlbedoCustomColor,
- getter = () => panel.data.albedoCompareColor,
- setter = (value) => panel.data.albedoCompareColor = value,
- isHiddenCallback = () => panel.data.albedoValidationPreset != AlbedoDebugValidationPreset.Custom
- };
-
- internal static DebugUI.Widget CreateAlbedoMinLuminance(SettingsPanel panel) => new DebugUI.FloatField
- {
- nameAndTooltip = Strings.AlbedoMinLuminance,
- getter = () => panel.data.albedoMinLuminance,
- setter = (value) => panel.data.albedoMinLuminance = value,
- incStep = 0.01f
- };
-
- internal static DebugUI.Widget CreateAlbedoMaxLuminance(SettingsPanel panel) => new DebugUI.FloatField
- {
- nameAndTooltip = Strings.AlbedoMaxLuminance,
- getter = () => panel.data.albedoMaxLuminance,
- setter = (value) => panel.data.albedoMaxLuminance = value,
- incStep = 0.01f
- };
-
- internal static DebugUI.Widget CreateAlbedoHueTolerance(SettingsPanel panel) => new DebugUI.FloatField
- {
- nameAndTooltip = Strings.AlbedoHueTolerance,
- getter = () => panel.data.albedoHueTolerance,
- setter = (value) => panel.data.albedoHueTolerance = value,
- incStep = 0.01f,
- isHiddenCallback = () => panel.data.albedoValidationPreset == AlbedoDebugValidationPreset.DefaultLuminance
- };
-
- internal static DebugUI.Widget CreateAlbedoSaturationTolerance(SettingsPanel panel) => new DebugUI.FloatField
- {
- nameAndTooltip = Strings.AlbedoSaturationTolerance,
- getter = () => panel.data.albedoSaturationTolerance,
- setter = (value) => panel.data.albedoSaturationTolerance = value,
- incStep = 0.01f,
- isHiddenCallback = () => panel.data.albedoValidationPreset == AlbedoDebugValidationPreset.DefaultLuminance
- };
-
- internal static DebugUI.Widget CreateMetallicMinValue(SettingsPanel panel) => new DebugUI.FloatField
- {
- nameAndTooltip = Strings.MetallicMinValue,
- getter = () => panel.data.metallicMinValue,
- setter = (value) => panel.data.metallicMinValue = value,
- incStep = 0.01f
- };
-
- internal static DebugUI.Widget CreateMetallicMaxValue(SettingsPanel panel) => new DebugUI.FloatField
- {
- nameAndTooltip = Strings.MetallicMaxValue,
- getter = () => panel.data.metallicMaxValue,
- setter = (value) => panel.data.metallicMaxValue = value,
- incStep = 0.01f
- };
- }
-
- [DisplayInfo(name = "Material", order = 2)]
- internal class SettingsPanel : DebugDisplaySettingsPanel<DebugDisplaySettingsMaterial>
- {
- public SettingsPanel(DebugDisplaySettingsMaterial data)
- : base(data)
- {
- AddWidget(new DebugUI.RuntimeDebugShadersMessageBox());
-
- AddWidget(new DebugUI.Foldout
- {
- displayName = "Material Filters",
- flags = DebugUI.Flags.FrequentlyUsed,
- isHeader = true,
- opened = true,
- children =
- {
- WidgetFactory.CreateMaterialOverride(this),
- WidgetFactory.CreateVertexAttribute(this)
- }
- });
- AddWidget(new DebugUI.Foldout
- {
- displayName = "Material Validation",
- isHeader = true,
- opened = true,
- children =
- {
- WidgetFactory.CreateMaterialValidationMode(this),
- new DebugUI.Container()
- {
- displayName = Strings.AlbedoSettingsContainerName,
- isHiddenCallback = () => data.materialValidationMode != DebugMaterialValidationMode.Albedo,
- children =
- {
- WidgetFactory.CreateAlbedoPreset(this),
- WidgetFactory.CreateAlbedoCustomColor(this),
- WidgetFactory.CreateAlbedoMinLuminance(this),
- WidgetFactory.CreateAlbedoMaxLuminance(this),
- WidgetFactory.CreateAlbedoHueTolerance(this),
- WidgetFactory.CreateAlbedoSaturationTolerance(this)
- }
- },
- new DebugUI.Container()
- {
- displayName = Strings.MetallicSettingsContainerName,
- isHiddenCallback = () => data.materialValidationMode != DebugMaterialValidationMode.Metallic,
- children =
- {
- WidgetFactory.CreateMetallicMinValue(this),
- WidgetFactory.CreateMetallicMaxValue(this)
- }
- }
- }
- });
- }
- }
-
- #region IDebugDisplaySettingsQuery
-
- /// <inheritdoc/>
- public bool AreAnySettingsActive =>
- (materialDebugMode != DebugMaterialMode.None) ||
- (vertexAttributeDebugMode != DebugVertexAttributeMode.None) ||
- (materialValidationMode != DebugMaterialValidationMode.None);
-
- /// <inheritdoc/>
- public bool IsPostProcessingAllowed => !AreAnySettingsActive;
-
- /// <inheritdoc/>
- public bool IsLightingActive => !AreAnySettingsActive;
-
- /// <inheritdoc/>
- IDebugDisplaySettingsPanelDisposable IDebugDisplaySettingsData.CreatePanel()
- {
- return new SettingsPanel(this);
- }
-
- #endregion
- }
- }
|