浏览代码

Merge pull request #292 from Unity-Technologies/Branch_DebugMenu2

Branch debugmenu2
/RenderPassXR_Sandbox
GitHub 8 年前
当前提交
fb10c3b0
共有 21 个文件被更改,包括 376 次插入138 次删除
  1. 2
      Assets/ScriptableRenderPipeline/Core/Camera/CameraSwitcher.cs
  2. 28
      Assets/ScriptableRenderPipeline/Core/Debugging/DebugActionManager.cs
  3. 40
      Assets/ScriptableRenderPipeline/Core/Debugging/DebugItemHandler.cs
  4. 2
      Assets/ScriptableRenderPipeline/Core/Debugging/DebugItemUI.cs
  5. 8
      Assets/ScriptableRenderPipeline/Core/Debugging/DebugMenuManager.cs
  6. 5
      Assets/ScriptableRenderPipeline/Core/Debugging/DebugMenuUI.cs
  7. 22
      Assets/ScriptableRenderPipeline/Core/Debugging/DebugPanel.cs
  8. 10
      Assets/ScriptableRenderPipeline/Core/Debugging/DebugPanelUI.cs
  9. 4
      Assets/ScriptableRenderPipeline/Core/Debugging/Editor/DebugMenuEditor.cs
  10. 115
      Assets/ScriptableRenderPipeline/Core/Shadow/Shadow.cs
  11. 38
      Assets/ScriptableRenderPipeline/Core/Shadow/ShadowBase.cs
  12. 22
      Assets/ScriptableRenderPipeline/HDRenderPipeline/Debug/DebugDisplay.cs
  13. 47
      Assets/ScriptableRenderPipeline/HDRenderPipeline/Debug/LightingDebugPanel.cs
  14. 11
      Assets/ScriptableRenderPipeline/HDRenderPipeline/HDRenderPipeline.cs
  15. 57
      Assets/ScriptableRenderPipeline/HDRenderPipeline/Lighting/TilePass/TilePass.cs
  16. 2
      Assets/ScriptableRenderPipeline/HDRenderPipeline/RenderPipelineResources/RenderPipelineResources.cs
  17. 92
      Assets/ScriptableRenderPipeline/Core/Shadow/Resources/DebugDisplayShadowMap.shader
  18. 9
      Assets/ScriptableRenderPipeline/Core/Shadow/Resources.meta
  19. 0
      /Assets/ScriptableRenderPipeline/Core/Shadow/Resources/DebugDisplayShadowMap.shader.meta
  20. 0
      /Assets/ScriptableRenderPipeline/Core/Shadow/Resources/DebugDisplayShadowMap.shader

2
Assets/ScriptableRenderPipeline/Core/Camera/CameraSwitcher.cs


m_CameraNames[GetCameraCount() - 1] = new GUIContent("Original Camera");
m_CameraIndices[GetCameraCount() - 1] = GetCameraCount() - 1;
DebugMenuManager.instance.AddDebugItem<int>("Camera", "Camera Switcher", () => m_CurrentCameraIndex, (value) => SetCameraIndex((int)value), false, new DebugItemHandlerIntEnum(m_CameraNames, m_CameraIndices));
DebugMenuManager.instance.AddDebugItem<int>("Camera", "Camera Switcher", () => m_CurrentCameraIndex, (value) => SetCameraIndex((int)value), DebugItemFlag.None, new DebugItemHandlerIntEnum(m_CameraNames, m_CameraIndices));
}
int GetCameraCount()

28
Assets/ScriptableRenderPipeline/Core/Debugging/DebugActionManager.cs


