Skip to content

Commit bb5951d

Browse files
Merge pull request #180 from Unity-Technologies/Branch_DebugCascade
Added a lighting debug mode to visualize Cascaded shadow splits.
2 parents 467a3b7 + 727e922 commit bb5951d

9 files changed

Lines changed: 53 additions & 15 deletions

File tree

Assets/ScriptableRenderPipeline/HDRenderPipeline/Debug/HDRenderPipelineDebug.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public class RenderingDebugSettings
3939
public bool enableSSS = true;
4040
}
4141

42-
public enum ShadowDebugMode
42+
public enum ShadowMapDebugMode
4343
{
4444
None,
4545
VisualizeAtlas,
@@ -51,14 +51,15 @@ public enum LightingDebugMode
5151
{
5252
None,
5353
DiffuseLighting,
54-
SpecularLighting
54+
SpecularLighting,
55+
VisualizeCascade
5556
}
5657

5758
[Serializable]
5859
public class LightingDebugSettings
5960
{
6061
public bool enableShadows = true;
61-
public ShadowDebugMode shadowDebugMode = ShadowDebugMode.None;
62+
public ShadowMapDebugMode shadowDebugMode = ShadowMapDebugMode.None;
6263
public uint shadowMapIndex = 0;
6364

6465
public LightingDebugMode lightingDebugMode = LightingDebugMode.None;

Assets/ScriptableRenderPipeline/HDRenderPipeline/Debug/HDRenderPipelineDebug.cs.hlsl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#define LIGHTINGDEBUGMODE_NONE (0)
1111
#define LIGHTINGDEBUGMODE_DIFFUSE_LIGHTING (1)
1212
#define LIGHTINGDEBUGMODE_SPECULAR_LIGHTING (2)
13+
#define LIGHTINGDEBUGMODE_VISUALIZE_CASCADE (3)
1314

1415

1516
#endif

Assets/ScriptableRenderPipeline/HDRenderPipeline/Editor/HDRenderPipelineInspector.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ private class Styles
8181
// Lighting Debug
8282
public readonly GUIContent lightingDebugSettings = new GUIContent("Lighting Debug");
8383
public readonly GUIContent shadowDebugEnable = new GUIContent("Enable Shadows");
84-
public readonly GUIContent shadowDebugVisualizationMode = new GUIContent("Shadow Debug Mode");
84+
public readonly GUIContent shadowDebugVisualizationMode = new GUIContent("Shadow Maps Debug Mode");
8585
public readonly GUIContent shadowDebugVisualizeShadowIndex = new GUIContent("Visualize Shadow Index");
8686
public readonly GUIContent lightingDebugMode = new GUIContent("Lighting Debug Mode");
8787
public readonly GUIContent lightingDebugOverrideSmoothness = new GUIContent("Override Smoothness");
@@ -454,7 +454,7 @@ private void LightingDebugSettingsUI(HDRenderPipeline renderContext, HDRenderPip
454454
EditorGUILayout.PropertyField(m_ShadowDebugMode, styles.shadowDebugVisualizationMode);
455455
if (!m_ShadowDebugMode.hasMultipleDifferentValues)
456456
{
457-
if ((ShadowDebugMode)m_ShadowDebugMode.intValue == ShadowDebugMode.VisualizeShadowMap)
457+
if ((ShadowMapDebugMode)m_ShadowDebugMode.intValue == ShadowMapDebugMode.VisualizeShadowMap)
458458
{
459459
EditorGUILayout.IntSlider(m_ShadowDebugShadowMapIndex, 0, renderpipelineInstance.GetCurrentShadowCount() - 1, styles.shadowDebugVisualizeShadowIndex);
460460
}

Assets/ScriptableRenderPipeline/HDRenderPipeline/HDRenderPipeline.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -976,9 +976,9 @@ void RenderDebugOverlay(Camera camera, ScriptableRenderContext renderContext)
976976

977977
LightingDebugSettings lightingDebug = globalDebugSettings.lightingDebugSettings;
978978

979-
if (lightingDebug.shadowDebugMode != ShadowDebugMode.None)
979+
if (lightingDebug.shadowDebugMode != ShadowMapDebugMode.None)
980980
{
981-
if (lightingDebug.shadowDebugMode == ShadowDebugMode.VisualizeShadowMap)
981+
if (lightingDebug.shadowDebugMode == ShadowMapDebugMode.VisualizeShadowMap)
982982
{
983983
uint visualizeShadowIndex = Math.Min(lightingDebug.shadowMapIndex, (uint)(GetCurrentShadowCount() - 1));
984984
ShadowLight shadowLight = m_ShadowsResult.shadowLights[visualizeShadowIndex];
@@ -999,7 +999,7 @@ void RenderDebugOverlay(Camera camera, ScriptableRenderContext renderContext)
999999
NextOverlayCoord(ref x, ref y, overlaySize, camera.pixelWidth);
10001000
}
10011001
}
1002-
else if (lightingDebug.shadowDebugMode == ShadowDebugMode.VisualizeAtlas)
1002+
else if (lightingDebug.shadowDebugMode == ShadowMapDebugMode.VisualizeAtlas)
10031003
{
10041004
propertyBlock.SetVector("_TextureScaleBias", new Vector4(1.0f, 1.0f, 0.0f, 0.0f));
10051005

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ public class LightDefinitions
134134
public static int USE_LEFTHAND_CAMERASPACE = 1;
135135

136136
public static int TILE_SIZE_FPTL = 16;
137-
public static int TILE_SIZE_CLUSTERED = 32;
137+
public static int TILE_SIZE_CLUSTERED = 16;
138138

139139
// flags
140140
public static int IS_CIRCULAR_SPOT_SHAPE = 1;

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
#define VIEWPORT_SCALE_Z (1)
2929
#define USE_LEFTHAND_CAMERASPACE (1)
3030
#define TILE_SIZE_FPTL (16)
31-
#define TILE_SIZE_CLUSTERED (32)
31+
#define TILE_SIZE_CLUSTERED (16)
3232
#define IS_CIRCULAR_SPOT_SHAPE (1)
3333
#define HAS_COOKIE_TEXTURE (2)
3434
#define IS_BOX_PROJECTED (4)

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

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// LightLoop
33
// ----------------------------------------------------------------------------
44

5-
void ApplyDebug(inout float3 diffuseLighting, inout float3 specularLighting)
5+
void ApplyDebug(LightLoopContext lightLoopContext, float3 positionWS, inout float3 diffuseLighting, inout float3 specularLighting)
66
{
77
#ifdef LIGHTING_DEBUG
88
int lightDebugMode = (int)_DebugLightModeAndAlbedo.x;
@@ -15,6 +15,32 @@ void ApplyDebug(inout float3 diffuseLighting, inout float3 specularLighting)
1515
{
1616
diffuseLighting = float3(0.0, 0.0, 0.0);
1717
}
18+
else if (lightDebugMode == LIGHTINGDEBUGMODE_VISUALIZE_CASCADE)
19+
{
20+
specularLighting = float3(0.0, 0.0, 0.0);
21+
22+
const float3 s_CascadeColors[] = {
23+
float3(1.0, 0.0, 0.0),
24+
float3(0.0, 1.0, 0.0),
25+
float3(0.0, 0.0, 1.0),
26+
float3(1.0, 1.0, 0.0)
27+
};
28+
29+
#ifdef SHADOWS_USE_SHADOWCTXT
30+
float shadow = GetDirectionalShadowAttenuation(lightLoopContext.shadowContext, positionWS, 0, float3(0.0, 0.0, 0.0), float2(0.0, 0.0));
31+
#else
32+
float shadow = GetDirectionalShadowAttenuation(lightLoopContext, positionWS, 0, float3(0.0, 0.0, 0.0), float2(0.0, 0.0));
33+
#endif
34+
35+
int shadowSplitIndex = GetSplitSphereIndexForDirshadows(positionWS, _DirShadowSplitSpheres);
36+
if (shadowSplitIndex == -1)
37+
diffuseLighting = float3(0.0, 0.0, 0.0);
38+
else
39+
{
40+
diffuseLighting = s_CascadeColors[shadowSplitIndex] * shadow;
41+
}
42+
43+
}
1844
#endif
1945
}
2046

@@ -222,7 +248,7 @@ void LightLoop( float3 V, PositionInputs posInput, PreLightData prelightData, BS
222248
diffuseLighting += bakeDiffuseLighting;
223249
#endif
224250

225-
ApplyDebug(diffuseLighting, specularLighting);
251+
ApplyDebug(context, posInput.positionWS, diffuseLighting, specularLighting);
226252
}
227253

228254
#else // LIGHTLOOP_SINGLE_PASS
@@ -322,7 +348,7 @@ void LightLoop( float3 V, PositionInputs posInput, PreLightData prelightData, BS
322348
// Add indirect diffuse + emissive (if any)
323349
diffuseLighting += bakeDiffuseLighting;
324350

325-
ApplyDebug(diffuseLighting, specularLighting);
351+
ApplyDebug(context, posInput.positionWS, diffuseLighting, specularLighting);
326352
}
327353

328354
#endif

Assets/ScriptableRenderPipeline/HDRenderPipeline/Shadow/ShadowBase.cs.hlsl

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
//
2-
// This file was automatically generated from Assets/ScriptableRenderLoop/HDRenderPipeline/Shadow/ShadowBase.cs. Please don't edit by hand.
2+
// This file was automatically generated from Assets/ScriptableRenderPipeline/HDRenderPipeline/Shadow/ShadowBase.cs. Please don't edit by hand.
33
//
44

55
#ifndef SHADOWBASE_CS_HLSL
@@ -11,6 +11,16 @@
1111
#define GPUSHADOWTYPE_SPOT (1)
1212
#define GPUSHADOWTYPE_DIRECTIONAL (2)
1313
#define GPUSHADOWTYPE_MAX (3)
14+
#define GPUSHADOWTYPE_UNKNOWN (3)
15+
#define GPUSHADOWTYPE_ALL (3)
16+
17+
//
18+
// UnityEngine.Experimental.Rendering.HDPipeline.GPUShadowSampling: static fields
19+
//
20+
#define GPUSHADOWSAMPLING_PCF_1TAP (0)
21+
#define GPUSHADOWSAMPLING_PCF_9TAPS_ADAPTIVE (1)
22+
#define GPUSHADOWSAMPLING_VSM_1TAP (2)
23+
#define GPUSHADOWSAMPLING_MSM_1TAP (3)
1424

1525
// Generated from UnityEngine.Experimental.Rendering.HDPipeline.ShadowExp.ShadowData
1626
// PackingRules = Exact

Assets/ScriptableRenderPipeline/fptl/LightDefinitions.cs.hlsl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99
//
1010
#define MAX_NR_LIGHTS_PER_CAMERA (1024)
1111
#define MAX_NR_BIGTILE_LIGHTS_PLUSONE (512)
12-
#define TILE_SIZE_CLUSTERED (32)
1312
#define VIEWPORT_SCALE_Z (1)
13+
#define TILE_SIZE_CLUSTERED (32)
1414
#define USE_LEFTHAND_CAMERASPACE (0)
1515
#define IS_CIRCULAR_SPOT_SHAPE (1)
1616
#define HAS_COOKIE_TEXTURE (2)

0 commit comments

Comments
 (0)