浏览代码

Added FullScreenDebug modes and implemented it for SSAO.

/RenderPassXR_Sandbox
Julien Ignace 7 年前
当前提交
278154db
共有 10 个文件被更改,包括 111 次插入50 次删除
  1. 40
      Assets/ScriptableRenderPipeline/HDRenderPipeline/Debug/DebugDisplay.cs
  2. 7
      Assets/ScriptableRenderPipeline/HDRenderPipeline/Debug/DebugDisplay.cs.hlsl
  3. 20
      Assets/ScriptableRenderPipeline/HDRenderPipeline/Debug/LightingDebugPanel.cs
  4. 54
      Assets/ScriptableRenderPipeline/HDRenderPipeline/HDRenderPipeline.cs
  5. 13
      Assets/ScriptableRenderPipeline/HDRenderPipeline/HDRenderPipelineAsset.cs
  6. 8
      Assets/ScriptableRenderPipeline/HDRenderPipeline/Lighting/AmbientOcclusion/AmbientOcclusion.cs
  7. 4
      Assets/ScriptableRenderPipeline/HDRenderPipeline/Lighting/TilePass/TilePass.cs
  8. 2
      Assets/ScriptableRenderPipeline/HDRenderPipeline/RenderPipelineResources/HDRenderPipelineResources.asset
  9. 2
      Assets/ScriptableRenderPipeline/HDRenderPipeline/RenderPipelineResources/RenderPipelineResources.cs
  10. 11
      Assets/ScriptableRenderPipeline/HDRenderPipeline/Utilities.cs

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


