浏览代码

Simplified (hopefully) the way we display material and lighting debug modes.

Material/Engine/Attributes/GBuffer are now clearly separated in the UI.
/Branch_Batching2
Julien Ignace 8 年前
当前提交
25092737
共有 11 个文件被更改,包括 392 次插入174 次删除
  1. 262
      Assets/ScriptableRenderPipeline/HDRenderPipeline/Debug/DebugDisplay.cs
  2. 13
      Assets/ScriptableRenderPipeline/HDRenderPipeline/Debug/DebugDisplay.cs.hlsl
  3. 2
      Assets/ScriptableRenderPipeline/HDRenderPipeline/Debug/DebugDisplay.hlsl
  4. 200
      Assets/ScriptableRenderPipeline/HDRenderPipeline/Editor/HDRenderPipelineInspector.cs
  5. 12
      Assets/ScriptableRenderPipeline/HDRenderPipeline/HDRenderPipeline.cs
  6. 7
      Assets/ScriptableRenderPipeline/HDRenderPipeline/Lighting/TilePass/TilePass.cs
  7. 6
      Assets/ScriptableRenderPipeline/HDRenderPipeline/Lighting/TilePass/TilePassLoop.hlsl
  8. 4
      Assets/ScriptableRenderPipeline/HDRenderPipeline/Material/Lit/Lit.hlsl
  9. 2
      Assets/ScriptableRenderPipeline/HDRenderPipeline/ShaderPass/ShaderPassForward.hlsl
  10. 42
      Assets/ScriptableRenderPipeline/common/Debugging/DebugItemDrawer.cs
  11. 16
      Assets/ScriptableRenderPipeline/common/Debugging/DebugMenuItemUI.cs

262
Assets/ScriptableRenderPipeline/HDRenderPipeline/Debug/DebugDisplay.cs