public enum Axis { X, Y, Third, Fourth, Fifth, Sixth, Seventh, Eigth }
public enum Joy { All, First, Second }
public string name;
public string desc;
public string btnNegative;
public string btnPositive;
public string altBtnNegative;
public string altBtnPositive;
public float gravity;
public float deadZone;
public float sensitivity;
public bool snap;
public bool invert;
public Kind kind;
public Axis axis;
public Joy joystick;
public string name = "";
public string desc = "";
public string btnNegative = "";
public string btnPositive = "";
public string altBtnNegative = "";
public string altBtnPositive = "";
public float gravity = 0.0f;
public float deadZone = 0.0f;
public float sensitivity = 0.0f;
public bool snap = false;
public bool invert = false;
public Kind kind = Kind.Axis;
public Axis axis = Axis.X;
public Joy joystick = Joy.All;
bool InputAlreadyRegistered(string name, Kind kind, UnityEditor.SerializedProperty spAxes)
{

40
Assets/ScriptableRenderPipeline/Core/Debugging/DebugItemHandler.cs


public class DebugItemHandlerFloatMinMax
: DefaultDebugItemHandler
{
float m_Min = 0.0f;
float m_Max = 1.0f;
protected float m_Min = 0.0f;
protected float m_Max = 1.0f;
public DebugItemHandlerFloatMinMax(float min, float max)
{
m_Min = min;

if (EditorGUI.EndChangeCheck())
{
m_DebugItem.SetValue(value);
return true;
}
return false;
}
#endif
}
public class DebugItemHandlerUIntMinMax
: DefaultDebugItemHandler
{
protected uint m_Min = 0;
protected uint m_Max = 1;
public DebugItemHandlerUIntMinMax(uint min, uint max)
{
m_Min = min;
m_Max = max;
}
public override void ClampValues(Func<object> getter, Action<object> setter)
{
setter(Math.Min(m_Max, Math.Max(m_Min, (uint)getter())));
}
#if UNITY_EDITOR
public override bool OnEditorGUIImpl()
{
Initialize();
EditorGUI.BeginChangeCheck();
int value = EditorGUILayout.IntSlider(m_DebugItem.name, (int)(uint)m_DebugItem.GetValue(), (int)m_Min, (int)m_Max);
if (EditorGUI.EndChangeCheck())
{
m_DebugItem.SetValue((uint)value);
return true;
}

2
Assets/ScriptableRenderPipeline/Core/Debugging/DebugItemUI.cs


protected GameObject m_Root = null;
protected DebugItem m_DebugItem = null;
public bool dynamicDisplay { get { return m_DebugItem.dynamicDisplay; } }
public bool dynamicDisplay { get { return (m_DebugItem.flags & DebugItemFlag.DynamicDisplay) != 0; } }
protected DebugItemUI(DebugItem debugItem)
{

8
Assets/ScriptableRenderPipeline/Core/Debugging/DebugMenuManager.cs


m_DebugMenuUI.AddDebugPanel(panel);
}
public void AddDebugItem<DebugPanelType, DebugItemType>(string name, Func<object> getter, Action<object> setter = null, bool dynamicDisplay = false, DebugItemHandler handler = null) where DebugPanelType : DebugPanel
public void AddDebugItem<DebugPanelType, DebugItemType>(string name, Func<object> getter, Action<object> setter = null, DebugItemFlag flags = DebugItemFlag.None, DebugItemHandler handler = null) where DebugPanelType : DebugPanel
debugPanel.AddDebugItem<DebugItemType>(name, getter, setter, dynamicDisplay, handler);
debugPanel.AddDebugItem<DebugItemType>(name, getter, setter, flags, handler);
public void AddDebugItem<DebugItemType>(string debugPanelName, string name, Func<object> getter, Action<object> setter = null, bool dynamicDisplay = false, DebugItemHandler handler = null)
public void AddDebugItem<DebugItemType>(string debugPanelName, string name, Func<object> getter, Action<object> setter = null, DebugItemFlag flags = DebugItemFlag.None, DebugItemHandler handler = null)
{
DebugPanel debugPanel = GetDebugPanel(debugPanelName);
// If the menu does not exist, create a generic one. This way, users don't have to explicitely create a new DebugMenu class if they don't need any particular overriding of default behavior.

if (debugPanel != null)
{
debugPanel.AddDebugItem<DebugItemType>(name, getter, setter, dynamicDisplay, handler);
debugPanel.AddDebugItem<DebugItemType>(name, getter, setter, flags, handler);
}
m_DebugMenuStateDirty = true;

5
Assets/ScriptableRenderPipeline/Core/Debugging/DebugMenuUI.cs


m_PersistentPanelRoot.SetActive(false);
DebugMenuUI.CreateTextElement("DebugMenuTitle", "Debug Menu", 14, TextAnchor.MiddleCenter, m_MainPanelLayout);
DebugMenuUI.CreateTextElement("DebugMenuTitle", "Debug Window", 14, TextAnchor.MiddleCenter, m_MainPanelLayout);
m_DebugMenuManager.GetPersistentDebugPanel().panelUI.BuildGUI(m_PersistentPanelLayout);
m_PersistentDebugPanelUI = m_DebugMenuManager.GetPersistentDebugPanel().panelUI;

public void OnEditorGUI()
{
s_UIChanged = false;
m_DebugPanelUIs[m_ActivePanelIndex].OnEditorGUI();
if(!m_DebugPanelUIs[m_ActivePanelIndex].empty)
m_DebugPanelUIs[m_ActivePanelIndex].OnEditorGUI();
if(s_UIChanged)
{
UnityEditorInternal.InternalEditorUtility.RepaintAllViews();

22
Assets/ScriptableRenderPipeline/Core/Debugging/DebugPanel.cs


namespace UnityEngine.Experimental.Rendering
{
[Flags]
public enum DebugItemFlag
{
None,
DynamicDisplay,
EditorOnly
}
public class DebugItem
{
static public event Action<DebugItem> OnItemDirty;

public string panelName { get { return m_PanelName; } }
public DebugItemHandler handler { get { return m_Handler; } }
public bool dynamicDisplay { get { return m_DynamicDisplay; } }
public DebugItemHandler handler { get { return m_Handler; } }
public DebugItemFlag flags { get { return m_Flags; } }
public DebugItem(string name, string panelName, Type type, Func<object> getter, Action<object> setter, bool dynamicDisplay = false, DebugItemHandler handler = null)
public DebugItem(string name, string panelName, Type type, Func<object> getter, Action<object> setter, DebugItemFlag flags = DebugItemFlag.None, DebugItemHandler handler = null)
{
m_Type = type;
m_Setter = setter;

m_Handler = handler;
m_DynamicDisplay = dynamicDisplay;
m_Flags = flags;
}
public Type GetItemType()

string m_Name;
string m_PanelName;
DebugItemHandler m_Handler = null;
bool m_DynamicDisplay = false;
DebugItemFlag m_Flags = DebugItemFlag.None;
}
public class DebugPanel

m_DebugPanelUI.RebuildGUI();
}
public void AddDebugItem<ItemType>(string itemName, Func<object> getter, Action<object> setter, bool dynamicDisplay = false, DebugItemHandler handler = null)
public void AddDebugItem<ItemType>(string itemName, Func<object> getter, Action<object> setter, DebugItemFlag flags = DebugItemFlag.None, DebugItemHandler handler = null)
{
if (handler == null)
handler = new DefaultDebugItemHandler();

RemoveDebugItem(oldItem);
DebugItem newItem = new DebugItem(itemName, m_Name, typeof(ItemType), getter, setter, dynamicDisplay, handler);
DebugItem newItem = new DebugItem(itemName, m_Name, typeof(ItemType), getter, setter, flags, handler);
handler.SetDebugItem(newItem);
m_Items.Add(newItem);
}

10
Assets/ScriptableRenderPipeline/Core/Debugging/DebugPanelUI.cs


protected List<DebugItemUI> m_ItemsUI = new List<DebugItemUI>();
protected int m_SelectedItem = -1;
public bool empty { get { return m_DebugPanel.itemCount == 0; } }
public int itemCount { get { return m_ItemsUI.Count; } }
public DebugPanelUI()

m_ItemsUI.Clear();
for (int i = 0; i < m_DebugPanel.itemCount; i++)
{
DebugItemHandler handler = m_DebugPanel.GetDebugItem(i).handler; // Should never be null, we have at least the default handler
m_ItemsUI.Add(handler.BuildGUI(parent));
DebugItem item = m_DebugPanel.GetDebugItem(i);
if(!((item.flags & DebugItemFlag.EditorOnly) != 0))
{
DebugItemHandler handler = item.handler; // Should never be null, we have at least the default handler
m_ItemsUI.Add(handler.BuildGUI(parent));
}
}
}

4
Assets/ScriptableRenderPipeline/Core/Debugging/Editor/DebugMenuEditor.cs


[SerializeField]
private DebugMenuState m_DebugMenuState;
[MenuItem("HDRenderPipeline/Debug Menu")]
[MenuItem("HDRenderPipeline/Debug Window")]
var window = EditorWindow.GetWindow<DebugMenuEditor>("Debug Menu");
var window = EditorWindow.GetWindow<DebugMenuEditor>("Debug Window");
window.Show();
}

115
Assets/ScriptableRenderPipeline/Core/Shadow/Shadow.cs


protected uint[] m_TmpHeights = new uint[ShadowmapBase.ShadowRequest.k_MaxFaceCount];
protected Vector4[] m_TmpSplits = new Vector4[k_MaxCascadesInShader];
protected ShadowAlgoVector m_SupportedAlgorithms = new ShadowAlgoVector( 0, false );
protected Material m_DebugMaterial = null;
protected struct Key
{

public void Initialize( AtlasInit init )
{
m_ShaderKeyword = init.shaderKeyword;
m_ShaderKeyword = init.shaderKeyword;
m_DebugMaterial = new Material(Shader.Find("Hidden/ScriptableRenderPipeline/DebugDisplayShadowMap")) { hideFlags = HideFlags.HideAndDontSave };
}
override public void ReserveSlots( ShadowContextStorage sc )

{
if( m_Shadowmap != null )
m_Shadowmap.Release();
Object.DestroyImmediate(m_DebugMaterial);
}
override public bool Reserve( FrameId frameId, ref ShadowData shadowData, ShadowRequest sr, uint width, uint height, ref VectorArray<ShadowData> entries, ref VectorArray<ShadowPayload> payload, VisibleLight[] lights )

{
// Nothing to do for this implementation here, as the atlas is reconstructed each frame, instead of keeping state across frames
}
override public void DisplayShadowMap(ScriptableRenderContext renderContext, Vector4 scaleBias, uint slice, float screenX, float screenY, float screenSizeX, float screenSizeY)
{
CommandBuffer debugCB = new CommandBuffer();
debugCB.name = "";
MaterialPropertyBlock propertyBlock = new MaterialPropertyBlock();
propertyBlock.SetTexture("_AtlasTexture", m_Shadowmap);
propertyBlock.SetVector("_TextureScaleBias", scaleBias);
propertyBlock.SetFloat("_TextureSlice", (float)slice);
debugCB.SetViewport(new Rect(screenX, screenY, screenSizeX, screenSizeY));
debugCB.DrawProcedural(Matrix4x4.identity, m_DebugMaterial, m_DebugMaterial.FindPass("REGULARSHADOW"), MeshTopology.Triangles, 3, 1, propertyBlock);
renderContext.ExecuteCommandBuffer(debugCB);
debugCB.Dispose();
}
}
// -------------------------------------------------------------------------------------------------------------------------------------------------

}
base.PostUpdate( frameId, cb, rendertargetSlice, lights );
}
override public void DisplayShadowMap(ScriptableRenderContext renderContext, Vector4 scaleBias, uint slice, float screenX, float screenY, float screenSizeX, float screenSizeY)
{
CommandBuffer debugCB = new CommandBuffer();
debugCB.name = "";
MaterialPropertyBlock propertyBlock = new MaterialPropertyBlock();
propertyBlock.SetTexture("_AtlasTexture", m_Shadowmap);
propertyBlock.SetVector("_TextureScaleBias", scaleBias);
propertyBlock.SetFloat("_TextureSlice", (float)slice);
debugCB.SetViewport(new Rect(screenX, screenY, screenSizeX, screenSizeY));
debugCB.DrawProcedural(Matrix4x4.identity, m_DebugMaterial, m_DebugMaterial.FindPass("VARIANCESHADOW"), MeshTopology.Triangles, 3, 1, propertyBlock);
renderContext.ExecuteCommandBuffer(debugCB);
debugCB.Dispose();
}
}
// -------------------------------------------------------------------------------------------------------------------------------------------------
//

// The following vector holds data that are returned to the caller so it can be sent to GPU memory in some form. Contents are stable in between calls to ProcessShadowRequests.
private ShadowIndicesVector m_ShadowIndices = new ShadowIndicesVector( 0, false );
public override uint GetShadowMapCount()
{
return (uint)m_Shadowmaps.Length;
}
public override uint GetShadowMapSliceCount(uint shadowMapIndex)
{
if (shadowMapIndex >= m_Shadowmaps.Length)
return 0;
return m_Shadowmaps[shadowMapIndex].slices;
}
public override uint GetShadowRequestCount()
{
return m_TmpRequests.Count();
}
public override uint GetShadowRequestFaceCount(uint requestIndex)
{
if (requestIndex >= (int)m_TmpRequests.Count())
return 0;
else
return m_TmpRequests[requestIndex].facecount;
}
public override int GetShadowRequestIndex(Light light)
{
for(int i = 0 ; i < m_TmpRequests.Count() ; ++i)
{
if (m_TmpRequests[(uint)i].instanceId == light.GetInstanceID())
return i;
}
return -1;
}
public ShadowManager( ShadowSettings shadowSettings, ref ShadowContext.CtxtInit ctxtInitializer, ShadowmapBase[] shadowmaps )
{
m_ShadowSettings = shadowSettings;

}
}
public override void DisplayShadows(ScriptableRenderContext renderContext, Material displayMaterial, int shadowMapIndex, float screenX, float screenY, float screenSizeX, float screenSizeY)
public override void DisplayShadow(ScriptableRenderContext renderContext, int shadowRequestIndex, uint faceIndex, float screenX, float screenY, float screenSizeX, float screenSizeY)
using (new HDPipeline.Utilities.ProfilingSample("Display Shadows", renderContext))
{
// This code is specific to shadow atlas implementation
MaterialPropertyBlock propertyBlock = new MaterialPropertyBlock();
if (m_ShadowIndices.Count() == 0)
return;
CommandBuffer debugCB = new CommandBuffer();
debugCB.name = "Display shadow Overlay";
uint index = Math.Max(0, Math.Min((uint)(m_ShadowIndices.Count() - 1), (uint)shadowRequestIndex));
int offset = (m_TmpRequests[index].facecount > 1 ) ? 1 : 0;
VectorArray<ShadowData> shadowDatas = m_ShadowCtxt.shadowDatas;
ShadowData faceData = shadowDatas[(uint)(m_ShadowIndices[index] + offset + faceIndex)];
uint texID, samplerID, slice;
faceData.UnpackShadowmapId(out texID, out samplerID, out slice);
m_Shadowmaps[texID].DisplayShadowMap(renderContext, faceData.scaleOffset, slice, screenX, screenY, screenSizeX, screenSizeY);
}
if (shadowMapIndex == -1) // Display the Atlas
{
propertyBlock.SetVector("_TextureScaleBias", new Vector4(1.0f, 1.0f, 0.0f, 0.0f));
}
else // Display particular index
{
VectorArray<ShadowData> shadowDatas = m_ShadowCtxt.shadowDatas;
uint shadowIdx = Math.Min((uint)shadowMapIndex, shadowDatas.Count());
propertyBlock.SetVector("_TextureScaleBias", shadowDatas[shadowIdx].scaleOffset);
}
public override void DisplayShadowMap(ScriptableRenderContext renderContext, uint shadowMapIndex, uint sliceIndex, float screenX, float screenY, float screenSizeX, float screenSizeY)
{
if(m_Shadowmaps.Length == 0)
return;
debugCB.SetViewport(new Rect(screenX, screenY, screenSizeX, screenSizeY));
debugCB.DrawProcedural(Matrix4x4.identity, displayMaterial, 0, MeshTopology.Triangles, 3, 1, propertyBlock);
renderContext.ExecuteCommandBuffer(debugCB);
}
uint index = Math.Max(0, Math.Min((uint)(m_Shadowmaps.Length - 1), shadowMapIndex));
m_Shadowmaps[index].DisplayShadowMap(renderContext, new Vector4(1.0f, 1.0f, 0.0f, 0.0f), sliceIndex, screenX, screenY, screenSizeX, screenSizeY);
}
public override void SyncData()