public class DebugDisplaySettings
{
public static string kEnableShadowDebug = "Enable Shadows";
public static string kShadowDebugMode = "Shadow Debug Mode";
public static string kShadowMapIndexDebug = "Shadow Map Index";
public static string kLightingDebugMode = "Lighting Debug Mode";
public static string kOverrideSmoothnessDebug = "Override Smoothness";
public static string kOverrideSmoothnessValueDebug = "Override Smoothness Value";
public static string kDebugLightingAlbedo = "Debug Lighting Albedo";
public static string kFullScreenDebugMode = "Fullscreen Debug Mode";
public static string kDisplaySkyReflectionDebug = "Display Sky Reflection";
public static string kSkyReflectionMipmapDebug = "Sky Reflection Mipmap";
public float debugOverlayRatio = 0.33f;
public MaterialDebugSettings materialDebugSettings = new MaterialDebugSettings();

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 DebugItemHandlerIntEnum(DebugDisplaySettings.debugViewMaterialGBufferStrings, DebugDisplaySettings.debugViewMaterialGBufferValues));
DebugMenuManager.instance.AddDebugItem<LightingDebugPanel, bool>("Enable Shadows", () => lightingDebugSettings.enableShadows, (value) => lightingDebugSettings.enableShadows = (bool)value);
DebugMenuManager.instance.AddDebugItem<LightingDebugPanel, ShadowMapDebugMode>("Shadow Debug Mode", () => lightingDebugSettings.shadowDebugMode, (value) => lightingDebugSettings.shadowDebugMode = (ShadowMapDebugMode)value);
DebugMenuManager.instance.AddDebugItem<LightingDebugPanel, uint>("Shadow Map Index", () => lightingDebugSettings.shadowMapIndex, (value) => lightingDebugSettings.shadowMapIndex = (uint)value);
DebugMenuManager.instance.AddDebugItem<LightingDebugPanel, DebugLightingMode>("Lighting Debug Mode", () => lightingDebugSettings.debugLightingMode, (value) => SetDebugLightingMode((DebugLightingMode)value));
DebugMenuManager.instance.AddDebugItem<LightingDebugPanel, bool>("Override Smoothness", () => lightingDebugSettings.overrideSmoothness, (value) => lightingDebugSettings.overrideSmoothness = (bool)value);
DebugMenuManager.instance.AddDebugItem<LightingDebugPanel, float>("Override Smoothness Value", () => lightingDebugSettings.overrideSmoothnessValue, (value) => lightingDebugSettings.overrideSmoothnessValue = (float)value, false, new DebugItemHandlerFloatMinMax(0.0f, 1.0f));
DebugMenuManager.instance.AddDebugItem<LightingDebugPanel, Color>("Debug Lighting Albedo", () => lightingDebugSettings.debugLightingAlbedo, (value) => lightingDebugSettings.debugLightingAlbedo = (Color)value);
DebugMenuManager.instance.AddDebugItem<bool>("Lighting", "Display Sky Reflection", () => lightingDebugSettings.displaySkyReflection, (value) => lightingDebugSettings.displaySkyReflection = (bool)value);
DebugMenuManager.instance.AddDebugItem<LightingDebugPanel, float>("Sky Reflection Mipmap", () => lightingDebugSettings.skyReflectionMipmap, (value) => lightingDebugSettings.skyReflectionMipmap = (float)value, false, new DebugItemHandlerFloatMinMax(0.0f, 1.0f));
DebugMenuManager.instance.AddDebugItem<LightingDebugPanel, bool>(kEnableShadowDebug, () => lightingDebugSettings.enableShadows, (value) => lightingDebugSettings.enableShadows = (bool)value);
DebugMenuManager.instance.AddDebugItem<LightingDebugPanel, ShadowMapDebugMode>(kShadowDebugMode, () => lightingDebugSettings.shadowDebugMode, (value) => lightingDebugSettings.shadowDebugMode = (ShadowMapDebugMode)value);
DebugMenuManager.instance.AddDebugItem<LightingDebugPanel, uint>(kShadowMapIndexDebug, () => lightingDebugSettings.shadowMapIndex, (value) => lightingDebugSettings.shadowMapIndex = (uint)value);
DebugMenuManager.instance.AddDebugItem<LightingDebugPanel, FullScreenDebugMode>(kFullScreenDebugMode, () => lightingDebugSettings.fullScreenDebugMode, (value) => lightingDebugSettings.fullScreenDebugMode = (FullScreenDebugMode)value);
DebugMenuManager.instance.AddDebugItem<LightingDebugPanel, DebugLightingMode>(kLightingDebugMode, () => lightingDebugSettings.debugLightingMode, (value) => SetDebugLightingMode((DebugLightingMode)value));
DebugMenuManager.instance.AddDebugItem<LightingDebugPanel, bool>(kOverrideSmoothnessDebug, () => lightingDebugSettings.overrideSmoothness, (value) => lightingDebugSettings.overrideSmoothness = (bool)value);
DebugMenuManager.instance.AddDebugItem<LightingDebugPanel, float>(kOverrideSmoothnessValueDebug, () => lightingDebugSettings.overrideSmoothnessValue, (value) => lightingDebugSettings.overrideSmoothnessValue = (float)value, false, new DebugItemHandlerFloatMinMax(0.0f, 1.0f));
DebugMenuManager.instance.AddDebugItem<LightingDebugPanel, Color>(kDebugLightingAlbedo, () => lightingDebugSettings.debugLightingAlbedo, (value) => lightingDebugSettings.debugLightingAlbedo = (Color)value);
DebugMenuManager.instance.AddDebugItem<bool>("Lighting", kDisplaySkyReflectionDebug, () => lightingDebugSettings.displaySkyReflection, (value) => lightingDebugSettings.displaySkyReflection = (bool)value);
DebugMenuManager.instance.AddDebugItem<LightingDebugPanel, float>(kSkyReflectionMipmapDebug, () => lightingDebugSettings.skyReflectionMipmap, (value) => lightingDebugSettings.skyReflectionMipmap = (float)value, false, 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);

