Skip to content

Commit f8b2b5c

Browse files
committed
Hierarchical Variance Screen Space Shadows. Backing up current state. Cascade logic is almost done being setup now - so quality isnt there quite yet, but the full algorithm is implemented.
HVSSS Cascades all setup and working. Added high quality filter modes. Need to expose these as toggleable keywords. Need to expose sample count as tuneable parameter. Need to cleanup some code. More iteration Backing up latest work. Includes general code cleanup, as well as more robust handling of depth buffer thickness heuristic Added support for mip bias while raymarching depth lods. Set our sample count back to 10 Only apply HVSSS in Deferred or Forward passes (skips things like DynamicGI and Volumetrics - for now). Forward is a little bit of a hack, it assumes that the depth of the forward renderered geometry is the same or very similar to the depth buffer depth. For opaque surfaces, this is true because depth prepass is enabled. For transparent objects this is not necessarily true. Lets see how this goes. Remove HVSSS keywords. Not using a variant for HVSSS. Stop using uint[4] for compute parameters, use a Vector4 instead. While the data is technically uint, its not worth the hassle of managing heap allocated arrays to pass the data through. RenderGraph does have an API to allow temporary allocations of arrays for this purpose, but it still feels like overkill. We dont need the precision of full uint. a float gives us 2^24 exact integers, which is enough for our use case. Fix up bilateral filtering. Added optional screen space vignette. Added fullscreen debug view. Fixed cpu uint[] -> Vector4 conversion logic HVSSS F16 Support HVSSS: Cleanup to raymarch loop. Evaluating 4x samples per loop iteration to help hide TEX unit latency. Implemented R16G16B16A16_UNorm discretized version of moments shadow mapping for HVSSS - seems to out perform even R32G32_SFloat VSM (more robust shadows / far less edge artifacts). Still havent gotten a nicely working implementation of the thickness heuristic for Moments, but maybe thats not important for our look afterall. Bugfix to view space depth calculation during light range limit cpu side. Tuned output of moments shadow data to avoid light gray areas dominating the screen in certain self intersection cases (by clipping off the top of the distribution) Got a tuned thickness that feels pretty good with moments, and makes intuitive sense Move HVSSS related rendergraph data and functions into its own partial HDRenderPipeline class. spacing Minor include cleanup Break HVSSSModes into different kernels so they can be toggled at runtime. HVSSS: More work exposing parameters HVSSS: Cleanup to raymarch setup code Fix bug in VSM32 linear initialization HVSSS: More stabilizing of depth thickness heuristic across all parameter settings HVSSS: More cleanup to dither HVSSS Dither Bugfix HVSSS: Cleanup to Transmission Accumulator. Additionally, early out if center pixel is outside of light range. Additionally, do not self shadow during raymarching (cleaned up a bunch of 1 pixel artifacts). HVSSS: More fixes to the transmissive accumulator HVSSS: Different base thickness scales for VSM32, VSM16, and Moments HVSSS: Retune defaults HVSSS: Bugfixes to VSM16 brings its quality to almost visually identical to VSM32 HVSSS: Disable debug symbols Add #if defined(SHADERPASS) guards to HVSSS sampling - previously if SHADERPASS wasnt defined at all HVSSS could also be enabled HVSSS another define guard tweaked hvsss defaults
1 parent d87a45a commit f8b2b5c

35 files changed

+1814
-57
lines changed