38
Assets/ScriptableRenderPipeline/Core/Shadow/ShadowBase.cs


id = texIdx << 24 | sampIdx << 16 | slice;
}
public void UnpackShadowmapId(out uint texIdx, out uint sampIdx, out uint slice)
{
texIdx = (id >> 24) & 0xff;
sampIdx = (id >> 16) & 0xff;
slice = (id & 0xffff);
}
public void PackShadowType( GPUShadowType type, GPUShadowAlgorithm algorithm )
{
shadowType = (uint)type << ShadowConstants.Bits.k_GPUShadowAlgorithm | (uint) algorithm;

protected readonly ShadowSupport m_ShadowSupport;
protected CullResults m_CullResults; // TODO: Temporary, due to CullResults dependency in ShadowUtils' matrix extraction code. Remove this member once that dependency is gone.
public uint width { get { return m_Width; } }
public uint height { get { return m_Height; } }
public uint slices { get { return m_Slices; } }
public struct BaseInit
{
public uint width; // width of the shadowmap

abstract public void ReserveSlots( ShadowContextStorage sc );
abstract public void Fill( ShadowContextStorage cs );
abstract protected void Register( GPUShadowType type, ShadowRegistry registry );
abstract public void DisplayShadowMap(ScriptableRenderContext renderContext, Vector4 scaleBias, uint slice, float screenX, float screenY, float screenSizeX, float screenSizeY);
}
interface IShadowManager

void ProcessShadowRequests( FrameId frameId, CullResults cullResults, Camera camera, VisibleLight[] lights, ref uint shadowRequestsCount, int[] shadowRequests, out int[] shadowDataIndices );
// Renders all shadows for lights the were deemed shadow casters after the last call to ProcessShadowRequests
void RenderShadows( FrameId frameId, ScriptableRenderContext renderContext, CullResults cullResults, VisibleLight[] lights );
// Debug function to display a shadow at the screen coordinate with the provided material.
void DisplayShadows(ScriptableRenderContext renderContext, Material displayMaterial, int shadowMapIndex, float screenX, float screenY, float screenSizeX, float screenSizeY);
// Debug function to display a shadow at the screen coordinate
void DisplayShadow(ScriptableRenderContext renderContext, int shadowIndex, uint faceIndex, float screenX, float screenY, float screenSizeX, float screenSizeY);
void DisplayShadowMap(ScriptableRenderContext renderContext, uint shadowMapIndex, uint sliceIndex, float screenX, float screenY, float screenSizeX, float screenSizeY);
// Synchronize data with GPU buffers
void SyncData();
// Binds resources to shader stages just before rendering the lighting pass

uint GetShadowMapCount();
uint GetShadowMapSliceCount(uint shadowMapIndex);
uint GetShadowRequestCount();
uint GetShadowRequestFaceCount(uint requestIndex);
int GetShadowRequestIndex(Light light);
}
abstract public class ShadowManagerBase : ShadowRegistry, IShadowManager

