浏览代码

Start of new small framework for debugging stuff in HDRenderPipeline. Used it for shadow map visualization.

/main
Julien Ignace 8 年前
当前提交
3a51e665
共有 9 个文件被更改,包括 1363 次插入35 次删除
  1. 81
      Assets/ScriptableRenderLoop/HDRenderPipeline/Editor/HDRenderPipelineInspector.cs
  2. 105
      Assets/ScriptableRenderLoop/HDRenderPipeline/HDRenderPipeline.cs
  3. 25
      Assets/ScriptableRenderLoop/RenderPasses/ShadowRenderPass.cs
  4. 9
      Assets/TestScenes/HDTest/CascadedShadowsTest.meta
  5. 1001
      Assets/TestScenes/HDTest/CascadedShadowsTest.unity
  6. 8
      Assets/TestScenes/HDTest/CascadedShadowsTest.unity.meta
  7. 160
      Assets/TestScenes/HDTest/CascadedShadowsTest/Lit_Gray.mat
  8. 9
      Assets/TestScenes/HDTest/CascadedShadowsTest/Lit_Gray.mat.meta

81
Assets/ScriptableRenderLoop/HDRenderPipeline/Editor/HDRenderPipelineInspector.cs


{
private class Styles
{
// Global debug parameters
public readonly GUIContent debugging = new GUIContent("Debugging");
public readonly GUIContent debugOverlayRatio = new GUIContent("Overlay Ratio");
public readonly GUIContent debugParameters = new GUIContent("Debug Parameters");
public readonly GUIContent debugViewMaterial = new GUIContent("DebugView Material", "Display various properties of Materials.");

public GUIContent[] debugViewMaterialStrings = null;
public int[] debugViewMaterialValues = null;
// Shadow Debug
public readonly GUIContent shadowDebugParameters = new GUIContent("Shadow Debug");
public readonly GUIContent shadowDebugEnable = new GUIContent("Enable Shadows");
public readonly GUIContent shadowDebugVisualizationMode = new GUIContent("Visualize");
public readonly GUIContent shadowDebugVisualizeShadowIndex = new GUIContent("Visualize Shadow Index");
public readonly GUIContent shadowsEnabled = new GUIContent("Enabled");
public readonly GUIContent shadowsAtlasWidth = new GUIContent("Atlas width");
public readonly GUIContent shadowsAtlasHeight = new GUIContent("Atlas height");

const float k_MaxExposure = 32.0f;
SerializedProperty m_ShowDebug = null;
SerializedProperty m_ShowDebugShadow = null;
SerializedProperty m_DebugOverlayRatio = null;
SerializedProperty m_DebugShadowEnabled = null;
SerializedProperty m_DebugShadowVisualizationMode = null;
SerializedProperty m_DebugShadowVisualizeShadowIndex = null;
private void InitializeProperties()
{
m_DebugOverlayRatio = serializedObject.FindProperty("m_GlobalDebugParameters.debugOverlayRatio");
m_ShowDebugShadow = serializedObject.FindProperty("m_GlobalDebugParameters.displayShadowDebug");
m_ShowDebug = serializedObject.FindProperty("m_GlobalDebugParameters.displayDebug");
m_DebugShadowEnabled = serializedObject.FindProperty("m_GlobalDebugParameters.shadowDebugParameters.enableShadows");
m_DebugShadowVisualizationMode = serializedObject.FindProperty("m_GlobalDebugParameters.shadowDebugParameters.visualizationMode");
m_DebugShadowVisualizeShadowIndex = serializedObject.FindProperty("m_GlobalDebugParameters.shadowDebugParameters.visualizeShadowMapIndex");
}
string GetSubNameSpaceName(Type type)
{
return type.Namespace.Substring(type.Namespace.LastIndexOf((".")) + 1) + "/";

}
}
private void DebuggingUI(HDRenderPipeline renderContext)
{
EditorGUILayout.LabelField(styles.debugging);
// Global debug parameters
EditorGUI.indentLevel++;
m_DebugOverlayRatio.floatValue = EditorGUILayout.Slider(styles.debugOverlayRatio, m_DebugOverlayRatio.floatValue, 0.1f, 1.0f);
EditorGUI.indentLevel--;
EditorGUILayout.Space();
DebugParametersUI(renderContext);
ShadowDebugParametersUI(renderContext);
}
m_ShowDebug.boolValue = EditorGUILayout.Foldout(m_ShowDebug.boolValue, styles.debugParameters);
if (!m_ShowDebug.boolValue)
return;
EditorGUILayout.LabelField(styles.debugParameters);
EditorGUI.indentLevel++;
EditorGUI.BeginChangeCheck();

EditorGUI.indentLevel--;
}
private void ShadowDebugParametersUI(HDRenderPipeline renderContext)
{
m_ShowDebugShadow.boolValue = EditorGUILayout.Foldout(m_ShowDebugShadow.boolValue, styles.shadowDebugParameters);
if (!m_ShowDebugShadow.boolValue)
return;
EditorGUI.indentLevel++;
EditorGUILayout.PropertyField(m_DebugShadowEnabled, styles.shadowDebugEnable);
EditorGUILayout.PropertyField(m_DebugShadowVisualizationMode, styles.shadowDebugVisualizationMode);
if (!m_DebugShadowVisualizationMode.hasMultipleDifferentValues)
{
if ((ShadowDebugMode)m_DebugShadowVisualizationMode.intValue == ShadowDebugMode.VisualizeShadowMap)
{
EditorGUILayout.IntSlider(m_DebugShadowVisualizeShadowIndex, 0, renderContext.GetCurrentShadowCount() - 1, styles.shadowDebugVisualizeShadowIndex);
}
}
EditorGUI.indentLevel--;
}
private void ShadowParametersUI(HDRenderPipeline renderContext)
{
EditorGUILayout.Space();

EditorGUI.indentLevel++;
EditorGUI.BeginChangeCheck();
shadowParameters.enabled = EditorGUILayout.Toggle(styles.shadowsEnabled, shadowParameters.enabled);
shadowParameters.shadowAtlasWidth = Mathf.Max(0, EditorGUILayout.IntField(styles.shadowsAtlasWidth, shadowParameters.shadowAtlasWidth));
shadowParameters.shadowAtlasHeight = Mathf.Max(0, EditorGUILayout.IntField(styles.shadowsAtlasHeight, shadowParameters.shadowAtlasHeight));

}
}
public void OnEnable()
{
InitializeProperties();
}
public override void OnInspectorGUI()
{
var renderContext = target as HDRenderPipeline;

DebugParametersUI(renderContext);
serializedObject.Update();
DebuggingUI(renderContext);
serializedObject.ApplyModifiedProperties();
}
}
}