com.unity.render-pipelines.high-definition/Editor/Lighting/HDLightUI.Skin.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ sealed class Styles
1717
public readonly GUIContent shadowHeader = new GUIContent("Shadows");
1818
public readonly GUIContent shadowMapSubHeader = new GUIContent("Shadow Map");
1919
public readonly GUIContent contactShadowsSubHeader = new GUIContent("Contact Shadows");
20+
public readonly GUIContent hiearchicalVarianceScreenSpaceShadowsSubHeader = new GUIContent("Hierarchical Variance Screen Space Shadows");
2021
public readonly GUIContent bakedShadowsSubHeader = new GUIContent("Baked Shadows");
2122
public readonly GUIContent veryHighShadowQualitySubHeader = new GUIContent("Very High Quality Settings");
2223
public readonly GUIContent highShadowQualitySubHeader = new GUIContent("High Quality Settings");
@@ -148,6 +149,8 @@ sealed class Styles
148149
public readonly GUIContent evsmLightLeakBias = new GUIContent("Light Leak Bias", "Increasing this value light leaking, but it eats up a bit of the softness of the shadow.");
149150
public readonly GUIContent evsmVarianceBias = new GUIContent("Variance Bias", "Variance Bias for EVSM. This is to contrast numerical accuracy issues. ");
150151
public readonly GUIContent evsmAdditionalBlurPasses = new GUIContent("Blur passes", "Increasing this will increase the softness of the shadow, but it will severely impact performance.");
152+
public readonly GUIContent useHierarchicalVarianceScreenSpaceShadows = new GUIContent("Enable", "Reccomended to only use for hero lights like character shadow casters.");
153+
public readonly GUIContent hierarchicalVarianceScreenSpaceShadowsPenumbraRadius = new GUIContent("Penumbra Radius", "Controls softness of HVSSS shadows. Parameterized in meters around the light source (think spherical area lights).");
151154

152155
// Very high shadow settings
153156
public readonly GUIContent lightAngle = new GUIContent("Light Angle");

com.unity.render-pipelines.high-definition/Editor/Lighting/HDLightUI.cs

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ enum Expandable
4545
BakedShadow = 1 << 7,
4646
ShadowQuality = 1 << 8,
4747
CelestialBody = 1 << 9,
48+
HierarchicalVarianceScreenSpaceShadows = 1 << 10
4849
}
4950

5051
enum AdvancedMode
@@ -135,7 +136,9 @@ static HDLightUI()
135136
CED.Conditional((serialized, owner) => HasShadowQualitySettingsUI(HDShadowFilteringQuality.Low, serialized, owner),
136137
CED.FoldoutGroup(s_Styles.lowShadowQualitySubHeader, Expandable.ShadowQuality, k_ExpandedState, FoldoutOption.SubFoldout | FoldoutOption.Indent, DrawLowShadowSettingsContent)),
137138
CED.Conditional((serialized, owner) => serialized.type != HDLightType.Area,
138-
CED.FoldoutGroup(s_Styles.contactShadowsSubHeader, Expandable.ContactShadow, k_ExpandedState, FoldoutOption.SubFoldout | FoldoutOption.Indent | FoldoutOption.NoSpaceAtEnd, DrawContactShadowsContent)
139+
CED.FoldoutGroup(s_Styles.contactShadowsSubHeader, Expandable.ContactShadow, k_ExpandedState, FoldoutOption.SubFoldout | FoldoutOption.Indent | FoldoutOption.NoSpaceAtEnd, DrawContactShadowsContent)),
140+
CED.Conditional((serialized, owner) => serialized.type == HDLightType.Point || serialized.type == HDLightType.Spot,
141+
CED.FoldoutGroup(s_Styles.hiearchicalVarianceScreenSpaceShadowsSubHeader, Expandable.HierarchicalVarianceScreenSpaceShadows, k_ExpandedState, FoldoutOption.SubFoldout | FoldoutOption.Indent | FoldoutOption.NoSpaceAtEnd, DrawHierarchicalVarianceScreenSpaceShadowsContent)
139142
)
140143
),
141144
CED.noop //will only add parameter in first sub header
@@ -1262,6 +1265,24 @@ static void DrawContactShadowsContent(SerializedHDLight serialized, Editor owner
12621265
}
12631266
}
12641267