public abstract void DisplayShadows(ScriptableRenderContext renderContext, Material displayMaterial, int shadowMapIndex, float screenX, float screenY, float screenSizeX, float screenSizeY);
public abstract void DisplayShadow(ScriptableRenderContext renderContext, int shadowIndex, uint faceIndex, float screenX, float screenY, float screenSizeX, float screenSizeY);
public abstract void DisplayShadowMap(ScriptableRenderContext renderContext, uint shadowMapIndex, uint sliceIndex, float screenX, float screenY, float screenSizeX, float screenSizeY);
public abstract void SyncData();
public abstract void BindResources( ScriptableRenderContext renderContext );
public abstract void UpdateCullingParameters( ref CullingParameters cullingParams );

protected abstract void PruneShadowCasters( Camera camera, VisibleLight[] lights, ref VectorArray<int> shadowRequests, ref VectorArray<ShadowmapBase.ShadowRequest> requestsGranted, out uint totalRequestCount );
// allocate the shadow requests in the shadow map, only is called if shadowsCount > 0 - may modify shadowRequests and shadowsCount
protected abstract void AllocateShadows( FrameId frameId, VisibleLight[] lights, uint totalGranted, ref VectorArray<ShadowmapBase.ShadowRequest> grantedRequests, ref VectorArray<int> shadowIndices, ref VectorArray<ShadowData> shadowmapDatas, ref VectorArray<ShadowPayload> shadowmapPayload );
public abstract uint GetShadowMapCount();
public abstract uint GetShadowMapSliceCount(uint shadowMapIndex);
public abstract uint GetShadowRequestCount();
public abstract uint GetShadowRequestFaceCount(uint requestIndex);
public abstract int GetShadowRequestIndex(Light light);
}
} // end of namespace UnityEngine.Experimental.ScriptableRenderLoop

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