105
Assets/ScriptableRenderLoop/HDRenderPipeline/HDRenderPipeline.cs


m_SkyManager.InstantiateSkyRenderer(skyRendererType);
}
public class DebugParameters
{
// Material Debugging
public int debugViewMaterial = 0;
// Rendering debugging
public bool displayOpaqueObjects = true;
public bool displayTransparentObjects = true;
public bool useForwardRenderingOnly = false; // TODO: Currently there is no way to strip the extra forward shaders generated by the shaders compiler, so we can switch dynamically.
public bool useDepthPrepass = false;
public bool useDistortion = true;
// we have to fallback to forward-only rendering when scene view is using wireframe rendering mode --
// as rendering everything in wireframe + deferred do not play well together
public bool ShouldUseForwardRenderingOnly () { return useForwardRenderingOnly || GL.wireframe; }
}
// Debugging
[SerializeField]
GlobalDebugParameters m_GlobalDebugParameters = new GlobalDebugParameters();
DebugParameters m_DebugParameters = new DebugParameters();
DebugParameters m_DebugParameters = new DebugParameters();
public DebugParameters debugParameters
{
get { return m_DebugParameters; }

GBufferManager m_gbufferManager = new GBufferManager();
[SerializeField]
ShadowSettings m_ShadowSettings = ShadowSettings.Default;
ShadowSettings m_ShadowSettings = ShadowSettings.Default;
ShadowOutput m_ShadowsResult;
public int GetCurrentShadowCount() { return m_ShadowsResult.shadowLights == null ? 0 : m_ShadowsResult.shadowLights.Length; }
ShadowRenderPass m_ShadowPass;

// Various set of material use in render loop
Material m_DebugViewMaterialGBuffer;
Material m_DebugDisplayShadowMap;
// Various buffer
int m_CameraColorBuffer;

m_SkyManager.Build();
m_DebugViewMaterialGBuffer = Utilities.CreateEngineMaterial("Hidden/HDRenderPipeline/DebugViewMaterialGBuffer");
m_DebugDisplayShadowMap = Utilities.CreateEngineMaterial("Hidden/HDRenderPipeline/DebugDisplayShadowMap");
m_ShadowPass = new ShadowRenderPass(m_ShadowSettings);

m_LitRenderLoop.Cleanup();
Utilities.Destroy(m_DebugViewMaterialGBuffer);
Utilities.Destroy(m_DebugDisplayShadowMap);
m_SkyManager.Cleanup();

}
}
void NextOverlayCoord(ref float x, ref float y, float overlaySize, float width)
{
x += overlaySize;
// Go to next line if it goes outside the screen.
if (x + overlaySize > width)
{
x = 0;
y -= overlaySize;
}
}
void RenderDebugOverlay(Camera camera, ScriptableRenderContext renderContext)
{
CommandBuffer debugCB = new CommandBuffer();
debugCB.name = "Debug Overlay";
float x = 0;
float overlayRatio = m_GlobalDebugParameters.debugOverlayRatio;
float overlaySize = Math.Min(camera.pixelHeight, camera.pixelWidth) * overlayRatio;
float y = camera.pixelHeight - overlaySize;
MaterialPropertyBlock propertyBlock = new MaterialPropertyBlock();
ShadowDebugParameters shadowDebug = m_GlobalDebugParameters.shadowDebugParameters;
if (shadowDebug.visualizationMode != ShadowDebugMode.None)
{
if (shadowDebug.visualizationMode == ShadowDebugMode.VisualizeShadowMap)
{
ShadowLight shadowLight = m_ShadowsResult.shadowLights[shadowDebug.visualizeShadowMapIndex];
for (int slice = 0; slice < shadowLight.shadowSliceCount; ++slice)
{
ShadowSliceData sliceData = m_ShadowsResult.shadowSlices[shadowLight.shadowSliceIndex + slice];
Vector4 texcoordScaleBias = new Vector4((float)sliceData.shadowResolution / m_ShadowSettings.shadowAtlasWidth,
(float)sliceData.shadowResolution / m_ShadowSettings.shadowAtlasHeight,
(float)sliceData.atlasX / m_ShadowSettings.shadowAtlasWidth,
(float)sliceData.atlasY / m_ShadowSettings.shadowAtlasHeight);
propertyBlock.SetVector("_TextureScaleBias", texcoordScaleBias);
debugCB.SetViewport(new Rect(x, y, overlaySize, overlaySize));
debugCB.DrawProcedural(Matrix4x4.identity, m_DebugDisplayShadowMap, 0, MeshTopology.Triangles, 6, 1, propertyBlock);
NextOverlayCoord(ref x, ref y, overlaySize, camera.pixelWidth);
}
}
else if (shadowDebug.visualizationMode == ShadowDebugMode.VisualizeAtlas)
{
propertyBlock.SetVector("_TextureScaleBias", new Vector4(1.0f, 1.0f, 0.0f, 0.0f));
debugCB.SetViewport(new Rect(x, y, overlaySize, overlaySize));
debugCB.DrawProcedural(Matrix4x4.identity, m_DebugDisplayShadowMap, 0, MeshTopology.Triangles, 6, 1, propertyBlock);
NextOverlayCoord(ref x, ref y, overlaySize, camera.pixelWidth);
}
}
renderContext.ExecuteCommandBuffer(debugCB);
}
// Function to prepare light structure for GPU lighting
void PrepareLightsForGPU(ShadowSettings shadowSettings, CullResults cullResults, Camera camera, ref ShadowOutput shadowOutput)

