initial commit
This commit is contained in:
parent
6715289efe
commit
788c3389af
37645 changed files with 2526849 additions and 80 deletions
|
|
@ -0,0 +1,125 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
namespace UnityEngine.Rendering.Universal
|
||||
{
|
||||
public class DebugDisplaySettings : IDebugDisplaySettingsQuery
|
||||
{
|
||||
private readonly HashSet<IDebugDisplaySettingsData> m_Settings = new HashSet<IDebugDisplaySettingsData>();
|
||||
|
||||
private static readonly Lazy<DebugDisplaySettings> s_Instance = new Lazy<DebugDisplaySettings>(() => new DebugDisplaySettings());
|
||||
|
||||
/// <summary>
|
||||
/// The singleton instance that contains the current settings of URP Rendering Debugger.
|
||||
/// </summary>
|
||||
public static DebugDisplaySettings Instance => s_Instance.Value;
|
||||
|
||||
DebugDisplaySettingsCommon CommonSettings { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Material-related Rendering Debugger settings.
|
||||
/// </summary>
|
||||
internal DebugDisplaySettingsMaterial MaterialSettings { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Rendering-related Rendering Debugger settings.
|
||||
/// </summary>
|
||||
internal DebugDisplaySettingsRendering RenderingSettings { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Lighting-related Rendering Debugger settings.
|
||||
/// </summary>
|
||||
internal DebugDisplaySettingsLighting LightingSettings { get; private set; }
|
||||
|
||||
#region IDebugDisplaySettingsQuery
|
||||
|
||||
/// <summary>
|
||||
/// Returns true if any of the debug settings are currently active.
|
||||
/// </summary>
|
||||
public bool AreAnySettingsActive => MaterialSettings.AreAnySettingsActive ||
|
||||
LightingSettings.AreAnySettingsActive ||
|
||||
RenderingSettings.AreAnySettingsActive;
|
||||
|
||||
public bool TryGetScreenClearColor(ref Color color)
|
||||
{
|
||||
return MaterialSettings.TryGetScreenClearColor(ref color) ||
|
||||
RenderingSettings.TryGetScreenClearColor(ref color) ||
|
||||
LightingSettings.TryGetScreenClearColor(ref color);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns true if lighting is active for current state of debug settings.
|
||||
/// </summary>
|
||||
public bool IsLightingActive => MaterialSettings.IsLightingActive &&
|
||||
RenderingSettings.IsLightingActive &&
|
||||
LightingSettings.IsLightingActive;
|
||||
|
||||
/// <summary>
|
||||
/// Returns true if the current state of debug settings allows post-processing.
|
||||
/// </summary>
|
||||
public bool IsPostProcessingAllowed
|
||||
{
|
||||
get
|
||||
{
|
||||
DebugPostProcessingMode debugPostProcessingMode = RenderingSettings.debugPostProcessingMode;
|
||||
|
||||
switch (debugPostProcessingMode)
|
||||
{
|
||||
case DebugPostProcessingMode.Disabled:
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
case DebugPostProcessingMode.Auto:
|
||||
{
|
||||
// Only enable post-processing if we aren't using certain debug-views...
|
||||
return MaterialSettings.IsPostProcessingAllowed &&
|
||||
RenderingSettings.IsPostProcessingAllowed &&
|
||||
LightingSettings.IsPostProcessingAllowed;
|
||||
}
|
||||
|
||||
case DebugPostProcessingMode.Enabled:
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
default:
|
||||
{
|
||||
throw new ArgumentOutOfRangeException(nameof(debugPostProcessingMode), $"Invalid post-processing state {debugPostProcessingMode}");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
private TData Add<TData>(TData newData) where TData : IDebugDisplaySettingsData
|
||||
{
|
||||
m_Settings.Add(newData);
|
||||
return newData;
|
||||
}
|
||||
|
||||
DebugDisplaySettings()
|
||||
{
|
||||
Reset();
|
||||
}
|
||||
|
||||
internal void Reset()
|
||||
{
|
||||
m_Settings.Clear();
|
||||
|
||||
CommonSettings = Add(new DebugDisplaySettingsCommon());
|
||||
MaterialSettings = Add(new DebugDisplaySettingsMaterial());
|
||||
LightingSettings = Add(new DebugDisplaySettingsLighting());
|
||||
RenderingSettings = Add(new DebugDisplaySettingsRendering());
|
||||
}
|
||||
|
||||
internal void ForEach(Action<IDebugDisplaySettingsData> onExecute)
|
||||
{
|
||||
foreach (IDebugDisplaySettingsData setting in m_Settings)
|
||||
{
|
||||
onExecute(setting);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 9f6344f2dc8b9435db33604d430c83d3
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
|
|
@ -0,0 +1,119 @@
|
|||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
namespace UnityEngine.Rendering.Universal
|
||||
{
|
||||
class DebugDisplaySettingsCommon : IDebugDisplaySettingsData
|
||||
{
|
||||
internal static class WidgetFactory
|
||||
{
|
||||
internal static DebugUI.Widget CreateMissingDebugShadersWarning() => new DebugUI.MessageBox
|
||||
{
|
||||
displayName = "Warning: the debug shader variants are missing. Ensure that the \"Strip Debug Variants\" option is disabled in URP Global Settings.",
|
||||
style = DebugUI.MessageBox.Style.Warning,
|
||||
isHiddenCallback = () =>
|
||||
{
|
||||
#if UNITY_EDITOR
|
||||
return true;
|
||||
#else
|
||||
if (UniversalRenderPipelineGlobalSettings.instance != null)
|
||||
return !UniversalRenderPipelineGlobalSettings.instance.stripDebugVariants;
|
||||
return true;
|
||||
#endif
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
private class SettingsPanel : DebugDisplaySettingsPanel
|
||||
{
|
||||
public override string PanelName => "Frequently Used";
|
||||
|
||||
const string k_GoToSectionString = "Go to Section...";
|
||||
|
||||
public SettingsPanel()
|
||||
{
|
||||
AddWidget(DebugDisplaySettingsCommon.WidgetFactory.CreateMissingDebugShadersWarning());
|
||||
|
||||
var materialSettingsData = DebugDisplaySettings.Instance.MaterialSettings;
|
||||
AddWidget(new DebugUI.Foldout
|
||||
{
|
||||
displayName = "Material Filters",
|
||||
isHeader = true,
|
||||
opened = true,
|
||||
children =
|
||||
{
|
||||
DebugDisplaySettingsMaterial.WidgetFactory.CreateMaterialOverride(materialSettingsData)
|
||||
},
|
||||
contextMenuItems = new List<DebugUI.Foldout.ContextMenuItem>()
|
||||
{
|
||||
new DebugUI.Foldout.ContextMenuItem
|
||||
{
|
||||
displayName = k_GoToSectionString,
|
||||
action = () => { DebugManager.instance.RequestEditorWindowPanelIndex(1); }
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
var lightingSettingsData = DebugDisplaySettings.Instance.LightingSettings;
|
||||
AddWidget(new DebugUI.Foldout
|
||||
{
|
||||
displayName = "Lighting Debug Modes",
|
||||
isHeader = true,
|
||||
opened = true,
|
||||
children =
|
||||
{
|
||||
DebugDisplaySettingsLighting.WidgetFactory.CreateLightingDebugMode(lightingSettingsData),
|
||||
DebugDisplaySettingsLighting.WidgetFactory.CreateLightingFeatures(lightingSettingsData)
|
||||
},
|
||||
contextMenuItems = new List<DebugUI.Foldout.ContextMenuItem>()
|
||||
{
|
||||
new DebugUI.Foldout.ContextMenuItem
|
||||
{
|
||||
displayName = k_GoToSectionString,
|
||||
action = () => { DebugManager.instance.RequestEditorWindowPanelIndex(2); }
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
var renderingSettingsData = DebugDisplaySettings.Instance.RenderingSettings;
|
||||
AddWidget(new DebugUI.Foldout
|
||||
{
|
||||
displayName = "Rendering Debug",
|
||||
isHeader = true,
|
||||
opened = true,
|
||||
children =
|
||||
{
|
||||
DebugDisplaySettingsRendering.WidgetFactory.CreateHDR(renderingSettingsData),
|
||||
DebugDisplaySettingsRendering.WidgetFactory.CreateMSAA(renderingSettingsData),
|
||||
DebugDisplaySettingsRendering.WidgetFactory.CreatePostProcessing(renderingSettingsData),
|
||||
DebugDisplaySettingsRendering.WidgetFactory.CreateAdditionalWireframeShaderViews(renderingSettingsData),
|
||||
DebugDisplaySettingsRendering.WidgetFactory.CreateWireframeNotSupportedWarning(renderingSettingsData),
|
||||
DebugDisplaySettingsRendering.WidgetFactory.CreateOverdraw(renderingSettingsData)
|
||||
},
|
||||
contextMenuItems = new List<DebugUI.Foldout.ContextMenuItem>()
|
||||
{
|
||||
new DebugUI.Foldout.ContextMenuItem
|
||||
{
|
||||
displayName = k_GoToSectionString,
|
||||
action = () => { DebugManager.instance.RequestEditorWindowPanelIndex(3); }
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
#region IDebugDisplaySettingsData
|
||||
|
||||
public bool AreAnySettingsActive => DebugDisplaySettings.Instance.AreAnySettingsActive;
|
||||
public bool IsPostProcessingAllowed => DebugDisplaySettings.Instance.IsPostProcessingAllowed;
|
||||
public bool IsLightingActive => DebugDisplaySettings.Instance.IsLightingActive;
|
||||
public bool TryGetScreenClearColor(ref Color color) => DebugDisplaySettings.Instance.TryGetScreenClearColor(ref color);
|
||||
|
||||
public IDebugDisplaySettingsPanelDisposable CreatePanel()
|
||||
{
|
||||
return new SettingsPanel();
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 89bc0329853842ae999d6f86829fc126
|
||||
timeCreated: 1615364496
|
||||
|
|
@ -0,0 +1,79 @@
|
|||
using UnityEngine;
|
||||
using NameAndTooltip = UnityEngine.Rendering.DebugUI.Widget.NameAndTooltip;
|
||||
|
||||
namespace UnityEngine.Rendering.Universal
|
||||
{
|
||||
class DebugDisplaySettingsLighting : IDebugDisplaySettingsData
|
||||
{
|
||||
internal DebugLightingMode DebugLightingMode { get; private set; }
|
||||
internal DebugLightingFeatureFlags DebugLightingFeatureFlagsMask { get; private set; }
|
||||
|
||||
static class Strings
|
||||
{
|
||||
public static readonly NameAndTooltip LightingDebugMode = new() { name = "Lighting Debug Mode", tooltip = "Use the drop-down to select which lighting and shadow debug information to overlay on the screen." };
|
||||
public static readonly NameAndTooltip LightingFeatures = new() { name = "Lighting Features", tooltip = "Filter and debug selected lighting features in the system." };
|
||||
}
|
||||
|
||||
internal static class WidgetFactory
|
||||
{
|
||||
internal static DebugUI.Widget CreateLightingDebugMode(DebugDisplaySettingsLighting data) => new DebugUI.EnumField
|
||||
{
|
||||
nameAndTooltip = Strings.LightingDebugMode,
|
||||
autoEnum = typeof(DebugLightingMode),
|
||||
getter = () => (int)data.DebugLightingMode,
|
||||
setter = (value) => { },
|
||||
getIndex = () => (int)data.DebugLightingMode,
|
||||
setIndex = (value) => data.DebugLightingMode = (DebugLightingMode)value
|
||||
};
|
||||
|
||||
internal static DebugUI.Widget CreateLightingFeatures(DebugDisplaySettingsLighting data) => new DebugUI.BitField
|
||||
{
|
||||
nameAndTooltip = Strings.LightingFeatures,
|
||||
getter = () => data.DebugLightingFeatureFlagsMask,
|
||||
setter = (value) => data.DebugLightingFeatureFlagsMask = (DebugLightingFeatureFlags)value,
|
||||
enumType = typeof(DebugLightingFeatureFlags),
|
||||
};
|
||||
}
|
||||
|
||||
private class SettingsPanel : DebugDisplaySettingsPanel
|
||||
{
|
||||
public override string PanelName => "Lighting";
|
||||
|
||||
public SettingsPanel(DebugDisplaySettingsLighting data)
|
||||
{
|
||||
AddWidget(DebugDisplaySettingsCommon.WidgetFactory.CreateMissingDebugShadersWarning());
|
||||
|
||||
AddWidget(new DebugUI.Foldout
|
||||
{
|
||||
displayName = "Lighting Debug Modes",
|
||||
isHeader = true,
|
||||
opened = true,
|
||||
children =
|
||||
{
|
||||
WidgetFactory.CreateLightingDebugMode(data),
|
||||
WidgetFactory.CreateLightingFeatures(data)
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
#region IDebugDisplaySettingsData
|
||||
public bool AreAnySettingsActive => (DebugLightingMode != DebugLightingMode.None) || (DebugLightingFeatureFlagsMask != DebugLightingFeatureFlags.None);
|
||||
|
||||
public bool IsPostProcessingAllowed => (DebugLightingMode != DebugLightingMode.Reflections && DebugLightingMode != DebugLightingMode.ReflectionsWithSmoothness);
|
||||
|
||||
public bool IsLightingActive => true;
|
||||
|
||||
public bool TryGetScreenClearColor(ref Color color)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
public IDebugDisplaySettingsPanelDisposable CreatePanel()
|
||||
{
|
||||
return new SettingsPanel(this);
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: e3df3f6511ee9d84fb93259d602ff2e5
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
|
|
@ -0,0 +1,368 @@
|
|||
using UnityEngine;
|
||||
using NameAndTooltip = UnityEngine.Rendering.DebugUI.Widget.NameAndTooltip;
|
||||
|
||||
namespace UnityEngine.Rendering.Universal
|
||||
{
|
||||
class DebugDisplaySettingsMaterial : IDebugDisplaySettingsData
|
||||
{
|
||||
#region Material validation
|
||||
internal enum AlbedoDebugValidationPreset
|
||||
{
|
||||
DefaultLuminance,
|
||||
BlackAcrylicPaint,
|
||||
DarkSoil,
|
||||
WornAsphalt,
|
||||
DryClaySoil,
|
||||
GreenGrass,
|
||||
OldConcrete,
|
||||
RedClayTile,
|
||||
DrySand,
|
||||
NewConcrete,
|
||||
WhiteAcrylicPaint,
|
||||
FreshSnow,
|
||||
BlueSky,
|
||||
Foliage,
|
||||
}
|
||||
|
||||
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
|
||||
},
|
||||
};
|
||||
|
||||
AlbedoDebugValidationPreset m_AlbedoDebugValidationPreset;
|
||||
internal AlbedoDebugValidationPreset albedoDebugValidationPreset
|
||||
{
|
||||
get => m_AlbedoDebugValidationPreset;
|
||||
set
|
||||
{
|
||||
m_AlbedoDebugValidationPreset = value;
|
||||
AlbedoDebugValidationPresetData presetData = m_AlbedoDebugValidationPresetData[(int)value];
|
||||
AlbedoMinLuminance = presetData.minLuminance;
|
||||
AlbedoMaxLuminance = presetData.maxLuminance;
|
||||
AlbedoCompareColor = presetData.color;
|
||||
}
|
||||
}
|
||||
|
||||
internal float AlbedoMinLuminance = 0.01f;
|
||||
internal float AlbedoMaxLuminance = 0.90f;
|
||||
|
||||
float m_AlbedoHueTolerance = 0.104f;
|
||||
internal float AlbedoHueTolerance
|
||||
{
|
||||
get => m_AlbedoDebugValidationPreset == AlbedoDebugValidationPreset.DefaultLuminance ? 1.0f : m_AlbedoHueTolerance;
|
||||
private set => m_AlbedoHueTolerance = value;
|
||||
}
|
||||
|
||||
float m_AlbedoSaturationTolerance = 0.214f;
|
||||
internal float AlbedoSaturationTolerance
|
||||
{
|
||||
get => m_AlbedoDebugValidationPreset == AlbedoDebugValidationPreset.DefaultLuminance ? 1.0f : m_AlbedoSaturationTolerance;
|
||||
private set => m_AlbedoSaturationTolerance = value;
|
||||
}
|
||||
|
||||
internal Color AlbedoCompareColor = new Color(127f / 255f, 127f / 255f, 127f / 255f, 255f / 255f);
|
||||
|
||||
internal float MetallicMinValue = 0.0f;
|
||||
internal float MetallicMaxValue = 0.9f;
|
||||
|
||||
internal DebugMaterialValidationMode MaterialValidationMode;
|
||||
|
||||
#endregion
|
||||
|
||||
internal DebugMaterialMode DebugMaterialModeData { get; private set; }
|
||||
internal DebugVertexAttributeMode DebugVertexAttributeIndexData { get; private 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 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(DebugDisplaySettingsMaterial data) => new DebugUI.EnumField
|
||||
{
|
||||
nameAndTooltip = Strings.MaterialOverride,
|
||||
autoEnum = typeof(DebugMaterialMode),
|
||||
getter = () => (int)data.DebugMaterialModeData,
|
||||
setter = (value) => { },
|
||||
getIndex = () => (int)data.DebugMaterialModeData,
|
||||
setIndex = (value) => data.DebugMaterialModeData = (DebugMaterialMode)value
|
||||
};
|
||||
|
||||
internal static DebugUI.Widget CreateVertexAttribute(DebugDisplaySettingsMaterial data) => new DebugUI.EnumField
|
||||
{
|
||||
nameAndTooltip = Strings.VertexAttribute,
|
||||
autoEnum = typeof(DebugVertexAttributeMode),
|
||||
getter = () => (int)data.DebugVertexAttributeIndexData,
|
||||
setter = (value) => { },
|
||||
getIndex = () => (int)data.DebugVertexAttributeIndexData,
|
||||
setIndex = (value) => data.DebugVertexAttributeIndexData = (DebugVertexAttributeMode)value
|
||||
};
|
||||
|
||||
internal static DebugUI.Widget CreateMaterialValidationMode(DebugDisplaySettingsMaterial data) => new DebugUI.EnumField
|
||||
{
|
||||
nameAndTooltip = Strings.MaterialValidationMode,
|
||||
autoEnum = typeof(DebugMaterialValidationMode),
|
||||
getter = () => (int)data.MaterialValidationMode,
|
||||
setter = (value) => { },
|
||||
getIndex = () => (int)data.MaterialValidationMode,
|
||||
setIndex = (value) => data.MaterialValidationMode = (DebugMaterialValidationMode)value,
|
||||
onValueChanged = (_, _) => DebugManager.instance.ReDrawOnScreenDebug()
|
||||
};
|
||||
|
||||
internal static DebugUI.Widget CreateAlbedoPreset(DebugDisplaySettingsMaterial data) => new DebugUI.EnumField
|
||||
{
|
||||
nameAndTooltip = Strings.ValidationPreset,
|
||||
autoEnum = typeof(AlbedoDebugValidationPreset),
|
||||
getter = () => (int)data.albedoDebugValidationPreset,
|
||||
setter = (value) => { },
|
||||
getIndex = () => (int)data.albedoDebugValidationPreset,
|
||||
setIndex = (value) => data.albedoDebugValidationPreset = (AlbedoDebugValidationPreset)value,
|
||||
onValueChanged = (_, _) => DebugManager.instance.ReDrawOnScreenDebug()
|
||||
};
|
||||
|
||||
internal static DebugUI.Widget CreateAlbedoMinLuminance(DebugDisplaySettingsMaterial data) => new DebugUI.FloatField
|
||||
{
|
||||
nameAndTooltip = Strings.AlbedoMinLuminance,
|
||||
getter = () => data.AlbedoMinLuminance,
|
||||
setter = (value) => data.AlbedoMinLuminance = value,
|
||||
incStep = 0.01f
|
||||
};
|
||||
|
||||
internal static DebugUI.Widget CreateAlbedoMaxLuminance(DebugDisplaySettingsMaterial data) => new DebugUI.FloatField
|
||||
{
|
||||
nameAndTooltip = Strings.AlbedoMaxLuminance,
|
||||
getter = () => data.AlbedoMaxLuminance,
|
||||
setter = (value) => data.AlbedoMaxLuminance = value,
|
||||
incStep = 0.01f
|
||||
};
|
||||
|
||||
internal static DebugUI.Widget CreateAlbedoHueTolerance(DebugDisplaySettingsMaterial data) => new DebugUI.FloatField
|
||||
{
|
||||
nameAndTooltip = Strings.AlbedoHueTolerance,
|
||||
getter = () => data.AlbedoHueTolerance,
|
||||
setter = (value) => data.AlbedoHueTolerance = value,
|
||||
incStep = 0.01f,
|
||||
isHiddenCallback = () => data.albedoDebugValidationPreset == AlbedoDebugValidationPreset.DefaultLuminance
|
||||
};
|
||||
|
||||
internal static DebugUI.Widget CreateAlbedoSaturationTolerance(DebugDisplaySettingsMaterial data) => new DebugUI.FloatField
|
||||
{
|
||||
nameAndTooltip = Strings.AlbedoSaturationTolerance,
|
||||
getter = () => data.AlbedoSaturationTolerance,
|
||||
setter = (value) => data.AlbedoSaturationTolerance = value,
|
||||
incStep = 0.01f,
|
||||
isHiddenCallback = () => data.albedoDebugValidationPreset == AlbedoDebugValidationPreset.DefaultLuminance
|
||||
};
|
||||
|
||||
internal static DebugUI.Widget CreateMetallicMinValue(DebugDisplaySettingsMaterial data) => new DebugUI.FloatField
|
||||
{
|
||||
nameAndTooltip = Strings.MetallicMinValue,
|
||||
getter = () => data.MetallicMinValue,
|
||||
setter = (value) => data.MetallicMinValue = value,
|
||||
incStep = 0.01f
|
||||
};
|
||||
|
||||
internal static DebugUI.Widget CreateMetallicMaxValue(DebugDisplaySettingsMaterial data) => new DebugUI.FloatField
|
||||
{
|
||||
nameAndTooltip = Strings.MetallicMaxValue,
|
||||
getter = () => data.MetallicMaxValue,
|
||||
setter = (value) => data.MetallicMaxValue = value,
|
||||
incStep = 0.01f
|
||||
};
|
||||
}
|
||||
|
||||
private class SettingsPanel : DebugDisplaySettingsPanel
|
||||
{
|
||||
public override string PanelName => "Material";
|
||||
public SettingsPanel(DebugDisplaySettingsMaterial data)
|
||||
{
|
||||
AddWidget(DebugDisplaySettingsCommon.WidgetFactory.CreateMissingDebugShadersWarning());
|
||||
|
||||
AddWidget(new DebugUI.Foldout
|
||||
{
|
||||
displayName = "Material Filters",
|
||||
isHeader = true,
|
||||
opened = true,
|
||||
children =
|
||||
{
|
||||
WidgetFactory.CreateMaterialOverride(data),
|
||||
WidgetFactory.CreateVertexAttribute(data)
|
||||
}
|
||||
});
|
||||
AddWidget(new DebugUI.Foldout
|
||||
{
|
||||
displayName = "Material Validation",
|
||||
isHeader = true,
|
||||
opened = true,
|
||||
children =
|
||||
{
|
||||
WidgetFactory.CreateMaterialValidationMode(data),
|
||||
new DebugUI.Container()
|
||||
{
|
||||
displayName = Strings.AlbedoSettingsContainerName,
|
||||
isHiddenCallback = () => data.MaterialValidationMode != DebugMaterialValidationMode.Albedo,
|
||||
children =
|
||||
{
|
||||
WidgetFactory.CreateAlbedoPreset(data),
|
||||
WidgetFactory.CreateAlbedoMinLuminance(data),
|
||||
WidgetFactory.CreateAlbedoMaxLuminance(data),
|
||||
WidgetFactory.CreateAlbedoHueTolerance(data),
|
||||
WidgetFactory.CreateAlbedoSaturationTolerance(data)
|
||||
}
|
||||
},
|
||||
new DebugUI.Container()
|
||||
{
|
||||
displayName = Strings.MetallicSettingsContainerName,
|
||||
isHiddenCallback = () => data.MaterialValidationMode != DebugMaterialValidationMode.Metallic,
|
||||
children =
|
||||
{
|
||||
WidgetFactory.CreateMetallicMinValue(data),
|
||||
WidgetFactory.CreateMetallicMaxValue(data)
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
#region IDebugDisplaySettingsData
|
||||
public bool AreAnySettingsActive =>
|
||||
(DebugMaterialModeData != DebugMaterialMode.None) ||
|
||||
(DebugVertexAttributeIndexData != DebugVertexAttributeMode.None) ||
|
||||
(MaterialValidationMode != DebugMaterialValidationMode.None);
|
||||
public bool IsPostProcessingAllowed => !AreAnySettingsActive;
|
||||
public bool IsLightingActive => !AreAnySettingsActive;
|
||||
|
||||
public bool TryGetScreenClearColor(ref Color color)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
public IDebugDisplaySettingsPanelDisposable CreatePanel()
|
||||
{
|
||||
return new SettingsPanel(this);
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: b64304a6322ab44a3acc9758c949e286
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
|
|
@ -0,0 +1,22 @@
|
|||
using System.Collections.Generic;
|
||||
|
||||
namespace UnityEngine.Rendering.Universal
|
||||
{
|
||||
public abstract class DebugDisplaySettingsPanel : IDebugDisplaySettingsPanelDisposable
|
||||
{
|
||||
private readonly List<DebugUI.Widget> m_Widgets = new List<DebugUI.Widget>();
|
||||
|
||||
public abstract string PanelName { get; }
|
||||
public DebugUI.Widget[] Widgets => m_Widgets.ToArray();
|
||||
|
||||
protected void AddWidget(DebugUI.Widget widget)
|
||||
{
|
||||
m_Widgets.Add(widget);
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
m_Widgets.Clear();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: e5ee786a2f4e04b5bbc5c7b2e645272e
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
|
|
@ -0,0 +1,323 @@
|
|||
using System;
|
||||
using UnityEngine;
|
||||
using NameAndTooltip = UnityEngine.Rendering.DebugUI.Widget.NameAndTooltip;
|
||||
|
||||
namespace UnityEngine.Rendering.Universal
|
||||
{
|
||||
class DebugDisplaySettingsRendering : IDebugDisplaySettingsData
|
||||
{
|
||||
// Under the hood, the implementation uses a single enum (DebugSceneOverrideMode). For UI, we have split
|
||||
// this enum into WireframeMode and a separate Overdraw boolean.
|
||||
|
||||
enum WireframeMode
|
||||
{
|
||||
None,
|
||||
Wireframe,
|
||||
SolidWireframe,
|
||||
ShadedWireframe,
|
||||
}
|
||||
|
||||
WireframeMode m_WireframeMode = WireframeMode.None;
|
||||
WireframeMode wireframeMode
|
||||
{
|
||||
get => m_WireframeMode;
|
||||
set
|
||||
{
|
||||
m_WireframeMode = value;
|
||||
UpdateDebugSceneOverrideMode();
|
||||
}
|
||||
}
|
||||
|
||||
bool m_Overdraw = false;
|
||||
|
||||
bool overdraw
|
||||
{
|
||||
get => m_Overdraw;
|
||||
set
|
||||
{
|
||||
m_Overdraw = value;
|
||||
UpdateDebugSceneOverrideMode();
|
||||
}
|
||||
}
|
||||
|
||||
void UpdateDebugSceneOverrideMode()
|
||||
{
|
||||
switch (wireframeMode)
|
||||
{
|
||||
case WireframeMode.Wireframe:
|
||||
debugSceneOverrideMode = DebugSceneOverrideMode.Wireframe;
|
||||
break;
|
||||
case WireframeMode.SolidWireframe:
|
||||
debugSceneOverrideMode = DebugSceneOverrideMode.SolidWireframe;
|
||||
break;
|
||||
case WireframeMode.ShadedWireframe:
|
||||
debugSceneOverrideMode = DebugSceneOverrideMode.ShadedWireframe;
|
||||
break;
|
||||
default:
|
||||
debugSceneOverrideMode = overdraw ? DebugSceneOverrideMode.Overdraw : DebugSceneOverrideMode.None;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
internal DebugFullScreenMode debugFullScreenMode { get; private set; } = DebugFullScreenMode.None;
|
||||
internal int debugFullScreenModeOutputSizeScreenPercent { get; private set; } = 50;
|
||||
internal DebugSceneOverrideMode debugSceneOverrideMode { get; private set; } = DebugSceneOverrideMode.None;
|
||||
internal DebugMipInfoMode debugMipInfoMode { get; private set; } = DebugMipInfoMode.None;
|
||||
|
||||
internal DebugPostProcessingMode debugPostProcessingMode { get; private set; } = DebugPostProcessingMode.Auto;
|
||||
internal bool enableMsaa { get; private set; } = true;
|
||||
internal bool enableHDR { get; private set; } = true;
|
||||
|
||||
#region Pixel validation
|
||||
|
||||
internal DebugValidationMode validationMode { get; private set; }
|
||||
internal PixelValidationChannels validationChannels { get; private set; } = PixelValidationChannels.RGB;
|
||||
internal float ValidationRangeMin { get; private set; } = 0.0f;
|
||||
internal float ValidationRangeMax { get; private set; } = 1.0f;
|
||||
|
||||
static class Strings
|
||||
{
|
||||
public const string RangeValidationSettingsContainerName = "Pixel Range Settings";
|
||||
|
||||
public static readonly NameAndTooltip MapOverlays = new() { name = "Map Overlays", tooltip = "Overlays render pipeline textures to validate the scene." };
|
||||
public static readonly NameAndTooltip MapSize = new() { name = "Map Size", tooltip = "Set the size of the render pipeline texture in the scene." };
|
||||
public static readonly NameAndTooltip AdditionalWireframeModes = new() { name = "Additional Wireframe Modes", tooltip = "Debug the scene with additional wireframe shader views that are different from those in the scene view." };
|
||||
public static readonly NameAndTooltip WireframeNotSupportedWarning = new() { name = "Warning: This platform might not support wireframe rendering.", tooltip = "Some platforms, for example, mobile platforms using OpenGL ES and Vulkan, might not support wireframe rendering." };
|
||||
public static readonly NameAndTooltip Overdraw = new() { name = "Overdraw", tooltip = "Debug anywhere pixels are overdrawn on top of each other." };
|
||||
public static readonly NameAndTooltip PostProcessing = new() { name = "Post-processing", tooltip = "Override the controls for Post Processing in the scene." };
|
||||
public static readonly NameAndTooltip MSAA = new() { name = "MSAA", tooltip = "Use the checkbox to disable MSAA in the scene." };
|
||||
public static readonly NameAndTooltip HDR = new() { name = "HDR", tooltip = "Use the checkbox to disable High Dynamic Range in the scene." };
|
||||
public static readonly NameAndTooltip PixelValidationMode = new() { name = "Pixel Validation Mode", tooltip = "Choose between modes that validate pixel on screen." };
|
||||
public static readonly NameAndTooltip Channels = new() { name = "Channels", tooltip = "Choose the texture channel used to validate the scene." };
|
||||
public static readonly NameAndTooltip ValueRangeMin = new() { name = "Value Range Min", tooltip = "Any values set below this field will be considered invalid and will appear red on screen." };
|
||||
public static readonly NameAndTooltip ValueRangeMax = new() { name = "Value Range Max", tooltip = "Any values set above this field will be considered invalid and will appear blue on screen." };
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
internal static class WidgetFactory
|
||||
{
|
||||
internal static DebugUI.Widget CreateMapOverlays(DebugDisplaySettingsRendering data) => new DebugUI.EnumField
|
||||
{
|
||||
nameAndTooltip = Strings.MapOverlays,
|
||||
autoEnum = typeof(DebugFullScreenMode),
|
||||
getter = () => (int)data.debugFullScreenMode,
|
||||
setter = (value) => { },
|
||||
getIndex = () => (int)data.debugFullScreenMode,
|
||||
setIndex = (value) => data.debugFullScreenMode = (DebugFullScreenMode)value
|
||||
};
|
||||
|
||||
internal static DebugUI.Widget CreateMapOverlaySize(DebugDisplaySettingsRendering data) => new DebugUI.Container()
|
||||
{
|
||||
children =
|
||||
{
|
||||
new DebugUI.IntField
|
||||
{
|
||||
nameAndTooltip = Strings.MapSize,
|
||||
getter = () => data.debugFullScreenModeOutputSizeScreenPercent,
|
||||
setter = value => data.debugFullScreenModeOutputSizeScreenPercent = value,
|
||||
incStep = 10,
|
||||
min = () => 0,
|
||||
max = () => 100
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
internal static DebugUI.Widget CreateAdditionalWireframeShaderViews(DebugDisplaySettingsRendering data) => new DebugUI.EnumField
|
||||
{
|
||||
nameAndTooltip = Strings.AdditionalWireframeModes,
|
||||
autoEnum = typeof(WireframeMode),
|
||||
getter = () => (int)data.wireframeMode,
|
||||
setter = (value) => { },
|
||||
getIndex = () => (int)data.wireframeMode,
|
||||
setIndex = (value) => data.wireframeMode = (WireframeMode)value,
|
||||
onValueChanged = (_, _) => DebugManager.instance.ReDrawOnScreenDebug()
|
||||
};
|
||||
|
||||
internal static DebugUI.Widget CreateWireframeNotSupportedWarning(DebugDisplaySettingsRendering data) => new DebugUI.MessageBox
|
||||
{
|
||||
nameAndTooltip = Strings.WireframeNotSupportedWarning,
|
||||
style = DebugUI.MessageBox.Style.Warning,
|
||||
isHiddenCallback = () =>
|
||||
{
|
||||
#if UNITY_EDITOR
|
||||
return true;
|
||||
#else
|
||||
switch (SystemInfo.graphicsDeviceType)
|
||||
{
|
||||
case GraphicsDeviceType.OpenGLES2:
|
||||
case GraphicsDeviceType.OpenGLES3:
|
||||
case GraphicsDeviceType.Vulkan:
|
||||
return data.wireframeMode == WireframeMode.None;
|
||||
default:
|
||||
return true;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
};
|
||||
|
||||
internal static DebugUI.Widget CreateOverdraw(DebugDisplaySettingsRendering data) => new DebugUI.BoolField
|
||||
{
|
||||
nameAndTooltip = Strings.Overdraw,
|
||||
getter = () => data.overdraw,
|
||||
setter = (value) => data.overdraw = value
|
||||
};
|
||||
|
||||
internal static DebugUI.Widget CreatePostProcessing(DebugDisplaySettingsRendering data) => new DebugUI.EnumField
|
||||
{
|
||||
nameAndTooltip = Strings.PostProcessing,
|
||||
autoEnum = typeof(DebugPostProcessingMode),
|
||||
getter = () => (int)data.debugPostProcessingMode,
|
||||
setter = (value) => data.debugPostProcessingMode = (DebugPostProcessingMode)value,
|
||||
getIndex = () => (int)data.debugPostProcessingMode,
|
||||
setIndex = (value) => data.debugPostProcessingMode = (DebugPostProcessingMode)value
|
||||
};
|
||||
|
||||
internal static DebugUI.Widget CreateMSAA(DebugDisplaySettingsRendering data) => new DebugUI.BoolField
|
||||
{
|
||||
nameAndTooltip = Strings.MSAA,
|
||||
getter = () => data.enableMsaa,
|
||||
setter = (value) => data.enableMsaa = value
|
||||
};
|
||||
|
||||
internal static DebugUI.Widget CreateHDR(DebugDisplaySettingsRendering data) => new DebugUI.BoolField
|
||||
{
|
||||
nameAndTooltip = Strings.HDR,
|
||||
getter = () => data.enableHDR,
|
||||
setter = (value) => data.enableHDR = value
|
||||
};
|
||||
|
||||
internal static DebugUI.Widget CreatePixelValidationMode(DebugDisplaySettingsRendering data) => new DebugUI.EnumField
|
||||
{
|
||||
nameAndTooltip = Strings.PixelValidationMode,
|
||||
autoEnum = typeof(DebugValidationMode),
|
||||
getter = () => (int)data.validationMode,
|
||||
setter = (value) => { },
|
||||
getIndex = () => (int)data.validationMode,
|
||||
setIndex = (value) => data.validationMode = (DebugValidationMode)value,
|
||||
onValueChanged = (_, _) => DebugManager.instance.ReDrawOnScreenDebug()
|
||||
};
|
||||
|
||||
internal static DebugUI.Widget CreatePixelValidationChannels(DebugDisplaySettingsRendering data) => new DebugUI.EnumField
|
||||
{
|
||||
nameAndTooltip = Strings.Channels,
|
||||
autoEnum = typeof(PixelValidationChannels),
|
||||
getter = () => (int)data.validationChannels,
|
||||
setter = (value) => { },
|
||||
getIndex = () => (int)data.validationChannels,
|
||||
setIndex = (value) => data.validationChannels = (PixelValidationChannels)value
|
||||
};
|
||||
|
||||
internal static DebugUI.Widget CreatePixelValueRangeMin(DebugDisplaySettingsRendering data) => new DebugUI.FloatField
|
||||
{
|
||||
nameAndTooltip = Strings.ValueRangeMin,
|
||||
getter = () => data.ValidationRangeMin,
|
||||
setter = (value) => data.ValidationRangeMin = value,
|
||||
incStep = 0.01f
|
||||
};
|
||||
|
||||
internal static DebugUI.Widget CreatePixelValueRangeMax(DebugDisplaySettingsRendering data) => new DebugUI.FloatField
|
||||
{
|
||||
nameAndTooltip = Strings.ValueRangeMax,
|
||||
getter = () => data.ValidationRangeMax,
|
||||
setter = (value) => data.ValidationRangeMax = value,
|
||||
incStep = 0.01f
|
||||
};
|
||||
}
|
||||
|
||||
private class SettingsPanel : DebugDisplaySettingsPanel
|
||||
{
|
||||
public override string PanelName => "Rendering";
|
||||
|
||||
public SettingsPanel(DebugDisplaySettingsRendering data)
|
||||
{
|
||||
AddWidget(DebugDisplaySettingsCommon.WidgetFactory.CreateMissingDebugShadersWarning());
|
||||
|
||||
AddWidget(new DebugUI.Foldout
|
||||
{
|
||||
displayName = "Rendering Debug",
|
||||
isHeader = true,
|
||||
opened = true,
|
||||
children =
|
||||
{
|
||||
WidgetFactory.CreateMapOverlays(data),
|
||||
WidgetFactory.CreateMapOverlaySize(data),
|
||||
WidgetFactory.CreateHDR(data),
|
||||
WidgetFactory.CreateMSAA(data),
|
||||
WidgetFactory.CreatePostProcessing(data),
|
||||
WidgetFactory.CreateAdditionalWireframeShaderViews(data),
|
||||
WidgetFactory.CreateWireframeNotSupportedWarning(data),
|
||||
WidgetFactory.CreateOverdraw(data)
|
||||
}
|
||||
});
|
||||
|
||||
AddWidget(new DebugUI.Foldout
|
||||
{
|
||||
displayName = "Pixel Validation",
|
||||
isHeader = true,
|
||||
opened = true,
|
||||
children =
|
||||
{
|
||||
WidgetFactory.CreatePixelValidationMode(data),
|
||||
new DebugUI.Container()
|
||||
{
|
||||
displayName = Strings.RangeValidationSettingsContainerName,
|
||||
isHiddenCallback = () => data.validationMode != DebugValidationMode.HighlightOutsideOfRange,
|
||||
children =
|
||||
{
|
||||
WidgetFactory.CreatePixelValidationChannels(data),
|
||||
WidgetFactory.CreatePixelValueRangeMin(data),
|
||||
WidgetFactory.CreatePixelValueRangeMax(data)
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
#region IDebugDisplaySettingsData
|
||||
public bool AreAnySettingsActive => (debugPostProcessingMode != DebugPostProcessingMode.Auto) ||
|
||||
(debugFullScreenMode != DebugFullScreenMode.None) ||
|
||||
(debugSceneOverrideMode != DebugSceneOverrideMode.None) ||
|
||||
(debugMipInfoMode != DebugMipInfoMode.None) ||
|
||||
(validationMode != DebugValidationMode.None) ||
|
||||
!enableMsaa ||
|
||||
!enableHDR;
|
||||
|
||||
public bool IsPostProcessingAllowed => (debugPostProcessingMode != DebugPostProcessingMode.Disabled) &&
|
||||
(debugSceneOverrideMode == DebugSceneOverrideMode.None) &&
|
||||
(debugMipInfoMode == DebugMipInfoMode.None);
|
||||
|
||||
public bool IsLightingActive => (debugSceneOverrideMode == DebugSceneOverrideMode.None) &&
|
||||
(debugMipInfoMode == DebugMipInfoMode.None);
|
||||
|
||||
public bool TryGetScreenClearColor(ref Color color)
|
||||
{
|
||||
switch (debugSceneOverrideMode)
|
||||
{
|
||||
case DebugSceneOverrideMode.None:
|
||||
case DebugSceneOverrideMode.ShadedWireframe:
|
||||
return false;
|
||||
|
||||
case DebugSceneOverrideMode.Overdraw:
|
||||
color = Color.black;
|
||||
return true;
|
||||
|
||||
case DebugSceneOverrideMode.Wireframe:
|
||||
case DebugSceneOverrideMode.SolidWireframe:
|
||||
color = new Color(0.1f, 0.1f, 0.1f, 1.0f);
|
||||
return true;
|
||||
|
||||
default:
|
||||
throw new ArgumentOutOfRangeException(nameof(color));
|
||||
} // End of switch.
|
||||
}
|
||||
|
||||
public IDebugDisplaySettingsPanelDisposable CreatePanel()
|
||||
{
|
||||
return new SettingsPanel(this);
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 6f1482d9a0a18492f96f7cae7df31add
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
|
|
@ -0,0 +1,77 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace UnityEngine.Rendering.Universal
|
||||
{
|
||||
public class DebugDisplaySettingsUI : IDebugData
|
||||
{
|
||||
private IEnumerable<IDebugDisplaySettingsPanelDisposable> m_DisposablePanels;
|
||||
private DebugDisplaySettings m_Settings;
|
||||
|
||||
private void Reset()
|
||||
{
|
||||
if (m_Settings != null)
|
||||
{
|
||||
m_Settings.Reset();
|
||||
|
||||
// TODO: Tear the UI down and re-create it for now - this is horrible, so reset it instead.
|
||||
UnregisterDebug();
|
||||
RegisterDebug(m_Settings);
|
||||
DebugManager.instance.RefreshEditor();
|
||||
}
|
||||
}
|
||||
|
||||
public void RegisterDebug(DebugDisplaySettings settings)
|
||||
{
|
||||
DebugManager debugManager = DebugManager.instance;
|
||||
List<IDebugDisplaySettingsPanelDisposable> panels = new List<IDebugDisplaySettingsPanelDisposable>();
|
||||
|
||||
debugManager.RegisterData(this);
|
||||
|
||||
m_Settings = settings;
|
||||
m_DisposablePanels = panels;
|
||||
|
||||
Action<IDebugDisplaySettingsData> onExecute = (data) =>
|
||||
{
|
||||
IDebugDisplaySettingsPanelDisposable disposableSettingsPanel = data.CreatePanel();
|
||||
DebugUI.Widget[] panelWidgets = disposableSettingsPanel.Widgets;
|
||||
string panelId = disposableSettingsPanel.PanelName;
|
||||
DebugUI.Panel panel = debugManager.GetPanel(panelId, true);
|
||||
ObservableList<DebugUI.Widget> panelChildren = panel.children;
|
||||
|
||||
panels.Add(disposableSettingsPanel);
|
||||
panelChildren.Add(panelWidgets);
|
||||
};
|
||||
|
||||
m_Settings.ForEach(onExecute);
|
||||
}
|
||||
|
||||
public void UnregisterDebug()
|
||||
{
|
||||
DebugManager debugManager = DebugManager.instance;
|
||||
|
||||
foreach (IDebugDisplaySettingsPanelDisposable disposableSettingsPanel in m_DisposablePanels)
|
||||
{
|
||||
DebugUI.Widget[] panelWidgets = disposableSettingsPanel.Widgets;
|
||||
string panelId = disposableSettingsPanel.PanelName;
|
||||
DebugUI.Panel panel = debugManager.GetPanel(panelId, true);
|
||||
ObservableList<DebugUI.Widget> panelChildren = panel.children;
|
||||
|
||||
disposableSettingsPanel.Dispose();
|
||||
panelChildren.Remove(panelWidgets);
|
||||
}
|
||||
|
||||
m_DisposablePanels = null;
|
||||
|
||||
debugManager.UnregisterData(this);
|
||||
}
|
||||
|
||||
#region IDebugData
|
||||
public Action GetReset()
|
||||
{
|
||||
return Reset;
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 267b889b8e81a45d2a5f5bc4121bc7b9
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
|
|
@ -0,0 +1,409 @@
|
|||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
|
||||
namespace UnityEngine.Rendering.Universal
|
||||
{
|
||||
class DebugHandler : IDebugDisplaySettingsQuery
|
||||
{
|
||||
#region Property Id Constants
|
||||
|
||||
static readonly int k_DebugColorInvalidModePropertyId = Shader.PropertyToID("_DebugColorInvalidMode");
|
||||
|
||||
static readonly int k_DebugColorPropertyId = Shader.PropertyToID("_DebugColor");
|
||||
static readonly int k_DebugTexturePropertyId = Shader.PropertyToID("_DebugTexture");
|
||||
static readonly int k_DebugTextureNoStereoPropertyId = Shader.PropertyToID("_DebugTextureNoStereo");
|
||||
static readonly int k_DebugTextureDisplayRect = Shader.PropertyToID("_DebugTextureDisplayRect");
|
||||
static readonly int k_DebugRenderTargetSupportsStereo = Shader.PropertyToID("_DebugRenderTargetSupportsStereo");
|
||||
|
||||
// Material settings...
|
||||
static readonly int k_DebugMaterialModeId = Shader.PropertyToID("_DebugMaterialMode");
|
||||
static readonly int k_DebugVertexAttributeModeId = Shader.PropertyToID("_DebugVertexAttributeMode");
|
||||
static readonly int k_DebugMaterialValidationModeId = Shader.PropertyToID("_DebugMaterialValidationMode");
|
||||
|
||||
// Rendering settings...
|
||||
static readonly int k_DebugMipInfoModeId = Shader.PropertyToID("_DebugMipInfoMode");
|
||||
static readonly int k_DebugSceneOverrideModeId = Shader.PropertyToID("_DebugSceneOverrideMode");
|
||||
static readonly int k_DebugFullScreenModeId = Shader.PropertyToID("_DebugFullScreenMode");
|
||||
static readonly int k_DebugValidationModeId = Shader.PropertyToID("_DebugValidationMode");
|
||||
static readonly int k_DebugValidateBelowMinThresholdColorPropertyId = Shader.PropertyToID("_DebugValidateBelowMinThresholdColor");
|
||||
static readonly int k_DebugValidateAboveMaxThresholdColorPropertyId = Shader.PropertyToID("_DebugValidateAboveMaxThresholdColor");
|
||||
|
||||
// Lighting settings...
|
||||
static readonly int k_DebugLightingModeId = Shader.PropertyToID("_DebugLightingMode");
|
||||
static readonly int k_DebugLightingFeatureFlagsId = Shader.PropertyToID("_DebugLightingFeatureFlags");
|
||||
|
||||
static readonly int k_DebugValidateAlbedoMinLuminanceId = Shader.PropertyToID("_DebugValidateAlbedoMinLuminance");
|
||||
static readonly int k_DebugValidateAlbedoMaxLuminanceId = Shader.PropertyToID("_DebugValidateAlbedoMaxLuminance");
|
||||
static readonly int k_DebugValidateAlbedoSaturationToleranceId = Shader.PropertyToID("_DebugValidateAlbedoSaturationTolerance");
|
||||
static readonly int k_DebugValidateAlbedoHueToleranceId = Shader.PropertyToID("_DebugValidateAlbedoHueTolerance");
|
||||
static readonly int k_DebugValidateAlbedoCompareColorId = Shader.PropertyToID("_DebugValidateAlbedoCompareColor");
|
||||
|
||||
static readonly int k_DebugValidateMetallicMinValueId = Shader.PropertyToID("_DebugValidateMetallicMinValue");
|
||||
static readonly int k_DebugValidateMetallicMaxValueId = Shader.PropertyToID("_DebugValidateMetallicMaxValue");
|
||||
|
||||
static readonly int k_ValidationChannelsId = Shader.PropertyToID("_ValidationChannels");
|
||||
static readonly int k_RangeMinimumId = Shader.PropertyToID("_RangeMinimum");
|
||||
static readonly int k_RangeMaximumId = Shader.PropertyToID("_RangeMaximum");
|
||||
|
||||
#endregion
|
||||
|
||||
readonly Material m_ReplacementMaterial;
|
||||
|
||||
bool m_HasDebugRenderTarget;
|
||||
bool m_DebugRenderTargetSupportsStereo;
|
||||
Vector4 m_DebugRenderTargetPixelRect;
|
||||
RenderTargetIdentifier m_DebugRenderTargetIdentifier;
|
||||
|
||||
readonly DebugDisplaySettings m_DebugDisplaySettings;
|
||||
|
||||
DebugDisplaySettingsLighting LightingSettings => m_DebugDisplaySettings.LightingSettings;
|
||||
DebugDisplaySettingsMaterial MaterialSettings => m_DebugDisplaySettings.MaterialSettings;
|
||||
DebugDisplaySettingsRendering RenderingSettings => m_DebugDisplaySettings.RenderingSettings;
|
||||
|
||||
#region IDebugDisplaySettingsQuery
|
||||
|
||||
public bool AreAnySettingsActive => m_DebugDisplaySettings.AreAnySettingsActive;
|
||||
public bool IsPostProcessingAllowed => m_DebugDisplaySettings.IsPostProcessingAllowed;
|
||||
public bool IsLightingActive => m_DebugDisplaySettings.IsLightingActive;
|
||||
|
||||
// These modes would require putting custom data into gbuffer, so instead we just disable deferred mode.
|
||||
internal bool IsActiveModeUnsupportedForDeferred =>
|
||||
m_DebugDisplaySettings.LightingSettings.DebugLightingMode != DebugLightingMode.None ||
|
||||
m_DebugDisplaySettings.LightingSettings.DebugLightingFeatureFlagsMask != DebugLightingFeatureFlags.None ||
|
||||
m_DebugDisplaySettings.RenderingSettings.debugSceneOverrideMode != DebugSceneOverrideMode.None ||
|
||||
m_DebugDisplaySettings.MaterialSettings.DebugMaterialModeData != DebugMaterialMode.None ||
|
||||
m_DebugDisplaySettings.MaterialSettings.DebugVertexAttributeIndexData != DebugVertexAttributeMode.None ||
|
||||
m_DebugDisplaySettings.MaterialSettings.MaterialValidationMode != DebugMaterialValidationMode.None;
|
||||
|
||||
public bool TryGetScreenClearColor(ref Color color)
|
||||
{
|
||||
return m_DebugDisplaySettings.TryGetScreenClearColor(ref color);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
internal Material ReplacementMaterial => m_ReplacementMaterial;
|
||||
internal DebugDisplaySettings DebugDisplaySettings => m_DebugDisplaySettings;
|
||||
|
||||
internal bool IsScreenClearNeeded
|
||||
{
|
||||
get
|
||||
{
|
||||
Color color = Color.black;
|
||||
|
||||
return TryGetScreenClearColor(ref color);
|
||||
}
|
||||
}
|
||||
|
||||
internal bool IsRenderPassSupported
|
||||
{
|
||||
get
|
||||
{
|
||||
return RenderingSettings.debugSceneOverrideMode == DebugSceneOverrideMode.None || RenderingSettings.debugSceneOverrideMode == DebugSceneOverrideMode.Overdraw;
|
||||
}
|
||||
}
|
||||
|
||||
internal DebugHandler(ScriptableRendererData scriptableRendererData)
|
||||
{
|
||||
Shader debugReplacementShader = scriptableRendererData.debugShaders.debugReplacementPS;
|
||||
|
||||
m_DebugDisplaySettings = DebugDisplaySettings.Instance;
|
||||
|
||||
m_ReplacementMaterial = (debugReplacementShader == null) ? null : CoreUtils.CreateEngineMaterial(debugReplacementShader);
|
||||
}
|
||||
|
||||
internal bool IsActiveForCamera(ref CameraData cameraData)
|
||||
{
|
||||
return !cameraData.isPreviewCamera && AreAnySettingsActive;
|
||||
}
|
||||
|
||||
internal bool TryGetFullscreenDebugMode(out DebugFullScreenMode debugFullScreenMode)
|
||||
{
|
||||
return TryGetFullscreenDebugMode(out debugFullScreenMode, out _);
|
||||
}
|
||||
|
||||
internal bool TryGetFullscreenDebugMode(out DebugFullScreenMode debugFullScreenMode, out int textureHeightPercent)
|
||||
{
|
||||
debugFullScreenMode = RenderingSettings.debugFullScreenMode;
|
||||
textureHeightPercent = RenderingSettings.debugFullScreenModeOutputSizeScreenPercent;
|
||||
return debugFullScreenMode != DebugFullScreenMode.None;
|
||||
}
|
||||
|
||||
[Conditional("DEVELOPMENT_BUILD"), Conditional("UNITY_EDITOR")]
|
||||
internal void SetupShaderProperties(CommandBuffer cmd, int passIndex = 0)
|
||||
{
|
||||
if (LightingSettings.DebugLightingMode == DebugLightingMode.ShadowCascades)
|
||||
{
|
||||
// we disable cubemap reflections, too distracting (in TemplateLWRP for ex.)
|
||||
cmd.EnableShaderKeyword("_DEBUG_ENVIRONMENTREFLECTIONS_OFF");
|
||||
}
|
||||
else
|
||||
{
|
||||
cmd.DisableShaderKeyword("_DEBUG_ENVIRONMENTREFLECTIONS_OFF");
|
||||
}
|
||||
|
||||
switch (RenderingSettings.debugSceneOverrideMode)
|
||||
{
|
||||
case DebugSceneOverrideMode.Overdraw:
|
||||
{
|
||||
cmd.SetGlobalColor(k_DebugColorPropertyId, new Color(0.1f, 0.01f, 0.01f, 1));
|
||||
break;
|
||||
}
|
||||
|
||||
case DebugSceneOverrideMode.Wireframe:
|
||||
{
|
||||
cmd.SetGlobalColor(k_DebugColorPropertyId, Color.black);
|
||||
break;
|
||||
}
|
||||
|
||||
case DebugSceneOverrideMode.SolidWireframe:
|
||||
{
|
||||
cmd.SetGlobalColor(k_DebugColorPropertyId, (passIndex == 0) ? Color.white : Color.black);
|
||||
break;
|
||||
}
|
||||
|
||||
case DebugSceneOverrideMode.ShadedWireframe:
|
||||
{
|
||||
if (passIndex == 0)
|
||||
{
|
||||
cmd.DisableShaderKeyword(ShaderKeywordStrings.DEBUG_DISPLAY);
|
||||
}
|
||||
else if (passIndex == 1)
|
||||
{
|
||||
cmd.SetGlobalColor(k_DebugColorPropertyId, Color.black);
|
||||
cmd.EnableShaderKeyword(ShaderKeywordStrings.DEBUG_DISPLAY);
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
switch (MaterialSettings.MaterialValidationMode)
|
||||
{
|
||||
case DebugMaterialValidationMode.Albedo:
|
||||
cmd.SetGlobalFloat(k_DebugValidateAlbedoMinLuminanceId, MaterialSettings.AlbedoMinLuminance);
|
||||
cmd.SetGlobalFloat(k_DebugValidateAlbedoMaxLuminanceId, MaterialSettings.AlbedoMaxLuminance);
|
||||
cmd.SetGlobalFloat(k_DebugValidateAlbedoSaturationToleranceId, MaterialSettings.AlbedoSaturationTolerance);
|
||||
cmd.SetGlobalFloat(k_DebugValidateAlbedoHueToleranceId, MaterialSettings.AlbedoHueTolerance);
|
||||
cmd.SetGlobalColor(k_DebugValidateAlbedoCompareColorId, MaterialSettings.AlbedoCompareColor.linear);
|
||||
break;
|
||||
|
||||
case DebugMaterialValidationMode.Metallic:
|
||||
cmd.SetGlobalFloat(k_DebugValidateMetallicMinValueId, MaterialSettings.MetallicMinValue);
|
||||
cmd.SetGlobalFloat(k_DebugValidateMetallicMaxValueId, MaterialSettings.MetallicMaxValue);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
internal void SetDebugRenderTarget(RenderTargetIdentifier renderTargetIdentifier, Rect displayRect, bool supportsStereo)
|
||||
{
|
||||
m_HasDebugRenderTarget = true;
|
||||
m_DebugRenderTargetSupportsStereo = supportsStereo;
|
||||
m_DebugRenderTargetIdentifier = renderTargetIdentifier;
|
||||
m_DebugRenderTargetPixelRect = new Vector4(displayRect.x, displayRect.y, displayRect.width, displayRect.height);
|
||||
}
|
||||
|
||||
internal void ResetDebugRenderTarget()
|
||||
{
|
||||
m_HasDebugRenderTarget = false;
|
||||
}
|
||||
|
||||
[Conditional("DEVELOPMENT_BUILD"), Conditional("UNITY_EDITOR")]
|
||||
internal void UpdateShaderGlobalPropertiesForFinalValidationPass(CommandBuffer cmd, ref CameraData cameraData, bool isFinalPass)
|
||||
{
|
||||
// Ensure final validation & fullscreen debug modes are only done once in the very final pass, for the last camera on the stack.
|
||||
bool isFinal = isFinalPass && cameraData.resolveFinalTarget;
|
||||
if (!isFinal)
|
||||
{
|
||||
cmd.DisableShaderKeyword(ShaderKeywordStrings.DEBUG_DISPLAY);
|
||||
return;
|
||||
}
|
||||
|
||||
if (IsActiveForCamera(ref cameraData))
|
||||
{
|
||||
cmd.EnableShaderKeyword(ShaderKeywordStrings.DEBUG_DISPLAY);
|
||||
}
|
||||
else
|
||||
{
|
||||
cmd.DisableShaderKeyword(ShaderKeywordStrings.DEBUG_DISPLAY);
|
||||
}
|
||||
|
||||
if (m_HasDebugRenderTarget)
|
||||
{
|
||||
cmd.SetGlobalTexture(m_DebugRenderTargetSupportsStereo ? k_DebugTexturePropertyId : k_DebugTextureNoStereoPropertyId, m_DebugRenderTargetIdentifier);
|
||||
cmd.SetGlobalVector(k_DebugTextureDisplayRect, m_DebugRenderTargetPixelRect);
|
||||
cmd.SetGlobalInteger(k_DebugRenderTargetSupportsStereo, m_DebugRenderTargetSupportsStereo ? 1 : 0);
|
||||
}
|
||||
|
||||
var renderingSettings = m_DebugDisplaySettings.RenderingSettings;
|
||||
if (renderingSettings.validationMode == DebugValidationMode.HighlightOutsideOfRange)
|
||||
{
|
||||
cmd.SetGlobalInteger(k_ValidationChannelsId, (int)renderingSettings.validationChannels);
|
||||
cmd.SetGlobalFloat(k_RangeMinimumId, renderingSettings.ValidationRangeMin);
|
||||
cmd.SetGlobalFloat(k_RangeMaximumId, renderingSettings.ValidationRangeMax);
|
||||
}
|
||||
}
|
||||
|
||||
[Conditional("DEVELOPMENT_BUILD"), Conditional("UNITY_EDITOR")]
|
||||
internal void Setup(ScriptableRenderContext context, ref CameraData cameraData)
|
||||
{
|
||||
var cmd = CommandBufferPool.Get("");
|
||||
|
||||
if (IsActiveForCamera(ref cameraData))
|
||||
{
|
||||
cmd.EnableShaderKeyword(ShaderKeywordStrings.DEBUG_DISPLAY);
|
||||
|
||||
// Material settings...
|
||||
cmd.SetGlobalFloat(k_DebugMaterialModeId, (int)MaterialSettings.DebugMaterialModeData);
|
||||
cmd.SetGlobalFloat(k_DebugVertexAttributeModeId, (int)MaterialSettings.DebugVertexAttributeIndexData);
|
||||
|
||||
cmd.SetGlobalInteger(k_DebugMaterialValidationModeId, (int)MaterialSettings.MaterialValidationMode);
|
||||
|
||||
// Rendering settings...
|
||||
cmd.SetGlobalInteger(k_DebugMipInfoModeId, (int)RenderingSettings.debugMipInfoMode);
|
||||
cmd.SetGlobalInteger(k_DebugSceneOverrideModeId, (int)RenderingSettings.debugSceneOverrideMode);
|
||||
cmd.SetGlobalInteger(k_DebugFullScreenModeId, (int)RenderingSettings.debugFullScreenMode);
|
||||
cmd.SetGlobalInteger(k_DebugValidationModeId, (int)RenderingSettings.validationMode);
|
||||
cmd.SetGlobalColor(k_DebugValidateBelowMinThresholdColorPropertyId, Color.red);
|
||||
cmd.SetGlobalColor(k_DebugValidateAboveMaxThresholdColorPropertyId, Color.blue);
|
||||
|
||||
// Lighting settings...
|
||||
cmd.SetGlobalFloat(k_DebugLightingModeId, (int)LightingSettings.DebugLightingMode);
|
||||
cmd.SetGlobalInteger(k_DebugLightingFeatureFlagsId, (int)LightingSettings.DebugLightingFeatureFlagsMask);
|
||||
|
||||
// Set-up any other persistent properties...
|
||||
cmd.SetGlobalColor(k_DebugColorInvalidModePropertyId, Color.red);
|
||||
}
|
||||
else
|
||||
{
|
||||
cmd.DisableShaderKeyword(ShaderKeywordStrings.DEBUG_DISPLAY);
|
||||
}
|
||||
|
||||
context.ExecuteCommandBuffer(cmd);
|
||||
CommandBufferPool.Release(cmd);
|
||||
}
|
||||
|
||||
#region DebugRenderPasses
|
||||
|
||||
private class DebugRenderPassEnumerable : IEnumerable<DebugRenderSetup>
|
||||
{
|
||||
private class Enumerator : IEnumerator<DebugRenderSetup>
|
||||
{
|
||||
private readonly DebugHandler m_DebugHandler;
|
||||
private readonly ScriptableRenderContext m_Context;
|
||||
private readonly CommandBuffer m_CommandBuffer;
|
||||
private readonly int m_NumIterations;
|
||||
|
||||
private int m_Index;
|
||||
|
||||
public DebugRenderSetup Current { get; private set; }
|
||||
object IEnumerator.Current => Current;
|
||||
|
||||
public Enumerator(DebugHandler debugHandler, ScriptableRenderContext context, CommandBuffer commandBuffer)
|
||||
{
|
||||
DebugSceneOverrideMode sceneOverrideMode = debugHandler.DebugDisplaySettings.RenderingSettings.debugSceneOverrideMode;
|
||||
|
||||
m_DebugHandler = debugHandler;
|
||||
m_Context = context;
|
||||
m_CommandBuffer = commandBuffer;
|
||||
m_NumIterations = ((sceneOverrideMode == DebugSceneOverrideMode.SolidWireframe) || (sceneOverrideMode == DebugSceneOverrideMode.ShadedWireframe)) ? 2 : 1;
|
||||
|
||||
m_Index = -1;
|
||||
}
|
||||
|
||||
#region IEnumerator<DebugRenderSetup>
|
||||
|
||||
public bool MoveNext()
|
||||
{
|
||||
Current?.Dispose();
|
||||
|
||||
if (++m_Index >= m_NumIterations)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
Current = new DebugRenderSetup(m_DebugHandler, m_Context, m_CommandBuffer, m_Index);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
public void Reset()
|
||||
{
|
||||
if (Current != null)
|
||||
{
|
||||
Current.Dispose();
|
||||
Current = null;
|
||||
}
|
||||
|
||||
m_Index = -1;
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
Current?.Dispose();
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
|
||||
private readonly DebugHandler m_DebugHandler;
|
||||
private readonly ScriptableRenderContext m_Context;
|
||||
private readonly CommandBuffer m_CommandBuffer;
|
||||
|
||||
public DebugRenderPassEnumerable(DebugHandler debugHandler, ScriptableRenderContext context, CommandBuffer commandBuffer)
|
||||
{
|
||||
m_DebugHandler = debugHandler;
|
||||
m_Context = context;
|
||||
m_CommandBuffer = commandBuffer;
|
||||
}
|
||||
|
||||
#region IEnumerable<DebugRenderSetup>
|
||||
|
||||
public IEnumerator<DebugRenderSetup> GetEnumerator()
|
||||
{
|
||||
return new Enumerator(m_DebugHandler, m_Context, m_CommandBuffer);
|
||||
}
|
||||
|
||||
IEnumerator IEnumerable.GetEnumerator()
|
||||
{
|
||||
return GetEnumerator();
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
|
||||
internal IEnumerable<DebugRenderSetup> CreateDebugRenderSetupEnumerable(ScriptableRenderContext context,
|
||||
CommandBuffer commandBuffer)
|
||||
{
|
||||
return new DebugRenderPassEnumerable(this, context, commandBuffer);
|
||||
}
|
||||
|
||||
internal delegate void DrawFunction(
|
||||
ScriptableRenderContext context,
|
||||
ref RenderingData renderingData,
|
||||
ref DrawingSettings drawingSettings,
|
||||
ref FilteringSettings filteringSettings,
|
||||
ref RenderStateBlock renderStateBlock);
|
||||
|
||||
internal void DrawWithDebugRenderState(
|
||||
ScriptableRenderContext context,
|
||||
CommandBuffer cmd,
|
||||
ref RenderingData renderingData,
|
||||
ref DrawingSettings drawingSettings,
|
||||
ref FilteringSettings filteringSettings,
|
||||
ref RenderStateBlock renderStateBlock,
|
||||
DrawFunction func)
|
||||
{
|
||||
foreach (DebugRenderSetup debugRenderSetup in CreateDebugRenderSetupEnumerable(context, cmd))
|
||||
{
|
||||
DrawingSettings debugDrawingSettings = debugRenderSetup.CreateDrawingSettings(drawingSettings);
|
||||
RenderStateBlock debugRenderStateBlock = debugRenderSetup.GetRenderStateBlock(renderStateBlock);
|
||||
func(context, ref renderingData, ref debugDrawingSettings, ref filteringSettings, ref debugRenderStateBlock);
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
fileFormatVersion: 2
|
||||
guid: a684da720c3a43aaa94d1c3e9de4321f
|
||||
timeCreated: 1601652776
|
||||
|
|
@ -0,0 +1,139 @@
|
|||
using System;
|
||||
|
||||
namespace UnityEngine.Rendering.Universal
|
||||
{
|
||||
class DebugRenderSetup : IDisposable
|
||||
{
|
||||
private readonly DebugHandler m_DebugHandler;
|
||||
private readonly ScriptableRenderContext m_Context;
|
||||
private readonly CommandBuffer m_CommandBuffer;
|
||||
private readonly int m_Index;
|
||||
|
||||
private DebugDisplaySettingsMaterial MaterialSettings => m_DebugHandler.DebugDisplaySettings.MaterialSettings;
|
||||
private DebugDisplaySettingsRendering RenderingSettings => m_DebugHandler.DebugDisplaySettings.RenderingSettings;
|
||||
private DebugDisplaySettingsLighting LightingSettings => m_DebugHandler.DebugDisplaySettings.LightingSettings;
|
||||
|
||||
private void Begin()
|
||||
{
|
||||
DebugSceneOverrideMode sceneOverrideMode = RenderingSettings.debugSceneOverrideMode;
|
||||
|
||||
switch (sceneOverrideMode)
|
||||
{
|
||||
case DebugSceneOverrideMode.Wireframe:
|
||||
{
|
||||
m_Context.Submit();
|
||||
GL.wireframe = true;
|
||||
break;
|
||||
}
|
||||
|
||||
case DebugSceneOverrideMode.SolidWireframe:
|
||||
case DebugSceneOverrideMode.ShadedWireframe:
|
||||
{
|
||||
if (m_Index == 1)
|
||||
{
|
||||
m_Context.Submit();
|
||||
GL.wireframe = true;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
m_DebugHandler.SetupShaderProperties(m_CommandBuffer, m_Index);
|
||||
|
||||
m_Context.ExecuteCommandBuffer(m_CommandBuffer);
|
||||
m_CommandBuffer.Clear();
|
||||
}
|
||||
|
||||
private void End()
|
||||
{
|
||||
DebugSceneOverrideMode sceneOverrideMode = RenderingSettings.debugSceneOverrideMode;
|
||||
|
||||
switch (sceneOverrideMode)
|
||||
{
|
||||
case DebugSceneOverrideMode.Wireframe:
|
||||
{
|
||||
m_Context.Submit();
|
||||
GL.wireframe = false;
|
||||
break;
|
||||
}
|
||||
|
||||
case DebugSceneOverrideMode.SolidWireframe:
|
||||
case DebugSceneOverrideMode.ShadedWireframe:
|
||||
{
|
||||
if (m_Index == 1)
|
||||
{
|
||||
m_Context.Submit();
|
||||
GL.wireframe = false;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
internal DebugRenderSetup(DebugHandler debugHandler, ScriptableRenderContext context, CommandBuffer commandBuffer, int index)
|
||||
{
|
||||
m_DebugHandler = debugHandler;
|
||||
m_Context = context;
|
||||
m_CommandBuffer = commandBuffer;
|
||||
m_Index = index;
|
||||
|
||||
Begin();
|
||||
}
|
||||
|
||||
internal DrawingSettings CreateDrawingSettings(DrawingSettings drawingSettings)
|
||||
{
|
||||
bool usesReplacementMaterial = (MaterialSettings.DebugVertexAttributeIndexData != DebugVertexAttributeMode.None);
|
||||
|
||||
if (usesReplacementMaterial)
|
||||
{
|
||||
Material replacementMaterial = m_DebugHandler.ReplacementMaterial;
|
||||
DrawingSettings modifiedDrawingSettings = drawingSettings;
|
||||
|
||||
modifiedDrawingSettings.overrideMaterial = replacementMaterial;
|
||||
modifiedDrawingSettings.overrideMaterialPassIndex = 0;
|
||||
return modifiedDrawingSettings;
|
||||
}
|
||||
|
||||
// No overrides, return original
|
||||
return drawingSettings;
|
||||
}
|
||||
|
||||
internal RenderStateBlock GetRenderStateBlock(RenderStateBlock renderStateBlock)
|
||||
{
|
||||
DebugSceneOverrideMode sceneOverrideMode = RenderingSettings.debugSceneOverrideMode;
|
||||
|
||||
// Potentially override parts of the RenderStateBlock
|
||||
switch (sceneOverrideMode)
|
||||
{
|
||||
case DebugSceneOverrideMode.Overdraw:
|
||||
{
|
||||
RenderTargetBlendState additiveBlend = new RenderTargetBlendState(sourceColorBlendMode: BlendMode.One, destinationColorBlendMode: BlendMode.One);
|
||||
|
||||
// Additive-blend but leave z-write and culling as they are when we draw normally
|
||||
renderStateBlock.blendState = new BlendState { blendState0 = additiveBlend };
|
||||
renderStateBlock.mask = RenderStateMask.Blend;
|
||||
break;
|
||||
}
|
||||
|
||||
case DebugSceneOverrideMode.SolidWireframe:
|
||||
case DebugSceneOverrideMode.ShadedWireframe:
|
||||
{
|
||||
if (m_Index == 1)
|
||||
{
|
||||
// Ensure we render the wireframe in front of the solid triangles of the previous pass...
|
||||
renderStateBlock.rasterState = new RasterState(offsetUnits: -1, offsetFactor: -1);
|
||||
renderStateBlock.mask = RenderStateMask.Raster;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return renderStateBlock;
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
End();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
fileFormatVersion: 2
|
||||
guid: a7745542269049e0a733b635ef8e4df8
|
||||
timeCreated: 1613120217
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
namespace UnityEngine.Rendering.Universal
|
||||
{
|
||||
public interface IDebugDisplaySettingsData : IDebugDisplaySettingsQuery
|
||||
{
|
||||
/// <summary>
|
||||
/// Creates the debug UI panel needed for these debug settings.
|
||||
/// </summary>
|
||||
/// <returns>The debug UI panel created.</returns>
|
||||
IDebugDisplaySettingsPanelDisposable CreatePanel();
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 78ae6e132563244b58b0aeaf4f96453e
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
|
|
@ -0,0 +1,21 @@
|
|||
using System;
|
||||
|
||||
namespace UnityEngine.Rendering.Universal
|
||||
{
|
||||
public interface IDebugDisplaySettingsPanel
|
||||
{
|
||||
/// <summary>
|
||||
/// The name used when displaying this panel.
|
||||
/// </summary>
|
||||
string PanelName { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Widgets used by this panel.
|
||||
/// </summary>
|
||||
DebugUI.Widget[] Widgets { get; }
|
||||
}
|
||||
|
||||
public interface IDebugDisplaySettingsPanelDisposable : IDebugDisplaySettingsPanel, IDisposable
|
||||
{
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: b2dd686478607420fa4600df5d27143f
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
|
|
@ -0,0 +1,32 @@
|
|||
using UnityEngine;
|
||||
|
||||
namespace UnityEngine.Rendering.Universal
|
||||
{
|
||||
/// <summary>
|
||||
/// Interface for determining what kind of debug settings are currently active.
|
||||
/// </summary>
|
||||
public interface IDebugDisplaySettingsQuery
|
||||
{
|
||||
/// <summary>
|
||||
/// Checks whether ANY of the debug settings are currently active.
|
||||
/// </summary>
|
||||
bool AreAnySettingsActive { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Checks whether the current state of these settings allows post-processing.
|
||||
/// </summary>
|
||||
bool IsPostProcessingAllowed { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Checks whether lighting is active for these settings.
|
||||
/// </summary>
|
||||
bool IsLightingActive { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Attempts to get the color used to clear the screen for this debug setting.
|
||||
/// </summary>
|
||||
/// <param name="color">A reference to the screen clear color to use.</param>
|
||||
/// <returns>"true" if we updated the color, "false" if we didn't change anything.</returns>
|
||||
bool TryGetScreenClearColor(ref Color color);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 52acb35497424fdcb9cc2535113a9c15
|
||||
timeCreated: 1613054809
|
||||
Loading…
Add table
Add a link
Reference in a new issue