namespace UnityEngine.Experimental.Rendering.HDPipeline
{
[GenerateHLSL]
public enum DebugDisplayMode
public enum DebugLightingMode
ViewMaterial,
DiffuseLighting,
SpecularLighting,
VisualizeCascade

public bool displayRenderingDebug = false;
public bool displayLightingDebug = false;
public DebugDisplayMode debugDisplayMode = DebugDisplayMode.None;
public bool IsDebugDisplayEnable()
private static bool isDebugViewMaterialInit = false;
public static GUIContent[] debugViewMaterialStrings = null;
public static int[] debugViewMaterialValues = null;
public static GUIContent[] debugViewEngineStrings = null;
public static int[] debugViewEngineValues = null;
public static GUIContent[] debugViewMaterialVaryingStrings = null;
public static int[] debugViewMaterialVaryingValues = null;
public static GUIContent[] debugViewMaterialGBufferStrings = null;
public static int[] debugViewMaterialGBufferValues = null;
public DebugDisplaySettings()
{
BuildDebugRepresentation();
}
public int GetDebugMaterialIndex()
{
return materialDebugSettings.GetDebugMaterialIndex();
}
public DebugLightingMode GetDebugLightingMode()
{
return lightingDebugSettings.debugLightingMode;
}
public bool IsDebugDisplayEnabled()
{
return materialDebugSettings.IsDebugDisplayEnabled() || lightingDebugSettings.IsDebugDisplayEnabled();
}
public bool IsDebugMaterialDisplayEnabled()
{
return materialDebugSettings.IsDebugDisplayEnabled();
}
public void SetDebugViewMaterial(int value)
{
if (value != 0)
lightingDebugSettings.debugLightingMode = DebugLightingMode.None;
materialDebugSettings.SetDebugViewMaterial(value);
}
public void SetDebugViewEngine(int value)
{
if (value != 0)
lightingDebugSettings.debugLightingMode = DebugLightingMode.None;
materialDebugSettings.SetDebugViewEngine(value);
}
public void SetDebugViewVarying(Attributes.DebugViewVarying value)
{
if (value != 0)
lightingDebugSettings.debugLightingMode = DebugLightingMode.None;
materialDebugSettings.SetDebugViewVarying(value);
}
public void SetDebugViewGBuffer(int value)
{
if (value != 0)
lightingDebugSettings.debugLightingMode = DebugLightingMode.None;
materialDebugSettings.SetDebugViewGBuffer(value);
}
public void SetDebugLightingMode(DebugLightingMode value)
return debugDisplayMode != DebugDisplayMode.None;
if(value != 0)
materialDebugSettings.DisableMaterialDebug();
lightingDebugSettings.debugLightingMode = value;
public void RegisterDebug()
{

DebugMenuManager.instance.AddDebugItem<int>("Material", "Material",() => materialDebugSettings.debugViewMaterial, (value) => SetDebugViewMaterial((int)value), false, new DebugItemDrawerIntEnum(DebugDisplaySettings.debugViewMaterialStrings, DebugDisplaySettings.debugViewMaterialValues));
DebugMenuManager.instance.AddDebugItem<int>("Material", "Engine",() => materialDebugSettings.debugViewEngine, (value) => SetDebugViewEngine((int)value), false, new DebugItemDrawerIntEnum(DebugDisplaySettings.debugViewEngineStrings, DebugDisplaySettings.debugViewEngineValues));
DebugMenuManager.instance.AddDebugItem<Attributes.DebugViewVarying>("Material", "Attributes",() => materialDebugSettings.debugViewVarying, (value) => SetDebugViewVarying((Attributes.DebugViewVarying)value));
DebugMenuManager.instance.AddDebugItem<int>("Material", "GBuffer",() => materialDebugSettings.debugViewGBuffer, (value) => SetDebugViewGBuffer((int)value), false, new DebugItemDrawerIntEnum(DebugDisplaySettings.debugViewMaterialGBufferStrings, DebugDisplaySettings.debugViewMaterialGBufferValues));
//DebugMenuManager.instance.AddDebugItem<LightingDebugMenu, LightingDebugMode>("Lighting Debug Mode", () => lightingDebugSettings.lightingDebugMode, (value) => lightingDebugSettings.lightingDebugMode = (LightingDebugMode)value);
DebugMenuManager.instance.AddDebugItem<LightingDebugMenu, DebugLightingMode>("Lighting Debug Mode", () => lightingDebugSettings.debugLightingMode, (value) => SetDebugLightingMode((DebugLightingMode)value));
DebugMenuManager.instance.AddDebugItem<LightingDebugMenu, bool>("Override Smoothness", () => lightingDebugSettings.overrideSmoothness, (value) => lightingDebugSettings.overrideSmoothness = (bool)value);
DebugMenuManager.instance.AddDebugItem<LightingDebugMenu, float>("Override Smoothness Value", () => lightingDebugSettings.overrideSmoothnessValue, (value) => lightingDebugSettings.overrideSmoothnessValue = (float)value, false, new DebugItemDrawFloatMinMax(0.0f, 1.0f));
DebugMenuManager.instance.AddDebugItem<LightingDebugMenu, Color>("Debug Lighting Albedo", () => lightingDebugSettings.debugLightingAlbedo, (value) => lightingDebugSettings.debugLightingAlbedo = (Color)value);

{
lightingDebugSettings.OnValidate();
}
void FillWithProperties(Type type, GUIContent[] debugViewMaterialStrings, int[] debugViewMaterialValues, string strSubNameSpace, ref int index)
{
var attributes = type.GetCustomAttributes(true);
// Get attribute to get the start number of the value for the enum
var attr = attributes[0] as GenerateHLSL;
if (!attr.needParamDebug)
{
return;
}
var fields = type.GetFields();
var localIndex = 0;
foreach (var field in fields)
{
var fieldName = field.Name;
// Check if the display name have been override by the users
if (Attribute.IsDefined(field, typeof(SurfaceDataAttributes)))
{
var propertyAttr = (SurfaceDataAttributes[])field.GetCustomAttributes(typeof(SurfaceDataAttributes), false);
if (propertyAttr[0].displayName != "")
{
fieldName = propertyAttr[0].displayName;
}
}
fieldName = strSubNameSpace + fieldName;
debugViewMaterialStrings[index] = new GUIContent(fieldName);
debugViewMaterialValues[index] = attr.paramDefinesStart + (int)localIndex;
index++;
localIndex++;
}
}
void FillWithPropertiesEnum(Type type, GUIContent[] debugViewMaterialStrings, int[] debugViewMaterialValues, string prefix, ref int index)
{
var names = Enum.GetNames(type);
var localIndex = 0;
foreach (var value in Enum.GetValues(type))
{
var valueName = prefix + names[localIndex];
debugViewMaterialStrings[index] = new GUIContent(valueName);
debugViewMaterialValues[index] = (int)value;
index++;
localIndex++;
}
}
string GetSubNameSpaceName(Type type)
{
return type.Namespace.Substring(type.Namespace.LastIndexOf((".")) + 1) + "/";
}
void BuildDebugRepresentation()
{
if (!isDebugViewMaterialInit)
{
var varyingNames = Enum.GetNames(typeof(Attributes.DebugViewVarying));
debugViewMaterialVaryingStrings = new GUIContent[varyingNames.Length];
debugViewMaterialVaryingValues = new int[varyingNames.Length];
var gbufferNames = Enum.GetNames(typeof(Attributes.DebugViewGbuffer));
debugViewMaterialGBufferStrings = new GUIContent[gbufferNames.Length + typeof(Lit.BSDFData).GetFields().Length];
debugViewMaterialGBufferValues = new int[gbufferNames.Length + typeof(Lit.BSDFData).GetFields().Length];
var num = typeof(Builtin.BuiltinData).GetFields().Length * 2 // BuildtinData are duplicated for each material
+ typeof(Lit.SurfaceData).GetFields().Length
+ typeof(Unlit.SurfaceData).GetFields().Length
+ 1; // None
debugViewMaterialStrings = new GUIContent[num];
debugViewMaterialValues = new int[num];
num = typeof(Lit.BSDFData).GetFields().Length
+ typeof(Unlit.BSDFData).GetFields().Length
+ 1; // None
debugViewEngineStrings = new GUIContent[num];
debugViewEngineValues = new int[num];
// Special case for None since it cannot be inferred from SurfaceDAta/BuiltinData
debugViewMaterialStrings[0] = new GUIContent("None");
debugViewMaterialValues[0] = 0;
var index = 1;
// 0 is a reserved number and should not be used (allow to track error)
FillWithProperties(typeof(Builtin.BuiltinData), debugViewMaterialStrings, debugViewMaterialValues, GetSubNameSpaceName(typeof(Lit.SurfaceData)), ref index);
FillWithProperties(typeof(Lit.SurfaceData), debugViewMaterialStrings, debugViewMaterialValues, GetSubNameSpaceName(typeof(Lit.SurfaceData)), ref index);
FillWithProperties(typeof(Builtin.BuiltinData), debugViewMaterialStrings, debugViewMaterialValues, GetSubNameSpaceName(typeof(Unlit.SurfaceData)), ref index);
FillWithProperties(typeof(Unlit.SurfaceData), debugViewMaterialStrings, debugViewMaterialValues, GetSubNameSpaceName(typeof(Unlit.SurfaceData)), ref index);
// Engine
debugViewEngineStrings[0] = new GUIContent("None");
debugViewEngineValues[0] = 0;
index = 1;
FillWithProperties(typeof(Lit.BSDFData), debugViewEngineStrings, debugViewEngineValues, GetSubNameSpaceName(typeof(Lit.BSDFData)), ref index);
FillWithProperties(typeof(Unlit.BSDFData), debugViewEngineStrings, debugViewEngineValues, GetSubNameSpaceName(typeof(Unlit.BSDFData)), ref index);
index = 0;
FillWithPropertiesEnum(typeof(Attributes.DebugViewVarying), debugViewMaterialVaryingStrings, debugViewMaterialVaryingValues, "", ref index);
index = 0;
FillWithPropertiesEnum(typeof(Attributes.DebugViewGbuffer), debugViewMaterialGBufferStrings, debugViewMaterialGBufferValues, "", ref index);
FillWithProperties(typeof(Lit.BSDFData), debugViewMaterialGBufferStrings, debugViewMaterialGBufferValues, "", ref index);
isDebugViewMaterialInit = true;
}
}
}
namespace Attributes

public enum DebugViewVarying
{
None = 0,
Texcoord0 = 1,
Texcoord1,
Texcoord2,

[GenerateHLSL]
public enum DebugViewGbuffer
{
None = 0,
Depth = DebugViewVarying.VertexColorAlpha + 1,
BakeDiffuseLightingWithAlbedoPlusEmissive,
}

public class MaterialDebugSettings
{
public int debugViewMaterial = 0;
public int debugViewMaterial { get { return m_DebugViewMaterial; } }
public int debugViewEngine { get { return m_DebugViewEngine; } }
public Attributes.DebugViewVarying debugViewVarying { get { return m_DebugViewVarying; } }
public int debugViewGBuffer { get { return m_DebugViewGBuffer; } }
int m_DebugViewMaterial = 0; // No enum there because everything is generated from materials.
int m_DebugViewEngine = 0; // No enum there because everything is generated from BSDFData
Attributes.DebugViewVarying m_DebugViewVarying = Attributes.DebugViewVarying.None;
int m_DebugViewGBuffer = 0; // Can't use GBuffer enum here because the values are actually split between this enum and values from Lit.BSDFData
public int GetDebugMaterialIndex()
{
// This value is used in the shader for the actual debug display.
// There is only one uniform parameter for that so we just add all of them
// They are all mutually exclusive so return the sum will return the right index.
return m_DebugViewGBuffer + m_DebugViewMaterial + m_DebugViewEngine + (int)m_DebugViewVarying;
}
public void DisableMaterialDebug()
{
m_DebugViewMaterial = 0;
m_DebugViewEngine = 0;
m_DebugViewVarying = Attributes.DebugViewVarying.None;
m_DebugViewGBuffer = 0;
}
public void SetDebugViewMaterial(int value)
{
if (value != 0)
DisableMaterialDebug();
m_DebugViewMaterial = value;
}
public void SetDebugViewEngine(int value)
{
if (value != 0)
DisableMaterialDebug();
m_DebugViewEngine = value;
}
public void SetDebugViewVarying(Attributes.DebugViewVarying value)
{
if (value != 0)
DisableMaterialDebug();
m_DebugViewVarying = value;
}
public void SetDebugViewGBuffer(int value)
{
if (value != 0)
DisableMaterialDebug();
m_DebugViewGBuffer = value;
}
public bool IsDebugDisplayEnabled()
{
return (m_DebugViewEngine != 0 || m_DebugViewMaterial != 0 || m_DebugViewVarying != Attributes.DebugViewVarying.None || m_DebugViewGBuffer != 0);
}
}
[Serializable]

[Serializable]
public class LightingDebugSettings
{
public bool IsDebugDisplayEnabled()
{
return debugLightingMode != DebugLightingMode.None;
}
public DebugLightingMode debugLightingMode = DebugLightingMode.None;
public bool enableShadows = true;
public ShadowMapDebugMode shadowDebugMode = ShadowMapDebugMode.None;
public uint shadowMapIndex = 0;

13
Assets/ScriptableRenderPipeline/HDRenderPipeline/Debug/DebugDisplay.cs.hlsl


#ifndef DEBUGDISPLAY_CS_HLSL
#define DEBUGDISPLAY_CS_HLSL
//
// UnityEngine.Experimental.Rendering.HDPipeline.DebugDisplayMode: static fields
// UnityEngine.Experimental.Rendering.HDPipeline.DebugLightingMode: static fields
#define DEBUGDISPLAYMODE_NONE (0)
#define DEBUGDISPLAYMODE_VIEW_MATERIAL (1)
#define DEBUGDISPLAYMODE_DIFFUSE_LIGHTING (2)
#define DEBUGDISPLAYMODE_SPECULAR_LIGHTING (3)
#define DEBUGDISPLAYMODE_VISUALIZE_CASCADE (4)
#define DEBUGLIGHTINGMODE_NONE (0)
#define DEBUGLIGHTINGMODE_DIFFUSE_LIGHTING (1)
#define DEBUGLIGHTINGMODE_SPECULAR_LIGHTING (2)
#define DEBUGLIGHTINGMODE_VISUALIZE_CASCADE (3)
#define DEBUGVIEWVARYING_NONE (0)
#define DEBUGVIEWVARYING_TEXCOORD0 (1)
#define DEBUGVIEWVARYING_TEXCOORD1 (2)
#define DEBUGVIEWVARYING_TEXCOORD2 (3)

//
// UnityEngine.Experimental.Rendering.HDPipeline.Attributes.DebugViewGbuffer: static fields
//
#define DEBUGVIEWGBUFFER_NONE (0)
#define DEBUGVIEWGBUFFER_DEPTH (10)
#define DEBUGVIEWGBUFFER_BAKE_DIFFUSE_LIGHTING_WITH_ALBEDO_PLUS_EMISSIVE (11)

2
Assets/ScriptableRenderPipeline/HDRenderPipeline/Debug/DebugDisplay.hlsl


#include "DebugDisplay.cs.hlsl"
// Set of parameters available when switching to debug shader mode
int _DebugDisplayMode; // Match enum DebugDisplayMode
int _DebugLightingMode; // Match enum DebugLightingMode
int _DebugViewMaterial; // Contain the id (define in various materialXXX.cs.hlsl) of the property to display
float4 _DebugLightingAlbedo; // xyz = albedo for diffuse, w unused
float4 _DebugLightingSmoothness; // x == bool override, y == override value

200
Assets/ScriptableRenderPipeline/HDRenderPipeline/Editor/HDRenderPipelineInspector.cs


public readonly GUIContent skyParams = new GUIContent("Sky Settings");
// Debug Display Settings
public readonly GUIContent debugDisplayMode = new GUIContent("Debug Display Mode");
public readonly GUIContent debugging = new GUIContent("Debugging");
public readonly GUIContent debugOverlayRatio = new GUIContent("Overlay Ratio");

public bool isDebugViewMaterialInit = false;
public GUIContent[] debugViewMaterialStrings = null;
public int[] debugViewMaterialValues = null;
public readonly GUIContent debugViewEngine = new GUIContent("DebugView Engine", "Display various properties of Materials.");
public readonly GUIContent debugViewMaterialVarying = new GUIContent("DebugView Attributes", "Display varying input of Materials.");
public readonly GUIContent debugViewMaterialGBuffer = new GUIContent("DebugView GBuffer", "Display GBuffer properties.");
// Rendering Debug
public readonly GUIContent renderingDebugSettings = new GUIContent("Rendering Debug");

// Lighting Debug
public readonly GUIContent lightingDebugSettings = new GUIContent("Lighting Debug");
public readonly GUIContent shadowDebugEnable = new GUIContent("Enable Shadows");
public readonly GUIContent lightingVisualizationMode = new GUIContent("Lighting Debug Mode");
public readonly GUIContent[] debugViewLightingStrings = { new GUIContent("None"), new GUIContent("Diffuse Lighting"), new GUIContent("Specular Lighting"), new GUIContent("Visualize Cascades") };
public readonly int[] debugViewLightingValues = { (int)DebugLightingMode.None, (int)DebugLightingMode.DiffuseLighting, (int)DebugLightingMode.SpecularLighting, (int)DebugLightingMode.VisualizeCascade };
public readonly GUIContent shadowDebugVisualizationMode = new GUIContent("Shadow Maps Debug Mode");
public readonly GUIContent shadowDebugVisualizeShadowIndex = new GUIContent("Visualize Shadow Index");
public readonly GUIContent lightingDebugOverrideSmoothness = new GUIContent("Override Smoothness");

}
// Display Debug
SerializedProperty m_DebugDisplayMode = null;
// Material Debug
SerializedProperty m_MaterialDebugMode = null;
// Rendering Debug
SerializedProperty m_DisplayOpaqueObjects = null;
SerializedProperty m_DisplayTransparentObjects = null;

private void InitializeProperties()
{
// DebugDisplay debug
m_DebugDisplayMode = FindProperty(x => x.debugDisplaySettings.debugDisplayMode);
// Material debug
m_MaterialDebugMode = FindProperty(x => x.debugDisplaySettings.materialDebugSettings.debugViewMaterial);
// Rendering debug
m_DisplayOpaqueObjects = FindProperty(x => x.debugDisplaySettings.renderingDebugSettings.displayOpaqueObjects);
m_DisplayTransparentObjects = FindProperty(x => x.debugDisplaySettings.renderingDebugSettings.displayTransparentObjects);

return serializedObject.FindProperty(path);
}
string GetSubNameSpaceName(Type type)
{
return type.Namespace.Substring(type.Namespace.LastIndexOf((".")) + 1) + "/";
}
void FillWithProperties(Type type, GUIContent[] debugViewMaterialStrings, int[] debugViewMaterialValues, bool isBSDFData, string strSubNameSpace, ref int index)
{
var attributes = type.GetCustomAttributes(true);
// Get attribute to get the start number of the value for the enum
var attr = attributes[0] as GenerateHLSL;
if (!attr.needParamDebug)
{
return;
}
var fields = type.GetFields();
var localIndex = 0;
foreach (var field in fields)
{
var fieldName = field.Name;
// Check if the display name have been override by the users
if (Attribute.IsDefined(field, typeof(SurfaceDataAttributes)))
{
var propertyAttr = (SurfaceDataAttributes[])field.GetCustomAttributes(typeof(SurfaceDataAttributes), false);
if (propertyAttr[0].displayName != "")
{
fieldName = propertyAttr[0].displayName;
}
}
fieldName = (isBSDFData ? "Engine/" : "") + strSubNameSpace + fieldName;
debugViewMaterialStrings[index] = new GUIContent(fieldName);
debugViewMaterialValues[index] = attr.paramDefinesStart + (int)localIndex;
index++;
localIndex++;
}
}
void FillWithPropertiesEnum(Type type, GUIContent[] debugViewMaterialStrings, int[] debugViewMaterialValues, string prefix, bool isBSDFData, ref int index)
{
var names = Enum.GetNames(type);
var localIndex = 0;
foreach (var value in Enum.GetValues(type))
{
var valueName = (isBSDFData ? "Engine/" : "" + prefix) + names[localIndex];
debugViewMaterialStrings[index] = new GUIContent(valueName);
debugViewMaterialValues[index] = (int)value;
index++;
localIndex++;
}
}
static void HackSetDirty(RenderPipelineAsset asset)
{
EditorUtility.SetDirty(asset);

// Debug Display settings
EditorGUI.indentLevel++;
EditorGUILayout.PropertyField(m_DebugDisplayMode, styles.debugDisplayMode);
if ((DebugDisplayMode)m_DebugDisplayMode.intValue == DebugDisplayMode.ViewMaterial)
{
MaterialDebugSettingsUI(renderContext);
}
else
{
LightingDebugSettingsUI(renderContext, renderpipelineInstance);
}
MaterialDebugSettingsUI(renderContext);
LightingDebugSettingsUI(renderContext, renderpipelineInstance);
EditorGUILayout.Space();

private void MaterialDebugSettingsUI(HDRenderPipeline renderContext)
{
HDRenderPipeline hdPipe = target as HDRenderPipeline;
bool dirty = false;
if (!styles.isDebugViewMaterialInit)
int value = EditorGUILayout.IntPopup(styles.debugViewMaterial, hdPipe.debugDisplaySettings.materialDebugSettings.debugViewMaterial, DebugDisplaySettings.debugViewMaterialStrings, DebugDisplaySettings.debugViewMaterialValues);
if (EditorGUI.EndChangeCheck())
var varyingNames = Enum.GetNames(typeof(Attributes.DebugViewVarying));
var gbufferNames = Enum.GetNames(typeof(Attributes.DebugViewGbuffer));
var num = varyingNames.Length
+ gbufferNames.Length
+ typeof(Builtin.BuiltinData).GetFields().Length * 2 // BuildtinData are duplicated for each material
+ typeof(Lit.SurfaceData).GetFields().Length
+ typeof(Lit.BSDFData).GetFields().Length
+ typeof(Unlit.SurfaceData).GetFields().Length
+ typeof(Unlit.BSDFData).GetFields().Length;
styles.debugViewMaterialStrings = new GUIContent[num];
styles.debugViewMaterialValues = new int[num];
var index = 0;
// 0 is a reserved number and should not be used (allow to track error)
FillWithPropertiesEnum(typeof(Attributes.DebugViewVarying), styles.debugViewMaterialStrings, styles.debugViewMaterialValues, GetSubNameSpaceName(typeof(Attributes.DebugViewVarying)), false, ref index);
FillWithProperties(typeof(Builtin.BuiltinData), styles.debugViewMaterialStrings, styles.debugViewMaterialValues, false, GetSubNameSpaceName(typeof(Lit.SurfaceData)), ref index);
FillWithProperties(typeof(Lit.SurfaceData), styles.debugViewMaterialStrings, styles.debugViewMaterialValues, false, GetSubNameSpaceName(typeof(Lit.SurfaceData)), ref index);
FillWithProperties(typeof(Builtin.BuiltinData), styles.debugViewMaterialStrings, styles.debugViewMaterialValues, false, GetSubNameSpaceName(typeof(Unlit.SurfaceData)), ref index);
FillWithProperties(typeof(Unlit.SurfaceData), styles.debugViewMaterialStrings, styles.debugViewMaterialValues, false, GetSubNameSpaceName(typeof(Unlit.SurfaceData)), ref index);
// Engine
FillWithPropertiesEnum(typeof(Attributes.DebugViewGbuffer), styles.debugViewMaterialStrings, styles.debugViewMaterialValues, "", true, ref index);
FillWithProperties(typeof(Lit.BSDFData), styles.debugViewMaterialStrings, styles.debugViewMaterialValues, true, "", ref index);
FillWithProperties(typeof(Unlit.BSDFData), styles.debugViewMaterialStrings, styles.debugViewMaterialValues, true, "", ref index);
hdPipe.debugDisplaySettings.SetDebugViewMaterial(value);
dirty = true;
}
styles.isDebugViewMaterialInit = true;
EditorGUI.BeginChangeCheck();
value = EditorGUILayout.IntPopup(styles.debugViewEngine, hdPipe.debugDisplaySettings.materialDebugSettings.debugViewEngine, DebugDisplaySettings.debugViewEngineStrings, DebugDisplaySettings.debugViewEngineValues);
if (EditorGUI.EndChangeCheck())
{
hdPipe.debugDisplaySettings.SetDebugViewEngine(value);
dirty = true;
EditorGUI.showMixedValue = m_MaterialDebugMode.hasMultipleDifferentValues;
m_MaterialDebugMode.intValue = EditorGUILayout.IntPopup(styles.debugViewMaterial, m_MaterialDebugMode.intValue, styles.debugViewMaterialStrings, styles.debugViewMaterialValues);
EditorGUI.showMixedValue = false;
EditorGUI.BeginChangeCheck();
value = EditorGUILayout.IntPopup(styles.debugViewMaterialVarying, (int)hdPipe.debugDisplaySettings.materialDebugSettings.debugViewVarying, DebugDisplaySettings.debugViewMaterialVaryingStrings, DebugDisplaySettings.debugViewMaterialVaryingValues);
if (EditorGUI.EndChangeCheck())
{
hdPipe.debugDisplaySettings.SetDebugViewVarying((Attributes.DebugViewVarying)value);
dirty = true;
}
EditorGUI.BeginChangeCheck();
value = EditorGUILayout.IntPopup(styles.debugViewMaterialGBuffer, (int)hdPipe.debugDisplaySettings.materialDebugSettings.debugViewGBuffer, DebugDisplaySettings.debugViewMaterialGBufferStrings, DebugDisplaySettings.debugViewMaterialGBufferValues);
HackSetDirty(renderContext); // Repaint
hdPipe.debugDisplaySettings.SetDebugViewGBuffer(value);
dirty = true;
if(dirty)
HackSetDirty(renderContext); // Repaint
EditorGUI.indentLevel--;
}

if (!m_ShowLightingDebug.boolValue)
return;
EditorGUI.BeginChangeCheck();
HDRenderPipeline hdPipe = target as HDRenderPipeline;
bool dirty = false;
EditorGUI.BeginChangeCheck();
EditorGUI.indentLevel++;
EditorGUILayout.PropertyField(m_DebugShadowEnabled, styles.shadowDebugEnable);
EditorGUILayout.PropertyField(m_ShadowDebugMode, styles.shadowDebugVisualizationMode);

EditorGUILayout.IntSlider(m_ShadowDebugShadowMapIndex, 0, renderpipelineInstance.GetCurrentShadowCount() - 1, styles.shadowDebugVisualizeShadowIndex);
}
}
if (EditorGUI.EndChangeCheck())
{
dirty = true;
}
if (!m_DebugDisplayMode.hasMultipleDifferentValues)
EditorGUI.BeginChangeCheck();
int value = EditorGUILayout.IntPopup(styles.lightingVisualizationMode, (int)hdPipe.debugDisplaySettings.lightingDebugSettings.debugLightingMode, styles.debugViewLightingStrings, styles.debugViewLightingValues);
if (EditorGUI.EndChangeCheck())
if ((DebugDisplayMode)m_DebugDisplayMode.intValue == DebugDisplayMode.DiffuseLighting)
{
EditorGUI.indentLevel++;
EditorGUILayout.PropertyField(m_LightingDebugAlbedo, styles.lightingDebugAlbedo);
EditorGUI.indentLevel--;
}
hdPipe.debugDisplaySettings.SetDebugLightingMode((DebugLightingMode)value);
dirty = true;
}
if ((DebugDisplayMode)m_DebugDisplayMode.intValue == DebugDisplayMode.SpecularLighting)
EditorGUI.BeginChangeCheck();
if (hdPipe.debugDisplaySettings.GetDebugLightingMode() == DebugLightingMode.DiffuseLighting)
{
EditorGUI.indentLevel++;
EditorGUILayout.PropertyField(m_LightingDebugAlbedo, styles.lightingDebugAlbedo);
EditorGUI.indentLevel--;
}
if (hdPipe.debugDisplaySettings.GetDebugLightingMode() == DebugLightingMode.SpecularLighting)
{
EditorGUI.indentLevel++;
EditorGUILayout.PropertyField(m_LightingDebugOverrideSmoothness, styles.lightingDebugOverrideSmoothness);
if (!m_LightingDebugOverrideSmoothness.hasMultipleDifferentValues && m_LightingDebugOverrideSmoothness.boolValue == true)
EditorGUILayout.PropertyField(m_LightingDebugOverrideSmoothness, styles.lightingDebugOverrideSmoothness);
if (!m_LightingDebugOverrideSmoothness.hasMultipleDifferentValues && m_LightingDebugOverrideSmoothness.boolValue == true)
{
EditorGUI.indentLevel++;
EditorGUILayout.PropertyField(m_LightingDebugOverrideSmoothnessValue, styles.lightingDebugOverrideSmoothnessValue);
EditorGUI.indentLevel--;
}
EditorGUILayout.PropertyField(m_LightingDebugOverrideSmoothnessValue, styles.lightingDebugOverrideSmoothnessValue);
EditorGUI.indentLevel--;
}
EditorGUILayout.PropertyField(m_LightingDebugDisplaySkyReflection, styles.lightingDisplaySkyReflection);