m_lightLoop.PushGlobalParams(hdCamera.camera, renderContext);
}
void ApplyDebugParameters()
{
m_ShadowSettings.enabled = m_GlobalDebugParameters.shadowDebugParameters.enableShadows;
}
void UpdateCommonSettings()
{
if(m_CommonSettings == null)

}
else
{
m_ShadowSettings.maxShadowDistance = m_CommonSettings.shadowMaxDistance;
m_ShadowSettings.maxShadowDistance = m_CommonSettings.shadowMaxDistance;
}
}

// Do anything we need to do upon a new frame.
m_lightLoop.NewFrame();
ApplyDebugParameters();
UpdateCommonSettings();
// Set Frame constant buffer

}
else
{
ShadowOutput shadows;
m_ShadowPass.Render(renderContext, cullResults, out shadows);
m_ShadowPass.Render(renderContext, cullResults, out m_ShadowsResult);
}
renderContext.SetupCameraProperties(camera); // Need to recall SetupCameraProperties after m_ShadowPass.Render

m_lightLoop.PrepareLightsForGPU(m_ShadowSettings, cullResults, camera, ref shadows);
m_lightLoop.PrepareLightsForGPU(m_ShadowSettings, cullResults, camera, ref m_ShadowsResult);
m_lightLoop.BuildGPULightLists(camera, renderContext, m_CameraDepthBufferRT); // TODO: Use async compute here to run light culling during shadow
}