VisualizeShadowMap
}
[GenerateHLSL]
public enum FullScreenDebugMode
{
None,
SSAO,
SSAOBeforeFiltering,
}
[Serializable]
public class LightingDebugSettings
{

public bool enableShadows = true;
public ShadowMapDebugMode shadowDebugMode = ShadowMapDebugMode.None;
public uint shadowMapIndex = 0;
public FullScreenDebugMode fullScreenDebugMode = FullScreenDebugMode.None;
public bool overrideSmoothness = false;
public float overrideSmoothnessValue = 0.5f;

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


#define DEBUGVIEWGBUFFER_DEPTH (10)
#define DEBUGVIEWGBUFFER_BAKE_DIFFUSE_LIGHTING_WITH_ALBEDO_PLUS_EMISSIVE (11)
//
// UnityEngine.Experimental.Rendering.HDPipeline.FullScreenDebugMode: static fields
//
#define FULLSCREENDEBUGMODE_NONE (0)
#define FULLSCREENDEBUGMODE_SSAO (1)
#define FULLSCREENDEBUGMODE_SSAOBEFORE_FILTERING (2)
#endif

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


{
using (new UnityEditor.EditorGUILayout.VerticalScope())
{
m_DebugPanel.GetDebugItem("Enable Shadows").handler.OnEditorGUI();
m_DebugPanel.GetDebugItem(DebugDisplaySettings.kEnableShadowDebug).handler.OnEditorGUI();
DebugItem shadowDebug = m_DebugPanel.GetDebugItem("Shadow Debug Mode");
DebugItem shadowDebug = m_DebugPanel.GetDebugItem(DebugDisplaySettings.kShadowDebugMode);
m_DebugPanel.GetDebugItem("Shadow Map Index").handler.OnEditorGUI();
m_DebugPanel.GetDebugItem(DebugDisplaySettings.kShadowMapIndexDebug).handler.OnEditorGUI();
DebugItem lightingDebugModeItem = m_DebugPanel.GetDebugItem("Lighting Debug Mode");
DebugItem lightingDebugModeItem = m_DebugPanel.GetDebugItem(DebugDisplaySettings.kLightingDebugMode);
DebugItem overrideSmoothnessItem = m_DebugPanel.GetDebugItem("Override Smoothness");
DebugItem overrideSmoothnessItem = m_DebugPanel.GetDebugItem(DebugDisplaySettings.kOverrideSmoothnessDebug);
m_DebugPanel.GetDebugItem("Override Smoothness Value").handler.OnEditorGUI();
m_DebugPanel.GetDebugItem(DebugDisplaySettings.kOverrideSmoothnessValueDebug).handler.OnEditorGUI();
}
EditorGUI.indentLevel--;
}

m_DebugPanel.GetDebugItem("Debug Lighting Albedo").handler.OnEditorGUI();
m_DebugPanel.GetDebugItem(DebugDisplaySettings.kDebugLightingAlbedo).handler.OnEditorGUI();
DebugItem displaySkyReflecItem = m_DebugPanel.GetDebugItem("Display Sky Reflection");
m_DebugPanel.GetDebugItem(DebugDisplaySettings.kFullScreenDebugMode).handler.OnEditorGUI();
DebugItem displaySkyReflecItem = m_DebugPanel.GetDebugItem(DebugDisplaySettings.kDisplaySkyReflectionDebug);
m_DebugPanel.GetDebugItem("Sky Reflection Mipmap").handler.OnEditorGUI();
m_DebugPanel.GetDebugItem(DebugDisplaySettings.kSkyReflectionMipmapDebug).handler.OnEditorGUI();
EditorGUI.indentLevel--;
}
}

54
Assets/ScriptableRenderPipeline/HDRenderPipeline/HDRenderPipeline.cs


private Material m_DebugViewMaterialGBuffer;
private Material m_DebugDisplayLatlong;
private Material m_DebugFullScreen;
// Various buffer
readonly int m_CameraColorBuffer;

// Debugging
public DebugDisplaySettings m_DebugDisplaySettings = new DebugDisplaySettings();
private int m_DebugFullScreenTempRT;
public SubsurfaceScatteringSettings sssSettings
{

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

return SkySettingsSingleton.overrideSettings;
return m_SkySettings;
}
}
public ScreenSpaceAmbientOcclusionSettings.Settings ssaoSettingsToUse
{
get
{
if (ScreenSpaceAmbientOcclusionSettingsSingleton.overrideSettings)
return ScreenSpaceAmbientOcclusionSettingsSingleton.overrideSettings.settings;
return m_SsaoSettings;
}
}

m_SsaoEffect.Build(asset.renderPipelineResources);
m_DebugDisplaySettings.RegisterDebug();
m_DebugFullScreenTempRT = Shader.PropertyToID("_DebugFullScreenTexture");
}
void InitializeDebugMaterials()

m_DebugFullScreen = Utilities.CreateEngineMaterial(m_Asset.renderPipelineResources.debugFullScreenShader);
}
public void OnSceneLoad()

using (new Utilities.ProfilingSample("Build Light list and render shadows", renderContext))
{
// TODO: Everything here (SSAO, Shadow, Build light list, material and light classification can be parallelize with Async compute)
m_SsaoEffect.Render(m_Asset.ssaoSettingsToUse, hdCamera, renderContext, GetDepthTexture(), m_Asset.renderingSettings.useForwardRenderingOnly);
m_SsaoEffect.Render(ssaoSettingsToUse, this, hdCamera, renderContext, GetDepthTexture(), m_Asset.renderingSettings.useForwardRenderingOnly);
m_LightLoop.PrepareLightsForGPU(m_ShadowSettings, cullResults, camera);
m_LightLoop.RenderShadows(renderContext, cullResults);
renderContext.SetupCameraProperties(camera); // Need to recall SetupCameraProperties after m_ShadowPass.Render

}
}
RenderDebugOverlay(camera, renderContext);
RenderDebug(hdCamera, renderContext);
// bind depth surface for editor grid/gizmo/selection rendering
if (camera.cameraType == CameraType.SceneView)