1268+
static void DrawHierarchicalVarianceScreenSpaceShadowsContent(SerializedHDLight serialized, Editor owner)
1269+
{
1270+
HDLightType lightType = serialized.type;
1271+
1272+
// For the moment, we only support hierarchical variance screen space shadows for point and spot lights. Might be interesting to extend to area lights (but not a priority).
1273+
if ((lightType == HDLightType.Point) || (lightType == HDLightType.Spot) && HDRenderPipeline.pipelineSupportsHierarchicalVarianceScreenSpaceShadows)
1274+
{
1275+
EditorGUILayout.PropertyField(serialized.useHierarchicalVarianceScreenSpaceShadows, s_Styles.useHierarchicalVarianceScreenSpaceShadows);
1276+
1277+
using (new EditorGUI.DisabledScope(!serialized.useHierarchicalVarianceScreenSpaceShadows.boolValue))
1278+
{
1279+
EditorGUI.indentLevel++;
1280+
EditorGUILayout.PropertyField(serialized.hierarchicalVarianceScreenSpaceShadowsPenumbraRadius, s_Styles.hierarchicalVarianceScreenSpaceShadowsPenumbraRadius);
1281+
EditorGUI.indentLevel--;
1282+
}
1283+
}
1284+
}
1285+
12651286
static void DrawBakedShadowsContent(SerializedHDLight serialized, Editor owner)
12661287
{
12671288
DrawEnableShadowMap(serialized, owner);

com.unity.render-pipelines.high-definition/Editor/Lighting/SerializedHDLight.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@ internal class SerializedHDLight
5050
public SerializedProperty useCustomSpotLightShadowCone;
5151
public SerializedProperty customSpotLightShadowCone;
5252
public SerializedProperty useScreenSpaceShadows;
53+
public SerializedProperty useHierarchicalVarianceScreenSpaceShadows;
54+
public SerializedProperty hierarchicalVarianceScreenSpaceShadowsPenumbraRadius;
5355
public SerializedProperty interactsWithSky;
5456
public SerializedProperty angularDiameter;
5557
public SerializedProperty flareSize;
@@ -368,6 +370,8 @@ public SerializedHDLight(HDAdditionalLightData[] lightDatas, LightEditor.Setting
368370
useCustomSpotLightShadowCone = o.Find("m_UseCustomSpotLightShadowCone");
369371
customSpotLightShadowCone = o.Find("m_CustomSpotLightShadowCone");
370372
useScreenSpaceShadows = o.Find("m_UseScreenSpaceShadows");
373+
useHierarchicalVarianceScreenSpaceShadows = o.Find("m_UseHierarchicalVarianceScreenSpaceShadows");
374+
hierarchicalVarianceScreenSpaceShadowsPenumbraRadius = o.Find("m_HierarchicalVarianceScreenSpaceShadowsPenumbraRadius");
371375
interactsWithSky = o.Find("m_InteractsWithSky");
372376
angularDiameter = o.Find("m_AngularDiameter");
373377
flareSize = o.Find("m_FlareSize");

com.unity.render-pipelines.high-definition/Editor/RenderPipeline/HDRenderPipelineUI.Skin.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,7 @@ public class GeneralSection
202202

203203
public static readonly GUIContent useContactShadows = EditorGUIUtility.TrTextContent("Use Contact Shadows", "Use contact shadows for lights.");
204204
public static readonly GUIContent supportScreenSpaceShadows = EditorGUIUtility.TrTextContent("Screen Space Shadows", "Enables the support of screen space shadows in HDRP.");
205+
public static readonly GUIContent supportHierarchicalVarianceScreenSpaceShadows = EditorGUIUtility.TrTextContent("Hierarchical Variance Screen Space Shadows", "Enables the support of hierarhical variance screen space shadows in HDRP.");
205206
public static readonly GUIContent maxScreenSpaceShadowSlots = EditorGUIUtility.TrTextContent("Maximum", "Sets the maximum number of screen space shadows slots HDRP can handle on screen at once. Opaque shadows requires one slot, color shadow requires three.");
206207
public static readonly GUIContent screenSpaceShadowFormat = EditorGUIUtility.TrTextContent("Buffer Format", "Defines the format of the buffer used for screen space shadows. The buffer format can be R8G8B8A8 or R16G16B16A16.");
207208
public static readonly GUIContent maxShadowResolution = EditorGUIUtility.TrTextContent("Max shadow resolution", "Specifies the maximum resolution for any single shadow map.");

com.unity.render-pipelines.high-definition/Editor/RenderPipeline/HDRenderPipelineUI.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -373,6 +373,8 @@ static void Drawer_SectionShadows(SerializedHDRenderPipelineAsset serialized, Ed
373373
--EditorGUI.indentLevel;
374374
}
375375

376+
EditorGUILayout.PropertyField(serialized.renderPipelineSettings.hdShadowInitParams.supportHierarchicalVarianceScreenSpaceShadows, Styles.supportHierarchicalVarianceScreenSpaceShadows);
377+
376378
SerializedScalableSettingUI.ValueGUI<bool>(serialized.renderPipelineSettings.lightSettings.useContactShadows, Styles.useContactShadows);
377379

378380
m_ShowDirectionalLightSection = EditorGUILayout.Foldout(m_ShowDirectionalLightSection, Styles.directionalShadowsSubTitle, true);

com.unity.render-pipelines.high-definition/Editor/RenderPipeline/Settings/FrameSettingsUI.Drawers.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -344,6 +344,7 @@ static void Drawer_SectionLightingSettings(SerializedFrameSettings serialized, E
344344
area.AmmendInfo(FrameSettingsField.ProbeVolume, overrideable: () => hdrpSettings.supportProbeVolume);
345345
area.AmmendInfo(FrameSettingsField.ProbeVolumeDynamicGI, overrideable: () => hdrpSettings.supportProbeVolumeDynamicGI);
346346
area.AmmendInfo(FrameSettingsField.ScreenSpaceShadows, overrideable: () => hdrpSettings.hdShadowInitParams.supportScreenSpaceShadows);
347+
area.AmmendInfo(FrameSettingsField.HierarchicalVarianceScreenSpaceShadows, overrideable: () => hdrpSettings.hdShadowInitParams.supportHierarchicalVarianceScreenSpaceShadows);
347348
area.Draw(withOverride);
348349
}
349350

com.unity.render-pipelines.high-definition/Editor/RenderPipeline/Settings/SerializedHDShadowInitParameters.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ class SerializedHDShadowInitParameters
3333
public SerializedProperty shadowFilteringQuality;
3434

3535
public SerializedProperty supportScreenSpaceShadows;
36+
public SerializedProperty supportHierarchicalVarianceScreenSpaceShadows;
3637
public SerializedProperty maxScreenSpaceShadowSlots;
3738
public SerializedProperty screenSpaceShadowBufferFormat;
3839

@@ -65,6 +66,7 @@ public SerializedHDShadowInitParameters(SerializedProperty root)
6566

6667
shadowFilteringQuality = root.Find((HDShadowInitParameters s) => s.shadowFilteringQuality);
6768
supportScreenSpaceShadows = root.Find((HDShadowInitParameters s) => s.supportScreenSpaceShadows);
69+
supportHierarchicalVarianceScreenSpaceShadows = root.Find((HDShadowInitParameters s) => s.supportHierarchicalVarianceScreenSpaceShadows);
6870
maxScreenSpaceShadowSlots = root.Find((HDShadowInitParameters s) => s.maxScreenSpaceShadowSlots);
6971
screenSpaceShadowBufferFormat = root.Find((HDShadowInitParameters s) => s.screenSpaceShadowBufferFormat);
7072
}

com.unity.render-pipelines.high-definition/Runtime/Debug/DebugDisplay.cs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,8 @@ public enum FullScreenDebugMode
7777
DepthPyramid,
7878
/// <summary>Display the final color pyramid for the frame.</summary>
7979
FinalColorPyramid,
80+
/// <summary>Display Hierarchical Variance Screen Space Shadows buffer.</summary>
81+
HierarchicalVarianceScreenSpaceShadows,
8082

8183
// Raytracing Only
8284
/// <summary>Display ray tracing light cluster.</summary>
@@ -129,7 +131,7 @@ public enum FullScreenDebugMode
129131
/// <summary>Display Screen Space Reflections buffer of the previous frame accumulated.</summary>
130132
ScreenSpaceReflectionsPrev,
131133
/// <summary>Display Screen Space Reflections buffer of the current frame hit.</summary>
132-
ScreenSpaceReflectionsAccum
134+
ScreenSpaceReflectionsAccum,
133135
}
134136