RenderDistortion(cullResults, camera, renderContext);
FinalPass(camera, renderContext);
RenderDebugOverlay(camera, renderContext);
}
// bind depth surface for editor grid/gizmo/selection rendering

25
Assets/ScriptableRenderLoop/RenderPasses/ShadowRenderPass.cs


public int directionalLightCascadeCount;
public Vector3 directionalLightCascades;
static ShadowSettings defaultShadowSettings = null;
ShadowSettings settings = new ShadowSettings();
settings.enabled = true;
settings.shadowAtlasHeight = settings.shadowAtlasWidth = 4096;
settings.directionalLightCascadeCount = 1;
settings.directionalLightCascades = new Vector3(0.05F, 0.2F, 0.3F);
settings.directionalLightCascadeCount = 4;
settings.maxShadowDistance = 1000.0F;
return settings;
if (defaultShadowSettings == null)
{
defaultShadowSettings = new ShadowSettings();
defaultShadowSettings.enabled = true;
defaultShadowSettings.shadowAtlasHeight = defaultShadowSettings.shadowAtlasWidth = 4096;
defaultShadowSettings.directionalLightCascadeCount = 1;
defaultShadowSettings.directionalLightCascades = new Vector3(0.05F, 0.2F, 0.3F);
defaultShadowSettings.directionalLightCascadeCount = 4;
defaultShadowSettings.maxShadowDistance = 1000.0F;
}
return defaultShadowSettings;
}
}
}