if (EditorGUI.EndChangeCheck())
{
dirty = true;
}
if(dirty)
}
}
private void SettingsUI(HDRenderPipeline renderContext)

12
Assets/ScriptableRenderPipeline/HDRenderPipeline/HDRenderPipeline.cs


Vector4 debugAlbedo = new Vector4(lightingDebugSettings.debugLightingAlbedo.r, lightingDebugSettings.debugLightingAlbedo.g, lightingDebugSettings.debugLightingAlbedo.b, 0.0f);
Vector4 debugSmoothness = new Vector4(lightingDebugSettings.overrideSmoothness ? 1.0f : 0.0f, lightingDebugSettings.overrideSmoothnessValue, 0.0f, 0.0f);
Shader.SetGlobalInt("_DebugDisplayMode", (int)debugDisplaySettings.debugDisplayMode);
Shader.SetGlobalInt("_DebugViewMaterial", (int)debugDisplaySettings.materialDebugSettings.debugViewMaterial);
Shader.SetGlobalInt("_DebugViewMaterial", (int)debugDisplaySettings.GetDebugMaterialIndex());
Shader.SetGlobalInt("_DebugLightingMode", (int)debugDisplaySettings.GetDebugLightingMode());
Shader.SetGlobalVector("_DebugLightingAlbedo", debugAlbedo);
Shader.SetGlobalVector("_DebugLightingSmoothness", debugSmoothness);
}