{
public static string kEnableShadowDebug = "Enable Shadows";
public static string kShadowDebugMode = "Shadow Debug Mode";
public static string kShadowSelectionDebug = "Use Selection";
public static string kShadowAtlasIndexDebug = "Shadow Atlas Index";
public static string kLightingDebugMode = "Lighting Debug Mode";
public static string kOverrideSmoothnessDebug = "Override Smoothness";
public static string kOverrideSmoothnessValueDebug = "Override Smoothness Value";

public void RegisterDebug()
{
DebugMenuManager.instance.AddDebugItem<float>("Display Stats", "Frame Rate", () => 1.0f / Time.smoothDeltaTime, null, true);
DebugMenuManager.instance.AddDebugItem<float>("Display Stats", "Frame Time (ms)", () => Time.smoothDeltaTime * 1000.0f, null, true);
DebugMenuManager.instance.AddDebugItem<float>("Display Stats", "Frame Rate", () => 1.0f / Time.smoothDeltaTime, null, DebugItemFlag.DynamicDisplay);
DebugMenuManager.instance.AddDebugItem<float>("Display Stats", "Frame Time (ms)", () => Time.smoothDeltaTime * 1000.0f, null, DebugItemFlag.DynamicDisplay);
DebugMenuManager.instance.AddDebugItem<int>("Material", "Material",() => materialDebugSettings.debugViewMaterial, (value) => SetDebugViewMaterial((int)value), false, new DebugItemHandlerIntEnum(DebugDisplaySettings.debugViewMaterialStrings, DebugDisplaySettings.debugViewMaterialValues));
DebugMenuManager.instance.AddDebugItem<int>("Material", "Engine",() => materialDebugSettings.debugViewEngine, (value) => SetDebugViewEngine((int)value), false, new DebugItemHandlerIntEnum(DebugDisplaySettings.debugViewEngineStrings, DebugDisplaySettings.debugViewEngineValues));
DebugMenuManager.instance.AddDebugItem<int>("Material", "Material",() => materialDebugSettings.debugViewMaterial, (value) => SetDebugViewMaterial((int)value), DebugItemFlag.None, new DebugItemHandlerIntEnum(DebugDisplaySettings.debugViewMaterialStrings, DebugDisplaySettings.debugViewMaterialValues));
DebugMenuManager.instance.AddDebugItem<int>("Material", "Engine",() => materialDebugSettings.debugViewEngine, (value) => SetDebugViewEngine((int)value), DebugItemFlag.None, new DebugItemHandlerIntEnum(DebugDisplaySettings.debugViewEngineStrings, DebugDisplaySettings.debugViewEngineValues));
DebugMenuManager.instance.AddDebugItem<int>("Material", "GBuffer",() => materialDebugSettings.debugViewGBuffer, (value) => SetDebugViewGBuffer((int)value), false, new DebugItemHandlerIntEnum(DebugDisplaySettings.debugViewMaterialGBufferStrings, DebugDisplaySettings.debugViewMaterialGBufferValues));
DebugMenuManager.instance.AddDebugItem<int>("Material", "GBuffer",() => materialDebugSettings.debugViewGBuffer, (value) => SetDebugViewGBuffer((int)value), DebugItemFlag.None, new DebugItemHandlerIntEnum(DebugDisplaySettings.debugViewMaterialGBufferStrings, DebugDisplaySettings.debugViewMaterialGBufferValues));
DebugMenuManager.instance.AddDebugItem<LightingDebugPanel, uint>(kShadowMapIndexDebug, () => lightingDebugSettings.shadowMapIndex, (value) => lightingDebugSettings.shadowMapIndex = (uint)value);
DebugMenuManager.instance.AddDebugItem<LightingDebugPanel, bool>(kShadowSelectionDebug, () => lightingDebugSettings.shadowDebugUseSelection, (value) => lightingDebugSettings.shadowDebugUseSelection = (bool)value, DebugItemFlag.EditorOnly);
DebugMenuManager.instance.AddDebugItem<LightingDebugPanel, uint>(kShadowMapIndexDebug, () => lightingDebugSettings.shadowMapIndex, (value) => lightingDebugSettings.shadowMapIndex = (uint)value, DebugItemFlag.None, new DebugItemHandlerShadowIndex(1));
DebugMenuManager.instance.AddDebugItem<LightingDebugPanel, uint>(kShadowAtlasIndexDebug, () => lightingDebugSettings.shadowAtlasIndex, (value) => lightingDebugSettings.shadowAtlasIndex = (uint)value, DebugItemFlag.None, new DebugItemHandlerShadowAtlasIndex(1));
DebugMenuManager.instance.AddDebugItem<LightingDebugPanel, float>(kOverrideSmoothnessValueDebug, () => lightingDebugSettings.overrideSmoothnessValue, (value) => lightingDebugSettings.overrideSmoothnessValue = (float)value, false, new DebugItemHandlerFloatMinMax(0.0f, 1.0f));
DebugMenuManager.instance.AddDebugItem<LightingDebugPanel, float>(kOverrideSmoothnessValueDebug, () => lightingDebugSettings.overrideSmoothnessValue, (value) => lightingDebugSettings.overrideSmoothnessValue = (float)value, DebugItemFlag.None, new DebugItemHandlerFloatMinMax(0.0f, 1.0f));
DebugMenuManager.instance.AddDebugItem<LightingDebugPanel, float>(kSkyReflectionMipmapDebug, () => lightingDebugSettings.skyReflectionMipmap, (value) => lightingDebugSettings.skyReflectionMipmap = (float)value, false, new DebugItemHandlerFloatMinMax(0.0f, 1.0f));
DebugMenuManager.instance.AddDebugItem<LightingDebugPanel, float>(kSkyReflectionMipmapDebug, () => lightingDebugSettings.skyReflectionMipmap, (value) => lightingDebugSettings.skyReflectionMipmap = (float)value, DebugItemFlag.None, new DebugItemHandlerFloatMinMax(0.0f, 1.0f));
DebugMenuManager.instance.AddDebugItem<bool>("Rendering", "Display Opaque",() => renderingDebugSettings.displayOpaqueObjects, (value) => renderingDebugSettings.displayOpaqueObjects = (bool)value);
DebugMenuManager.instance.AddDebugItem<bool>("Rendering", "Display Transparency",() => renderingDebugSettings.displayTransparentObjects, (value) => renderingDebugSettings.displayTransparentObjects = (bool)value);

public DebugLightingMode debugLightingMode = DebugLightingMode.None;
public bool enableShadows = true;
public ShadowMapDebugMode shadowDebugMode = ShadowMapDebugMode.None;
public bool shadowDebugUseSelection = false;
public uint shadowAtlasIndex = 0;
public FullScreenDebugMode fullScreenDebugMode = FullScreenDebugMode.None;
public bool overrideSmoothness = false;

47
Assets/ScriptableRenderPipeline/HDRenderPipeline/Debug/LightingDebugPanel.cs


using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System;
#if UNITY_EDITOR
using UnityEditor;

{
public class DebugItemHandlerShadowAtlasIndex
: DebugItemHandlerUIntMinMax
{
public DebugItemHandlerShadowAtlasIndex(uint max)
: base(0, max)
{
}
public override void ClampValues(Func<object> getter, Action<object> setter)
{
HDRenderPipeline hdPipeline = RenderPipelineManager.currentPipeline as HDRenderPipeline;
m_Max = (uint)hdPipeline.GetShadowAtlasCount() - 1;
setter(Math.Min(m_Max, Math.Max(m_Min, (uint)getter())));
}
}
public class DebugItemHandlerShadowIndex
: DebugItemHandlerUIntMinMax
{
public DebugItemHandlerShadowIndex(uint max)
: base(0, max)
{
}
public override void ClampValues(Func<object> getter, Action<object> setter)
{
HDRenderPipeline hdPipeline = RenderPipelineManager.currentPipeline as HDRenderPipeline;
m_Max = (uint)hdPipeline.GetCurrentShadowCount() - 1;
setter(Math.Min(m_Max, Math.Max(m_Min, (uint)getter())));
}
}
public class LightingDebugPanelUI
: DebugPanelUI
{

if ((ShadowMapDebugMode)shadowDebug.GetValue() == ShadowMapDebugMode.VisualizeShadowMap)
{
EditorGUI.indentLevel++;
m_DebugPanel.GetDebugItem(DebugDisplaySettings.kShadowMapIndexDebug).handler.OnEditorGUI();
DebugItem shadowSelectionDebug = m_DebugPanel.GetDebugItem(DebugDisplaySettings.kShadowSelectionDebug);
shadowSelectionDebug.handler.OnEditorGUI();
if(!(bool)shadowSelectionDebug.GetValue())
m_DebugPanel.GetDebugItem(DebugDisplaySettings.kShadowMapIndexDebug).handler.OnEditorGUI();
EditorGUI.indentLevel--;
}
if ((ShadowMapDebugMode)shadowDebug.GetValue() == ShadowMapDebugMode.VisualizeAtlas)
{
EditorGUI.indentLevel++;
m_DebugPanel.GetDebugItem(DebugDisplaySettings.kShadowAtlasIndexDebug).handler.OnEditorGUI();
DebugItem lightingDebugModeItem = m_DebugPanel.GetDebugItem(DebugDisplaySettings.kLightingDebugMode);
lightingDebugModeItem.handler.OnEditorGUI();
if ((DebugLightingMode)lightingDebugModeItem.GetValue() == DebugLightingMode.SpecularLighting)

11
Assets/ScriptableRenderPipeline/HDRenderPipeline/HDRenderPipeline.cs


int m_CurrentHeight;
public int GetCurrentShadowCount() { return m_LightLoop.GetCurrentShadowCount(); }
public int GetShadowAtlasCount() { return m_LightLoop.GetShadowAtlasCount(); }
readonly SkyManager m_SkyManager = new SkyManager();
readonly LightLoop m_LightLoop = new LightLoop();

public DebugDisplaySettings m_DebugDisplaySettings = new DebugDisplaySettings();
private int m_DebugFullScreenTempRT;
private bool m_FullScreenDebugPushed = false;
public SubsurfaceScatteringSettings sssSettings
{

private CommonSettings.Settings m_CommonSettings = CommonSettings.Settings.s_Defaultsettings;
private SkySettings m_SkySettings;
private SkySettings m_SkySettings = null;
private ScreenSpaceAmbientOcclusionSettings.Settings m_SsaoSettings = ScreenSpaceAmbientOcclusionSettings.Settings.s_Defaultsettings;
public CommonSettings.Settings commonSettingsToUse

{
if(debugMode == m_DebugDisplaySettings.lightingDebugSettings.fullScreenDebugMode)
{
m_FullScreenDebugPushed = true; // We need this flag because otherwise if no fullscreen debug is pushed, when we render the result in RenderDebug the temporary RT will not exist.
cb.GetTemporaryRT(m_DebugFullScreenTempRT, camera.pixelWidth, camera.pixelHeight, 0, FilterMode.Point, RenderTextureFormat.ARGBHalf, RenderTextureReadWrite.Linear);
cb.Blit(textureID, m_DebugFullScreenTempRT);
}

if (camera.camera.cameraType == CameraType.Reflection || camera.camera.cameraType == CameraType.Preview)
return;
// We make sure the depth buffer is bound because we need it to write depth at near plane for overlays otherwise the editor grid end up visible in them.
Utilities.SetRenderTarget(renderContext, BuiltinRenderTextureType.CameraTarget, m_CameraDepthStencilBufferRT);
if(m_DebugDisplaySettings.lightingDebugSettings.fullScreenDebugMode != FullScreenDebugMode.None)
if(m_DebugDisplaySettings.lightingDebugSettings.fullScreenDebugMode != FullScreenDebugMode.None && m_FullScreenDebugPushed)
m_FullScreenDebugPushed = false;
debugCB.SetGlobalTexture("_DebugFullScreenTexture", m_DebugFullScreenTempRT);
m_DebugFullScreen.SetFloat("_FullScreenDebugMode", (float)m_DebugDisplaySettings.lightingDebugSettings.fullScreenDebugMode);
Utilities.DrawFullScreen(debugCB, m_DebugFullScreen, camera, BuiltinRenderTextureType.CameraTarget);

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


Light m_CurrentSunLight = null;
public Light GetCurrentSunLight() { return m_CurrentSunLight; }
// For displaying shadow map
Material m_DebugDisplayShadowMap;
// shadow related stuff
FrameId m_FrameId = new FrameId();
ShadowSetup m_ShadowSetup; // doesn't actually have to reside here, it would be enough to pass the IShadowManager in from the outside

m_SingleDeferredMaterialMRT.SetInt("_DstBlend", (int)BlendMode.Zero);
m_DebugViewTilesMaterial = Utilities.CreateEngineMaterial(m_Resources.debugViewTilesShader);
m_DebugDisplayShadowMap = Utilities.CreateEngineMaterial(m_Resources.debugDisplayShadowMapShader);
m_DefaultTexture2DArray = new Texture2DArray(1, 1, 1, TextureFormat.ARGB32, false);
m_DefaultTexture2DArray.SetPixels32(new Color32[1] { new Color32(128, 128, 128, 128) }, 0);

Utilities.Destroy(m_SingleDeferredMaterialSRT);
Utilities.Destroy(m_SingleDeferredMaterialMRT);
Utilities.Destroy(m_DebugDisplayShadowMap);
Utilities.Destroy(s_DefaultAdditionalLightDataGameObject);
s_DefaultAdditionalLightDataGameObject = null;

public int GetCurrentShadowCount()
{
return m_ShadowRequests.Count;
}
public int GetShadowAtlasCount()
{
return (int)m_ShadowMgr.GetShadowMapCount();
}
public void UpdateCullingParameters(ref CullingParameters cullingParams)

public void RenderDebugOverlay(Camera camera, ScriptableRenderContext renderContext, DebugDisplaySettings debugDisplaySettings, ref float x, ref float y, float overlaySize, float width)
{
LightingDebugSettings lightingDebug = debugDisplaySettings.lightingDebugSettings;
if (lightingDebug.shadowDebugMode != ShadowMapDebugMode.None)
using (new Utilities.ProfilingSample("Display Shadows", renderContext))
m_ShadowMgr.DisplayShadows(renderContext, m_DebugDisplayShadowMap, (int)lightingDebug.shadowMapIndex, x, y, overlaySize, overlaySize);
Utilities.NextOverlayCoord(ref x, ref y, overlaySize, overlaySize, camera.pixelWidth);
int index = (int)lightingDebug.shadowMapIndex;
// TODO: @Julien exchange shadowmapIndex by lightIndex and draw all slide like below
/*
for (int slice = 0; slice < shadowLight.shadowSliceCount; ++slice)
#if UNITY_EDITOR
if(lightingDebug.shadowDebugUseSelection)
ShadowSliceData sliceData = m_ShadowsResult.shadowSlices[shadowLight.shadowSliceIndex + slice];
Vector4 texcoordScaleBias = new Vector4((float)sliceData.shadowResolution / m_Owner.shadowSettings.shadowAtlasWidth,
(float)sliceData.shadowResolution / m_Owner.shadowSettings.shadowAtlasHeight,
(float)sliceData.atlasX / m_Owner.shadowSettings.shadowAtlasWidth,
(float)sliceData.atlasY / m_Owner.shadowSettings.shadowAtlasHeight);
propertyBlock.SetVector("_TextureScaleBias", texcoordScaleBias);
debugCB.SetViewport(new Rect(x, y, overlaySize, overlaySize));
debugCB.DrawProcedural(Matrix4x4.identity, m_DebugDisplayShadowMap, 0, MeshTopology.Triangles, 3, 1, propertyBlock);
index = -1;
if (UnityEditor.Selection.activeObject is GameObject)
{
GameObject go = UnityEditor.Selection.activeObject as GameObject;
Light light = go.GetComponent<Light>();
if (light != null)
{
index = m_ShadowMgr.GetShadowRequestIndex(light);
}
}
}
#endif
Utilities.NextOverlayCoord(ref x, ref y, overlaySize, camera.pixelWidth);
if(index != -1)
{
uint faceCount = m_ShadowMgr.GetShadowRequestFaceCount((uint)index);
for (uint i = 0; i < faceCount; ++i)
{
m_ShadowMgr.DisplayShadow(renderContext, index, i, x, y, overlaySize, overlaySize);
Utilities.NextOverlayCoord(ref x, ref y, overlaySize, overlaySize, camera.pixelWidth);
}
*/
m_ShadowMgr.DisplayShadows(renderContext, m_DebugDisplayShadowMap, -1, x, y, overlaySize, overlaySize);
m_ShadowMgr.DisplayShadowMap(renderContext, lightingDebug.shadowAtlasIndex, 0, x, y, overlaySize, overlaySize);
Utilities.NextOverlayCoord(ref x, ref y, overlaySize, overlaySize, camera.pixelWidth);
}
}

2
Assets/ScriptableRenderPipeline/HDRenderPipeline/RenderPipelineResources/RenderPipelineResources.cs


var instance = CreateInstance<RenderPipelineResources>();
instance.debugDisplayLatlongShader = UnityEditor.AssetDatabase.LoadAssetAtPath<Shader>("Assets/ScriptableRenderPipeline/HDRenderPipeline/Debug/DebugDisplayLatlong.Shader");
instance.debugDisplayShadowMapShader = UnityEditor.AssetDatabase.LoadAssetAtPath<Shader>("Assets/ScriptableRenderPipeline/HDRenderPipeline/Debug/DebugDisplayShadowMap.Shader");
instance.debugViewMaterialGBufferShader = UnityEditor.AssetDatabase.LoadAssetAtPath<Shader>("Assets/ScriptableRenderPipeline/HDRenderPipeline/Debug/DebugViewMaterialGBuffer.Shader");
instance.debugViewTilesShader = UnityEditor.AssetDatabase.LoadAssetAtPath<Shader>("Assets/ScriptableRenderPipeline/HDRenderPipeline/Debug/DebugViewTiles.Shader");
instance.debugFullScreenShader = UnityEditor.AssetDatabase.LoadAssetAtPath<Shader>("Assets/ScriptableRenderPipeline/HDRenderPipeline/Debug/DebugFullScreen.Shader");

#endif
// Debug
public Shader debugDisplayLatlongShader;
public Shader debugDisplayShadowMapShader;
public Shader debugViewMaterialGBufferShader;
public Shader debugViewTilesShader;
public Shader debugFullScreenShader;

92
Assets/ScriptableRenderPipeline/Core/Shadow/Resources/DebugDisplayShadowMap.shader


Shader "Hidden/HDRenderPipeline/DebugDisplayShadowMap"
Shader "Hidden/ScriptableRenderPipeline/DebugDisplayShadowMap"
HLSLINCLUDE
#pragma target 4.5
#pragma only_renderers d3d11 ps4 metal // TEMP: unitl we go futher in dev
#include "../../../ShaderLibrary/Common.hlsl"
float4 _TextureScaleBias;
float _TextureSlice;
SamplerState ltc_linear_clamp_sampler;
TEXTURE2D_ARRAY(_AtlasTexture);
struct Attributes
{
uint vertexID : SV_VertexID;
};
struct Varyings
{
float4 positionCS : SV_POSITION;
float2 texcoord : TEXCOORD0;
};
Varyings Vert(Attributes input)
{
Varyings output;
output.positionCS = GetFullScreenTriangleVertexPosition(input.vertexID);
output.texcoord = GetFullScreenTriangleTexcoord(input.vertexID) * _TextureScaleBias.xy + _TextureScaleBias.zw;
return output;
}
ENDHLSL
ZWrite Off
Name "RegularShadow"
ZWrite On
#pragma target 4.5
#pragma only_renderers d3d11 ps4 metal // TEMP: unitl we go futher in dev
#pragma fragment Frag
#include "../../ShaderLibrary/Common.hlsl"
#define SHADOW_TILEPASS // TODO: Not sure it must be define, ask uygar
#include "../../ShaderLibrary/Shadow/Shadow.hlsl"
#undef SHADOW_TILEPASS
SamplerState ltc_linear_clamp_sampler;
float4 _TextureScaleBias;
struct Attributes
#pragma fragment FragRegular
float4 FragRegular(Varyings input) : SV_Target
uint vertexID : SV_VertexID;
};
return SAMPLE_TEXTURE2D_ARRAY(_AtlasTexture, ltc_linear_clamp_sampler, input.texcoord, _TextureSlice).xxxx;
}
struct Varyings
{
float4 positionCS : SV_POSITION;
float2 texcoord : TEXCOORD0;
};
ENDHLSL
}
Varyings Vert(Attributes input)
{
Varyings output;
output.positionCS = GetFullScreenTriangleVertexPosition(input.vertexID);
output.texcoord = GetFullScreenTriangleTexcoord(input.vertexID) * _TextureScaleBias.xy + _TextureScaleBias.zw;
Pass
{
Name "VarianceShadow"
ZTest Off
Blend One Zero
Cull Off
ZWrite On
return output;
}
HLSLPROGRAM
float4 Frag(Varyings input) : SV_Target
#pragma vertex Vert
#pragma fragment FragVariance
float4 FragVariance(Varyings input) : SV_Target
ShadowContext shadowContext = InitShadowContext();
// Caution: ShadowContext is define in Shadowcontext.hlsl for current render pipeline. This shader must be in sync with its content else it doesn't work.
return SAMPLE_TEXTURE2D_ARRAY(_ShadowmapExp_PCF, ltc_linear_clamp_sampler, input.texcoord, 0).xxxx;
return SAMPLE_TEXTURE2D_ARRAY(_AtlasTexture, ltc_linear_clamp_sampler, input.texcoord, _TextureSlice).rgba; // Might want something more clever like a channel selector.
}
Fallback Off
}

9
Assets/ScriptableRenderPipeline/Core/Shadow/Resources.meta


fileFormatVersion: 2
guid: 17c6560a19ee38a488a305b841122612
folderAsset: yes
timeCreated: 1496931301
licenseType: Pro
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:

/Assets/ScriptableRenderPipeline/HDRenderPipeline/Debug/DebugDisplayShadowMap.shader.meta → /Assets/ScriptableRenderPipeline/Core/Shadow/Resources/DebugDisplayShadowMap.shader.meta

/Assets/ScriptableRenderPipeline/HDRenderPipeline/Debug/DebugDisplayShadowMap.shader → /Assets/ScriptableRenderPipeline/Core/Shadow/Resources/DebugDisplayShadowMap.shader

正在加载...
取消
保存