Shader.SetGlobalVector("_DebugLightingSmoothness", debugSmoothness);
}
void RenderDebugOverlay(Camera camera, ScriptableRenderContext renderContext)
public void PushFullScreenDebugTexture(CommandBuffer cb, int textureID, Camera camera, ScriptableRenderContext renderContext, FullScreenDebugMode debugMode)
{
if(debugMode == m_DebugDisplaySettings.lightingDebugSettings.fullScreenDebugMode)
{
cb.GetTemporaryRT(m_DebugFullScreenTempRT, camera.pixelWidth, camera.pixelHeight, 0, FilterMode.Point, RenderTextureFormat.ARGBHalf, RenderTextureReadWrite.Linear);
cb.Blit(textureID, m_DebugFullScreenTempRT);
}
}
void RenderDebug(HDCamera camera, ScriptableRenderContext renderContext)
if (camera.cameraType == CameraType.Reflection || camera.cameraType == CameraType.Preview)
if (camera.camera.cameraType == CameraType.Reflection || camera.camera.cameraType == CameraType.Preview)
debugCB.name = "Debug Overlay";
debugCB.name = "Render Debug";
// First render full screen debug texture
if(m_DebugDisplaySettings.lightingDebugSettings.fullScreenDebugMode != FullScreenDebugMode.None)
{
debugCB.SetGlobalTexture("_DebugFullScreenTexture", m_DebugFullScreenTempRT);
m_DebugFullScreen.SetFloat("_FullScreenDebugMode", (float)m_DebugDisplaySettings.lightingDebugSettings.fullScreenDebugMode);
Utilities.DrawFullScreen(debugCB, m_DebugFullScreen, camera, BuiltinRenderTextureType.CameraTarget);
}
// Then overlays
float overlaySize = Math.Min(camera.pixelHeight, camera.pixelWidth) * overlayRatio;
float y = camera.pixelHeight - overlaySize;
float overlaySize = Math.Min(camera.camera.pixelHeight, camera.camera.pixelWidth) * overlayRatio;
float y = camera.camera.pixelHeight - overlaySize;
MaterialPropertyBlock propertyBlock = new MaterialPropertyBlock();

Texture skyReflection = m_SkyManager.skyReflection;
propertyBlock.SetTexture("_InputCubemap", skyReflection);
propertyBlock.SetFloat("_Mipmap", lightingDebug.skyReflectionMipmap);
debugCB.SetViewport(new Rect(x, y, overlaySize, overlaySize));
debugCB.SetViewport(new Rect(x, y, overlaySize, overlaySize));
Utilities.NextOverlayCoord(ref x, ref y, overlaySize, camera.pixelWidth);
Utilities.NextOverlayCoord(ref x, ref y, overlaySize, overlaySize, camera.camera.pixelWidth);
m_LightLoop.RenderDebugOverlay(camera, renderContext, m_DebugDisplaySettings, ref x, ref y, overlaySize, camera.pixelWidth);
m_LightLoop.RenderDebugOverlay(camera.camera, renderContext, m_DebugDisplaySettings, ref x, ref y, overlaySize, camera.camera.pixelWidth);
}
void InitAndClearBuffer(Camera camera, ScriptableRenderContext renderContext)

13
Assets/ScriptableRenderPipeline/HDRenderPipeline/HDRenderPipelineAsset.cs


// Texture Settings
public TextureSettings textureSettings = new TextureSettings();
private ScreenSpaceAmbientOcclusionSettings.Settings m_SsaoSettings = ScreenSpaceAmbientOcclusionSettings.Settings.s_Defaultsettings;
public ScreenSpaceAmbientOcclusionSettings.Settings ssaoSettingsToUse
{
get
{
if (ScreenSpaceAmbientOcclusionSettingsSingleton.overrideSettings)
return ScreenSpaceAmbientOcclusionSettingsSingleton.overrideSettings.settings;
return m_SsaoSettings;
}
}
// Default Material / Shader
[SerializeField]

8
Assets/ScriptableRenderPipeline/HDRenderPipeline/Lighting/AmbientOcclusion/AmbientOcclusion.cs


Material m_Material;
readonly RenderTargetIdentifier m_AmbientOcclusionRT;
public ScreenSpaceAmbientOcclusionEffect()
{}