int m_ShadowTexName;
const int k_DepthBuffer = 24;
public int shadowTexName
{
get { return m_ShadowTexName; }
}
public ShadowRenderPass(ShadowSettings settings)
{

if (!m_Settings.enabled)
{
ClearPackedShadows(cullResults.visibleLights, out packedShadows);
return;
}
// Pack all shadow quads into the texture

9
Assets/TestScenes/HDTest/CascadedShadowsTest.meta


fileFormatVersion: 2
guid: ab939294412b89e49b889738eeeb844a
folderAsset: yes
timeCreated: 1485274537
licenseType: Pro
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:

1001
Assets/TestScenes/HDTest/CascadedShadowsTest.unity
文件差异内容过多而无法显示
查看文件

8
Assets/TestScenes/HDTest/CascadedShadowsTest.unity.meta


fileFormatVersion: 2
guid: e30864c7c4266b24cb1c708c206200a6
timeCreated: 1483527925
licenseType: Pro
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:

160
Assets/TestScenes/HDTest/CascadedShadowsTest/Lit_Gray.mat


%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!21 &2100000
Material:
serializedVersion: 6
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_Name: Lit_Gray
m_Shader: {fileID: 4800000, guid: 6e4ae4064600d784cac1e41a9e6f2e59, type: 3}
m_ShaderKeywords: _ALPHACUTOFFENABLE_OFF _DEPTHOFFSETENABLE_OFF _DETAIL_MAP_WITH_NORMAL
_DISTORTIONDEPTHTEST_OFF _DISTORTIONENABLE_OFF _DISTORTIONONLY_OFF _ENABLEPERPIXELDISPLACEMENT_OFF
_NORMALMAP_TANGENT_SPACE
m_LightmapFlags: 4
m_EnableInstancingVariants: 0
m_CustomRenderQueue: -1
stringTagMap: {}
disabledShaderPasses:
- DistortionVectors
m_SavedProperties:
serializedVersion: 3
m_TexEnvs:
- _AnisotropyMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _BaseColorMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _BumpMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _DetailAlbedoMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _DetailMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _DetailMask:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _DetailNormalMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _DistortionVectorMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _EmissionMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _EmissiveColorMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _HeightMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _MainTex:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _MaskMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _MetallicGlossMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _NormalMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _OcclusionMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _ParallaxMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _SpecularOcclusionMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _SubSurfaceRadiusMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _TangentMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
m_Floats:
- _AlphaCutoff: 0.5
- _AlphaCutoffEnable: 0
- _Anisotropy: 0
- _BlendMode: 0
- _BumpScale: 1
- _CullMode: 2
- _Cutoff: 0.5
- _DepthOffsetEnable: 0
- _DetailAOScale: 1
- _DetailAlbedoScale: 1
- _DetailHeightScale: 1
- _DetailMapMode: 0
- _DetailNormalMapScale: 1
- _DetailNormalScale: 1
- _DetailSmoothnessScale: 1
- _DistortionDepthTest: 0
- _DistortionEnable: 0
- _DistortionOnly: 0
- _DoubleSidedMode: 0
- _DstBlend: 0
- _EmissiveColorMode: 1
- _EmissiveIntensity: 0
- _EnablePerPixelDisplacement: 0
- _GlossMapScale: 1
- _Glossiness: 0.5
- _GlossyReflections: 1
- _HeightAmplitude: 0.01
- _HeightCenter: 0.5
- _MaterialId: 0
- _Metallic: 0
- _Mode: 0
- _NormalMapSpace: 0
- _NormalScale: 1
- _OcclusionStrength: 1
- _PPDMaxSamples: 15
- _PPDMinSamples: 5
- _Parallax: 0.02
- _Smoothness: 0.5
- _SmoothnessTextureChannel: 0
- _SpecularHighlights: 1
- _SrcBlend: 1
- _SubSurfaceRadius: 0
- _SurfaceType: 0
- _TexWorldScale: 1
- _UVBase: 0
- _UVDetail: 0
- _UVMappingPlanar: 0
- _UVSec: 0
- _ZTestMode: 8
- _ZWrite: 1
m_Colors:
- _BaseColor: {r: 0.49803922, g: 0.49803922, b: 0.49803922, a: 1}
- _Color: {r: 1, g: 1, b: 1, a: 1}
- _EmissionColor: {r: 0, g: 0, b: 0, a: 1}
- _EmissiveColor: {r: 0, g: 0, b: 0, a: 1}
- _UVDetailsMappingMask: {r: 1, g: 0, b: 0, a: 0}
- _UVMappingMask: {r: 1, g: 0, b: 0, a: 0}

9
Assets/TestScenes/HDTest/CascadedShadowsTest/Lit_Gray.mat.meta


fileFormatVersion: 2
guid: 906f2e00230e2a34b832d52909cc5906
timeCreated: 1485274548
licenseType: Pro
NativeFormatImporter:
mainObjectFileID: 2100000
userData:
assetBundleName:
assetBundleVariant:
正在加载...
取消
保存