CopyDepthBufferIfNeeded(renderContext);
}
if (debugDisplaySettings.debugDisplayMode == DebugDisplayMode.ViewMaterial)
if (debugDisplaySettings.IsDebugMaterialDisplayEnabled())
{
RenderDebugViewMaterial(cullResults, hdCamera, renderContext);
}

return;
}
string passName = debugDisplaySettings.IsDebugDisplayEnable() ? "GBufferDebugDisplay" : "GBuffer";
string passName = debugDisplaySettings.IsDebugDisplayEnabled() ? "GBufferDebugDisplay" : "GBuffer";
using (new Utilities.ProfilingSample(passName, renderContext))
{

if (!m_Owner.renderingSettings.ShouldUseForwardRenderingOnly() && renderOpaque)
return;
string passName = debugDisplaySettings.IsDebugDisplayEnable() ? "ForwardDisplayDebug" : "Forward";
string passName = debugDisplaySettings.IsDebugDisplayEnabled() ? "ForwardDisplayDebug" : "Forward";
using (new Utilities.ProfilingSample(passName, renderContext))
{

// Render material that are forward opaque only (like eye), this include unlit material
void RenderForwardOnlyOpaque(CullResults cullResults, Camera camera, ScriptableRenderContext renderContext)
{
string passName = debugDisplaySettings.IsDebugDisplayEnable() ? "ForwardOnlyOpaqueDisplayDebug" : "ForwardOnlyOpaque";
string passName = debugDisplaySettings.IsDebugDisplayEnabled() ? "ForwardOnlyOpaqueDisplayDebug" : "ForwardOnlyOpaque";
using (new Utilities.ProfilingSample(passName, renderContext))
{

7
Assets/ScriptableRenderPipeline/HDRenderPipeline/Lighting/TilePass/TilePass.cs


var camera = hdCamera.camera;
SetupDebugDisplayMode(debugDisplaySettings.IsDebugDisplayEnable());
SetupDebugDisplayMode(debugDisplaySettings.IsDebugDisplayEnabled());
if (!m_PassSettings.enableTileAndCluster)
{

if (m_PassSettings.enableComputeLightEvaluation)
{
bool enableFeatureVariants = GetFeatureVariantsEnabled() && !debugDisplaySettings.IsDebugDisplayEnable();
bool enableFeatureVariants = GetFeatureVariantsEnabled() && !debugDisplaySettings.IsDebugDisplayEnabled();
int numVariants = 1;
if (enableFeatureVariants)

}
else
{
if (debugDisplaySettings.IsDebugDisplayEnable())
if (debugDisplaySettings.IsDebugDisplayEnabled())
{
kernel = usingFptl ? s_shadeOpaqueDirectFptlDebugDisplayKernel : s_shadeOpaqueDirectClusteredDebugDisplayKernel;
}

PushGlobalParams(camera, renderContext, shadeOpaqueShader, kernel);
// TODO: Update value like in ApplyDebugDisplaySettings() call. Sadly it is high likely that this will not be keep in sync. we really need to get rid of this by making global parameters visible to compute shaders
cmd.SetComputeIntParam(shadeOpaqueShader, "_DebugDisplayMode", Shader.GetGlobalInt("_DebugDisplayMode"));
cmd.SetComputeIntParam(shadeOpaqueShader, "_DebugViewMaterial", Shader.GetGlobalInt("_DebugViewMaterial"));
cmd.SetComputeVectorParam(shadeOpaqueShader, "_DebugLightingAlbedo", Shader.GetGlobalVector("_DebugLightingAlbedo"));
cmd.SetComputeVectorParam(shadeOpaqueShader, "_DebugLightingSmoothness", Shader.GetGlobalVector("_DebugLightingSmoothness"));

6
Assets/ScriptableRenderPipeline/HDRenderPipeline/Lighting/TilePass/TilePassLoop.hlsl


void ApplyDebug(LightLoopContext lightLoopContext, float3 positionWS, inout float3 diffuseLighting, inout float3 specularLighting)
{
#ifdef DEBUG_DISPLAY
if (_DebugDisplayMode == DEBUGDISPLAYMODE_DIFFUSE_LIGHTING)
if (_DebugLightingMode == DEBUGLIGHTINGMODE_DIFFUSE_LIGHTING)
else if (_DebugDisplayMode == DEBUGDISPLAYMODE_SPECULAR_LIGHTING)
else if (_DebugLightingMode == DEBUGLIGHTINGMODE_SPECULAR_LIGHTING)
else if (_DebugDisplayMode == DEBUGDISPLAYMODE_VISUALIZE_CASCADE)
else if (_DebugLightingMode == DEBUGLIGHTINGMODE_VISUALIZE_CASCADE)
{
specularLighting = float3(0.0, 0.0, 0.0);

4
Assets/ScriptableRenderPipeline/HDRenderPipeline/Material/Lit/Lit.hlsl


void ApplyDebugToBSDFData(inout BSDFData bsdfData)
{
#ifdef DEBUG_DISPLAY
if (_DebugDisplayMode == DEBUGDISPLAYMODE_SPECULAR_LIGHTING)
if (_DebugLightingMode == DEBUGLIGHTINGMODE_SPECULAR_LIGHTING)
{
bool overrideSmoothness = _DebugLightingSmoothness.x != 0.0;
float overrideSmoothnessValue = _DebugLightingSmoothness.y;

}
}
if (_DebugDisplayMode == DEBUGDISPLAYMODE_DIFFUSE_LIGHTING)
if (_DebugLightingMode == DEBUGLIGHTINGMODE_DIFFUSE_LIGHTING)
{
bsdfData.diffuseColor = _DebugLightingAlbedo.xyz;
}

2
Assets/ScriptableRenderPipeline/HDRenderPipeline/ShaderPass/ShaderPassForward.hlsl


#endif
#ifdef DEBUG_DISPLAY
if (_DebugDisplayMode == DEBUGDISPLAYMODE_VIEW_MATERIAL)
if (_DebugViewMaterial != 0)
{
float3 result = float3(1.0, 0.0, 1.0);
bool needLinearToSRGB = false;

42
Assets/ScriptableRenderPipeline/common/Debugging/DebugItemDrawer.cs


protected DebugMenuItem m_MenuItem = null;
// Label for simple GUI items
GUIContent m_Label;
List<GUIContent> m_EnumStrings = null;
List<int> m_EnumValues = null;
protected GUIContent m_Label;
protected List<GUIContent> m_EnumStrings = null;
protected List<int> m_EnumValues = null;
public DebugItemDrawer()
{

}
else if (m_MenuItem.GetItemType().BaseType == typeof(System.Enum))
{
newItemUI = new DebugMenuEnumItemUI(parent, menuItem, m_Label.text, m_EnumStrings, m_EnumValues);
newItemUI = new DebugMenuEnumItemUI(parent, menuItem, m_Label.text, m_EnumStrings.ToArray(), m_EnumValues.ToArray());
}
return newItemUI;

}
#endif
}
public class DebugItemDrawerIntEnum
: DebugItemDrawer
{
GUIContent[] m_EnumStrings = null;
int[] m_EnumValues = null;
public DebugItemDrawerIntEnum(GUIContent[] enumStrings, int[] enumValues)
{
m_EnumStrings = enumStrings;
m_EnumValues = enumValues;
}
public override DebugMenuItemUI BuildGUI(GameObject parent, DebugMenuItem menuItem)
{
return new DebugMenuEnumItemUI(parent, menuItem, m_Label.text, m_EnumStrings, m_EnumValues);
}
#if UNITY_EDITOR
public override bool OnEditorGUI()
{
UnityEditor.EditorGUI.BeginChangeCheck();
int value = UnityEditor.EditorGUILayout.IntPopup(m_Label, (int)m_MenuItem.GetValue(), m_EnumStrings, m_EnumValues);
if (UnityEditor.EditorGUI.EndChangeCheck())
{
m_MenuItem.SetValue(value);
return true;
}
return false;
}
#endif
}
}

16
Assets/ScriptableRenderPipeline/common/Debugging/DebugMenuItemUI.cs


public class DebugMenuEnumItemUI : DebugMenuSimpleItemUI
{
int m_CurrentValueIndex = 0;
List<GUIContent> m_ValueNames;
List<int> m_Values;
GUIContent[] m_ValueNames;
int[] m_Values;
public DebugMenuEnumItemUI(GameObject parent, DebugMenuItem menuItem, string name, List<GUIContent> valueNames, List<int> values)
public DebugMenuEnumItemUI(GameObject parent, DebugMenuItem menuItem, string name, GUIContent[] valueNames, int[] values)
: base(parent, menuItem, name)
{
m_Values = values;

private int FindIndexForValue(int value)
{
for(int i = 0 ; i < m_Values.Count ; ++i)
for(int i = 0 ; i < m_Values.Length ; ++i)
{
if (m_Values[i] == value)
return i;

public override void OnIncrement()
{
m_CurrentValueIndex = (m_CurrentValueIndex + 1) % m_Values.Count;
m_MenuItem.SetValue(m_CurrentValueIndex);
m_CurrentValueIndex = (m_CurrentValueIndex + 1) % m_Values.Length;
m_MenuItem.SetValue(m_Values[m_CurrentValueIndex]);
Update();
}

if (m_CurrentValueIndex < 0)
m_CurrentValueIndex = m_Values.Count - 1;
m_CurrentValueIndex = m_Values.Length - 1;
m_MenuItem.SetValue(m_CurrentValueIndex);
m_MenuItem.SetValue(m_Values[m_CurrentValueIndex]);
Update();
}
}

正在加载...
取消
保存