m_Material.hideFlags = HideFlags.DontSave;
}
public void Render(ScreenSpaceAmbientOcclusionSettings.Settings settings, HDCamera hdCamera, ScriptableRenderContext renderContext, RenderTargetIdentifier depthID, bool isForward)
public void Render(ScreenSpaceAmbientOcclusionSettings.Settings settings, HDRenderPipeline hdRP, HDCamera hdCamera, ScriptableRenderContext renderContext, RenderTargetIdentifier depthID, bool isForward)
{
const RenderTextureFormat kFormat = RenderTextureFormat.ARGB32;
const RenderTextureReadWrite kRWMode = RenderTextureReadWrite.Linear;

cmd.SetGlobalTexture(Uniforms._MainTex, depthID);
Utilities.DrawFullScreen(cmd, m_Material, hdCamera, Uniforms._TempTex1, null, 0);
hdRP.PushFullScreenDebugTexture(cmd, Uniforms._TempTex1, hdCamera.camera, renderContext, FullScreenDebugMode.SSAOBeforeFiltering);
// Denoising (horizontal pass).
cmd.GetTemporaryRT(Uniforms._TempTex2, width, height, 0, kFilter, kFormat, kRWMode);
cmd.SetGlobalTexture(Uniforms._MainTex, Uniforms._TempTex1);

// Setup texture for lighting pass (automagic of unity)
cmd.SetGlobalTexture("_AmbientOcclusionTexture", Uniforms._AOBuffer);
hdRP.PushFullScreenDebugTexture(cmd, Uniforms._AOBuffer, hdCamera.camera, renderContext, FullScreenDebugMode.SSAO);
// Register the command buffer and release it.
renderContext.ExecuteCommandBuffer(cmd);

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


if (lightingDebug.shadowDebugMode == ShadowMapDebugMode.VisualizeShadowMap)
{
m_ShadowMgr.DisplayShadows(renderContext, m_DebugDisplayShadowMap, (int)lightingDebug.shadowMapIndex, x, y, overlaySize, overlaySize);
Utilities.NextOverlayCoord(ref x, ref y, overlaySize, camera.pixelWidth);
Utilities.NextOverlayCoord(ref x, ref y, overlaySize, overlaySize, camera.pixelWidth);
// TODO: @Julien exchange shadowmapIndex by lightIndex and draw all slide like below
/*

else if (lightingDebug.shadowDebugMode == ShadowMapDebugMode.VisualizeAtlas)
{
m_ShadowMgr.DisplayShadows(renderContext, m_DebugDisplayShadowMap, -1, x, y, overlaySize, overlaySize);
Utilities.NextOverlayCoord(ref x, ref y, overlaySize, camera.pixelWidth);
Utilities.NextOverlayCoord(ref x, ref y, overlaySize, overlaySize, camera.pixelWidth);
}
}
}

2
Assets/ScriptableRenderPipeline/HDRenderPipeline/RenderPipelineResources/HDRenderPipelineResources.asset


type: 3}
debugViewTilesShader: {fileID: 4800000, guid: c7c2bd17b06ceb4468e14081aaf1b96f,
type: 3}
debugFullScreenShader: {fileID: 4800000, guid: e874aca2df8300a488258738c31f85cf,
type: 3}
deferredShader: {fileID: 4800000, guid: 00dd221e34a6ab349a1196b0f2fab693, type: 3}
clearDispatchIndirectShader: {fileID: 7200000, guid: fc1f553acb80a6446a32d33e403d0656,
type: 3}

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


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");
instance.deferredShader = UnityEditor.AssetDatabase.LoadAssetAtPath<Shader>("Assets/ScriptableRenderPipeline/HDRenderPipeline/Lighting/Deferred.Shader");

public Shader debugDisplayShadowMapShader;
public Shader debugViewMaterialGBufferShader;
public Shader debugViewTilesShader;
public Shader debugFullScreenShader;
// Lighting resources
public Shader deferredShader;

11
Assets/ScriptableRenderPipeline/HDRenderPipeline/Utilities.cs


}
// Helper to help to display debug info on screen
public static void NextOverlayCoord(ref float x, ref float y, float overlaySize, float width)
static float overlayLineHeight = -1.0f;
public static void NextOverlayCoord(ref float x, ref float y, float overlayWidth, float overlayHeight, float width)
x += overlaySize;
x += overlayWidth;
overlayLineHeight = Mathf.Max(overlayHeight, overlayLineHeight);
if (x + overlaySize > width)
if (x + overlayWidth > width)
y -= overlaySize;
y -= overlayLineHeight;
overlayLineHeight = -1.0f;
}
}
}
正在加载...
取消
保存