135137
/// <summary>
@@ -640,6 +642,11 @@ public void SetFullScreenDebugMode(FullScreenDebugMode value)
640642
data.fullScreenDebugMode = value;
641643
}
642644

645+
public FullScreenDebugMode GetFullScreenDebugMode()
646+
{
647+
return data.fullScreenDebugMode;
648+
}
649+
643650
/// <summary>
644651
/// Set the current Shadow Map Debug Mode.
645652
/// </summary>

com.unity.render-pipelines.high-definition/Runtime/Debug/DebugDisplay.cs.hlsl

Lines changed: 24 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -18,29 +18,30 @@
1818
#define FULLSCREENDEBUGMODE_PRE_REFRACTION_COLOR_PYRAMID (8)
1919
#define FULLSCREENDEBUGMODE_DEPTH_PYRAMID (9)
2020
#define FULLSCREENDEBUGMODE_FINAL_COLOR_PYRAMID (10)
21-
#define FULLSCREENDEBUGMODE_LIGHT_CLUSTER (11)
22-
#define FULLSCREENDEBUGMODE_SCREEN_SPACE_GLOBAL_ILLUMINATION (12)
23-
#define FULLSCREENDEBUGMODE_RECURSIVE_RAY_TRACING (13)
24-
#define FULLSCREENDEBUGMODE_RAY_TRACED_SUB_SURFACE (14)
25-
#define FULLSCREENDEBUGMODE_MAX_LIGHTING_FULL_SCREEN_DEBUG (15)
26-
#define FULLSCREENDEBUGMODE_MIN_RENDERING_FULL_SCREEN_DEBUG (16)
27-
#define FULLSCREENDEBUGMODE_MOTION_VECTORS (17)
28-
#define FULLSCREENDEBUGMODE_NAN_TRACKER (18)
29-
#define FULLSCREENDEBUGMODE_COLOR_LOG (19)
30-
#define FULLSCREENDEBUGMODE_GRAYSCALE (20)
31-
#define FULLSCREENDEBUGMODE_DEPTH_OF_FIELD_COC (21)
32-
#define FULLSCREENDEBUGMODE_TRANSPARENCY_OVERDRAW (22)
33-
#define FULLSCREENDEBUGMODE_QUAD_OVERDRAW (23)
34-
#define FULLSCREENDEBUGMODE_VERTEX_DENSITY (24)
35-
#define FULLSCREENDEBUGMODE_REQUESTED_VIRTUAL_TEXTURE_TILES (25)
36-
#define FULLSCREENDEBUGMODE_MAX_RENDERING_FULL_SCREEN_DEBUG (26)
37-
#define FULLSCREENDEBUGMODE_MIN_MATERIAL_FULL_SCREEN_DEBUG (27)
38-
#define FULLSCREENDEBUGMODE_VALIDATE_DIFFUSE_COLOR (28)
39-
#define FULLSCREENDEBUGMODE_VALIDATE_SPECULAR_COLOR (29)
40-
#define FULLSCREENDEBUGMODE_HEIGHTMAPS (30)
41-
#define FULLSCREENDEBUGMODE_MAX_MATERIAL_FULL_SCREEN_DEBUG (31)
42-
#define FULLSCREENDEBUGMODE_SCREEN_SPACE_REFLECTIONS_PREV (32)
43-
#define FULLSCREENDEBUGMODE_SCREEN_SPACE_REFLECTIONS_ACCUM (33)
21+
#define FULLSCREENDEBUGMODE_HIERARCHICAL_VARIANCE_SCREEN_SPACE_SHADOWS (11)
22+
#define FULLSCREENDEBUGMODE_LIGHT_CLUSTER (12)
23+
#define FULLSCREENDEBUGMODE_SCREEN_SPACE_GLOBAL_ILLUMINATION (13)
24+
#define FULLSCREENDEBUGMODE_RECURSIVE_RAY_TRACING (14)
25+
#define FULLSCREENDEBUGMODE_RAY_TRACED_SUB_SURFACE (15)
26+
#define FULLSCREENDEBUGMODE_MAX_LIGHTING_FULL_SCREEN_DEBUG (16)
27+
#define FULLSCREENDEBUGMODE_MIN_RENDERING_FULL_SCREEN_DEBUG (17)
28+
#define FULLSCREENDEBUGMODE_MOTION_VECTORS (18)
29+
#define FULLSCREENDEBUGMODE_NAN_TRACKER (19)
30+
#define FULLSCREENDEBUGMODE_COLOR_LOG (20)
31+
#define FULLSCREENDEBUGMODE_GRAYSCALE (21)
32+
#define FULLSCREENDEBUGMODE_DEPTH_OF_FIELD_COC (22)
33+
#define FULLSCREENDEBUGMODE_TRANSPARENCY_OVERDRAW (23)
34+
#define FULLSCREENDEBUGMODE_QUAD_OVERDRAW (24)
35+
#define FULLSCREENDEBUGMODE_VERTEX_DENSITY (25)
36+
#define FULLSCREENDEBUGMODE_REQUESTED_VIRTUAL_TEXTURE_TILES (26)
37+
#define FULLSCREENDEBUGMODE_MAX_RENDERING_FULL_SCREEN_DEBUG (27)
38+
#define FULLSCREENDEBUGMODE_MIN_MATERIAL_FULL_SCREEN_DEBUG (28)
39+
#define FULLSCREENDEBUGMODE_VALIDATE_DIFFUSE_COLOR (29)
40+
#define FULLSCREENDEBUGMODE_VALIDATE_SPECULAR_COLOR (30)
41+
#define FULLSCREENDEBUGMODE_HEIGHTMAPS (31)
42+
#define FULLSCREENDEBUGMODE_MAX_MATERIAL_FULL_SCREEN_DEBUG (32)
43+
#define FULLSCREENDEBUGMODE_SCREEN_SPACE_REFLECTIONS_PREV (33)
44+
#define FULLSCREENDEBUGMODE_SCREEN_SPACE_REFLECTIONS_ACCUM (34)
4445

4546
// Generated from UnityEngine.Rendering.HighDefinition.ShaderVariablesDebugDisplay
4647
// PackingRules = Exact

com.unity.render-pipelines.high-definition/Runtime/Debug/DebugFullScreen.shader

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -412,6 +412,10 @@ Shader "Hidden/HDRP/DebugFullScreen"
412412
return float4(HsvToRgb(hsv), 1.0f);
413413

414414
}
415+
if (_FullScreenDebugMode == FULLSCREENDEBUGMODE_HIERARCHICAL_VARIANCE_SCREEN_SPACE_SHADOWS)
416+
{
417+
return SRGBToLinear(SAMPLE_TEXTURE2D_X(_DebugFullScreenTexture, s_point_clamp_sampler, input.texcoord).xxxx);
418+
}
415419

416420
return float4(0.0, 0.0, 0.0, 0.0);
417421
}

0 commit comments

Comments
 (0)