From e4ae29a114e84177024af99adf6a3412bb9b68e4 Mon Sep 17 00:00:00 2001 From: FrancescoC-Unity Date: Fri, 20 Mar 2020 17:29:32 +0100 Subject: [PATCH 1/8] shadow mask --- .../Lighting/LightLoop/Deferred.compute | 32 +------------------ .../Runtime/Lighting/LightLoop/LightLoop.cs | 22 +++++-------- 2 files changed, 9 insertions(+), 45 deletions(-) diff --git a/com.unity.render-pipelines.high-definition/Runtime/Lighting/LightLoop/Deferred.compute b/com.unity.render-pipelines.high-definition/Runtime/Lighting/LightLoop/Deferred.compute index 3ce1088838d..8897369216f 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/Lighting/LightLoop/Deferred.compute +++ b/com.unity.render-pipelines.high-definition/Runtime/Lighting/LightLoop/Deferred.compute @@ -1,7 +1,5 @@ #pragma kernel Deferred_Direct_Fptl SHADE_OPAQUE_ENTRY=Deferred_Direct_Fptl #pragma kernel Deferred_Direct_Fptl_DebugDisplay SHADE_OPAQUE_ENTRY=Deferred_Direct_Fptl_DebugDisplay DEBUG_DISPLAY -#pragma kernel Deferred_Direct_ShadowMask_Fptl SHADE_OPAQUE_ENTRY=Deferred_Direct_ShadowMask_Fptl SHADOWS_SHADOWMASK -#pragma kernel Deferred_Direct_ShadowMask_Fptl_DebugDisplay SHADE_OPAQUE_ENTRY=Deferred_Direct_ShadowMask_Fptl_DebugDisplay SHADOWS_SHADOWMASK DEBUG_DISPLAY // Variant with and without shadowmask #pragma kernel Deferred_Indirect_Fptl_Variant0 SHADE_OPAQUE_ENTRY=Deferred_Indirect_Fptl_Variant0 USE_INDIRECT VARIANT=0 @@ -34,35 +32,7 @@ #pragma kernel Deferred_Indirect_Fptl_Variant27 SHADE_OPAQUE_ENTRY=Deferred_Indirect_Fptl_Variant27 USE_INDIRECT VARIANT=27 #pragma kernel Deferred_Indirect_Fptl_Variant28 SHADE_OPAQUE_ENTRY=Deferred_Indirect_Fptl_Variant28 USE_INDIRECT VARIANT=28 -#pragma kernel Deferred_Indirect_ShadowMask_Fptl_Variant0 SHADE_OPAQUE_ENTRY=Deferred_Indirect_ShadowMask_Fptl_Variant0 USE_INDIRECT SHADOWS_SHADOWMASK VARIANT=0 -#pragma kernel Deferred_Indirect_ShadowMask_Fptl_Variant1 SHADE_OPAQUE_ENTRY=Deferred_Indirect_ShadowMask_Fptl_Variant1 USE_INDIRECT SHADOWS_SHADOWMASK VARIANT=1 -#pragma kernel Deferred_Indirect_ShadowMask_Fptl_Variant2 SHADE_OPAQUE_ENTRY=Deferred_Indirect_ShadowMask_Fptl_Variant2 USE_INDIRECT SHADOWS_SHADOWMASK VARIANT=2 -#pragma kernel Deferred_Indirect_ShadowMask_Fptl_Variant3 SHADE_OPAQUE_ENTRY=Deferred_Indirect_ShadowMask_Fptl_Variant3 USE_INDIRECT SHADOWS_SHADOWMASK VARIANT=3 -#pragma kernel Deferred_Indirect_ShadowMask_Fptl_Variant4 SHADE_OPAQUE_ENTRY=Deferred_Indirect_ShadowMask_Fptl_Variant4 USE_INDIRECT SHADOWS_SHADOWMASK VARIANT=4 -#pragma kernel Deferred_Indirect_ShadowMask_Fptl_Variant5 SHADE_OPAQUE_ENTRY=Deferred_Indirect_ShadowMask_Fptl_Variant5 USE_INDIRECT SHADOWS_SHADOWMASK VARIANT=5 -#pragma kernel Deferred_Indirect_ShadowMask_Fptl_Variant6 SHADE_OPAQUE_ENTRY=Deferred_Indirect_ShadowMask_Fptl_Variant6 USE_INDIRECT SHADOWS_SHADOWMASK VARIANT=6 -#pragma kernel Deferred_Indirect_ShadowMask_Fptl_Variant7 SHADE_OPAQUE_ENTRY=Deferred_Indirect_ShadowMask_Fptl_Variant7 USE_INDIRECT SHADOWS_SHADOWMASK VARIANT=7 -#pragma kernel Deferred_Indirect_ShadowMask_Fptl_Variant8 SHADE_OPAQUE_ENTRY=Deferred_Indirect_ShadowMask_Fptl_Variant8 USE_INDIRECT SHADOWS_SHADOWMASK VARIANT=8 -#pragma kernel Deferred_Indirect_ShadowMask_Fptl_Variant9 SHADE_OPAQUE_ENTRY=Deferred_Indirect_ShadowMask_Fptl_Variant9 USE_INDIRECT SHADOWS_SHADOWMASK VARIANT=9 -#pragma kernel Deferred_Indirect_ShadowMask_Fptl_Variant10 SHADE_OPAQUE_ENTRY=Deferred_Indirect_ShadowMask_Fptl_Variant10 USE_INDIRECT SHADOWS_SHADOWMASK VARIANT=10 -#pragma kernel Deferred_Indirect_ShadowMask_Fptl_Variant11 SHADE_OPAQUE_ENTRY=Deferred_Indirect_ShadowMask_Fptl_Variant11 USE_INDIRECT SHADOWS_SHADOWMASK VARIANT=11 -#pragma kernel Deferred_Indirect_ShadowMask_Fptl_Variant12 SHADE_OPAQUE_ENTRY=Deferred_Indirect_ShadowMask_Fptl_Variant12 USE_INDIRECT SHADOWS_SHADOWMASK VARIANT=12 -#pragma kernel Deferred_Indirect_ShadowMask_Fptl_Variant13 SHADE_OPAQUE_ENTRY=Deferred_Indirect_ShadowMask_Fptl_Variant13 USE_INDIRECT SHADOWS_SHADOWMASK VARIANT=13 -#pragma kernel Deferred_Indirect_ShadowMask_Fptl_Variant14 SHADE_OPAQUE_ENTRY=Deferred_Indirect_ShadowMask_Fptl_Variant14 USE_INDIRECT SHADOWS_SHADOWMASK VARIANT=14 -#pragma kernel Deferred_Indirect_ShadowMask_Fptl_Variant15 SHADE_OPAQUE_ENTRY=Deferred_Indirect_ShadowMask_Fptl_Variant15 USE_INDIRECT SHADOWS_SHADOWMASK VARIANT=15 -#pragma kernel Deferred_Indirect_ShadowMask_Fptl_Variant16 SHADE_OPAQUE_ENTRY=Deferred_Indirect_ShadowMask_Fptl_Variant16 USE_INDIRECT SHADOWS_SHADOWMASK VARIANT=16 -#pragma kernel Deferred_Indirect_ShadowMask_Fptl_Variant17 SHADE_OPAQUE_ENTRY=Deferred_Indirect_ShadowMask_Fptl_Variant17 USE_INDIRECT SHADOWS_SHADOWMASK VARIANT=17 -#pragma kernel Deferred_Indirect_ShadowMask_Fptl_Variant18 SHADE_OPAQUE_ENTRY=Deferred_Indirect_ShadowMask_Fptl_Variant18 USE_INDIRECT SHADOWS_SHADOWMASK VARIANT=18 -#pragma kernel Deferred_Indirect_ShadowMask_Fptl_Variant19 SHADE_OPAQUE_ENTRY=Deferred_Indirect_ShadowMask_Fptl_Variant19 USE_INDIRECT SHADOWS_SHADOWMASK VARIANT=19 -#pragma kernel Deferred_Indirect_ShadowMask_Fptl_Variant20 SHADE_OPAQUE_ENTRY=Deferred_Indirect_ShadowMask_Fptl_Variant20 USE_INDIRECT SHADOWS_SHADOWMASK VARIANT=20 -#pragma kernel Deferred_Indirect_ShadowMask_Fptl_Variant21 SHADE_OPAQUE_ENTRY=Deferred_Indirect_ShadowMask_Fptl_Variant21 USE_INDIRECT SHADOWS_SHADOWMASK VARIANT=21 -#pragma kernel Deferred_Indirect_ShadowMask_Fptl_Variant22 SHADE_OPAQUE_ENTRY=Deferred_Indirect_ShadowMask_Fptl_Variant22 USE_INDIRECT SHADOWS_SHADOWMASK VARIANT=22 -#pragma kernel Deferred_Indirect_ShadowMask_Fptl_Variant23 SHADE_OPAQUE_ENTRY=Deferred_Indirect_ShadowMask_Fptl_Variant23 USE_INDIRECT SHADOWS_SHADOWMASK VARIANT=23 -#pragma kernel Deferred_Indirect_ShadowMask_Fptl_Variant24 SHADE_OPAQUE_ENTRY=Deferred_Indirect_ShadowMask_Fptl_Variant24 USE_INDIRECT SHADOWS_SHADOWMASK VARIANT=24 -#pragma kernel Deferred_Indirect_ShadowMask_Fptl_Variant25 SHADE_OPAQUE_ENTRY=Deferred_Indirect_ShadowMask_Fptl_Variant25 USE_INDIRECT SHADOWS_SHADOWMASK VARIANT=25 -#pragma kernel Deferred_Indirect_ShadowMask_Fptl_Variant26 SHADE_OPAQUE_ENTRY=Deferred_Indirect_ShadowMask_Fptl_Variant26 USE_INDIRECT SHADOWS_SHADOWMASK VARIANT=26 -#pragma kernel Deferred_Indirect_ShadowMask_Fptl_Variant27 SHADE_OPAQUE_ENTRY=Deferred_Indirect_ShadowMask_Fptl_Variant27 USE_INDIRECT SHADOWS_SHADOWMASK VARIANT=27 -#pragma kernel Deferred_Indirect_ShadowMask_Fptl_Variant28 SHADE_OPAQUE_ENTRY=Deferred_Indirect_ShadowMask_Fptl_Variant28 USE_INDIRECT SHADOWS_SHADOWMASK VARIANT=28 +#pragma multi_compile _ SHADOWS_SHADOWMASK #ifdef DEBUG_DISPLAY // Don't care about this warning in debug diff --git a/com.unity.render-pipelines.high-definition/Runtime/Lighting/LightLoop/LightLoop.cs b/com.unity.render-pipelines.high-definition/Runtime/Lighting/LightLoop/LightLoop.cs index 3a7027e7afb..11429ef7be8 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/Lighting/LightLoop/LightLoop.cs +++ b/com.unity.render-pipelines.high-definition/Runtime/Lighting/LightLoop/LightLoop.cs @@ -558,7 +558,6 @@ public void Allocate() static int s_shadeOpaqueDirectShadowMaskFptlDebugDisplayKernel; static int[] s_shadeOpaqueIndirectFptlKernels = new int[LightDefinitions.s_NumFeatureVariants]; - static int[] s_shadeOpaqueIndirectShadowMaskFptlKernels = new int[LightDefinitions.s_NumFeatureVariants]; static int s_deferredContactShadowKernel; static int s_deferredContactShadowKernelMSAA; @@ -775,16 +774,12 @@ void InitializeLightLoop(IBLFilterBSDF[] iBLFilterBSDFArray) s_shadeOpaqueDirectFptlKernel = deferredComputeShader.FindKernel("Deferred_Direct_Fptl"); s_shadeOpaqueDirectFptlDebugDisplayKernel = deferredComputeShader.FindKernel("Deferred_Direct_Fptl_DebugDisplay"); - s_shadeOpaqueDirectShadowMaskFptlKernel = deferredComputeShader.FindKernel("Deferred_Direct_ShadowMask_Fptl"); - s_shadeOpaqueDirectShadowMaskFptlDebugDisplayKernel = deferredComputeShader.FindKernel("Deferred_Direct_ShadowMask_Fptl_DebugDisplay"); - s_deferredContactShadowKernel = contactShadowComputeShader.FindKernel("DeferredContactShadow"); s_deferredContactShadowKernelMSAA = contactShadowComputeShader.FindKernel("DeferredContactShadowMSAA"); for (int variant = 0; variant < LightDefinitions.s_NumFeatureVariants; variant++) { s_shadeOpaqueIndirectFptlKernels[variant] = deferredComputeShader.FindKernel("Deferred_Indirect_Fptl_Variant" + variant); - s_shadeOpaqueIndirectShadowMaskFptlKernels[variant] = deferredComputeShader.FindKernel("Deferred_Indirect_ShadowMask_Fptl_Variant" + variant); } m_TextureCaches.Initialize(asset, defaultResources, iBLFilterBSDFArray); @@ -3601,6 +3596,12 @@ static void RenderComputeDeferredLighting(in DeferredLightingParameters paramete using (new ProfilingScope(cmd, ProfilingSampler.Get(HDProfileId.RenderDeferredLightingCompute))) { cmd.SetGlobalBuffer(HDShaderIDs.g_vLightListGlobal, resources.lightListBuffer); + parameters.deferredComputeShader.shaderKeywords = null; + + if (parameters.enableShadowMasks) + { + parameters.deferredComputeShader.EnableKeyword("SHADOWS_SHADOWMASK"); + } for (int variant = 0; variant < parameters.numVariants; variant++) { @@ -3608,18 +3609,11 @@ static void RenderComputeDeferredLighting(in DeferredLightingParameters paramete if (parameters.enableFeatureVariants) { - kernel = parameters.enableShadowMasks ? s_shadeOpaqueIndirectShadowMaskFptlKernels[variant] : s_shadeOpaqueIndirectFptlKernels[variant]; + kernel = s_shadeOpaqueIndirectFptlKernels[variant]; } else { - if (parameters.enableShadowMasks) - { - kernel = parameters.debugDisplaySettings.IsDebugDisplayEnabled() ? s_shadeOpaqueDirectShadowMaskFptlDebugDisplayKernel : s_shadeOpaqueDirectShadowMaskFptlKernel; - } - else - { - kernel = parameters.debugDisplaySettings.IsDebugDisplayEnabled() ? s_shadeOpaqueDirectFptlDebugDisplayKernel : s_shadeOpaqueDirectFptlKernel; - } + kernel = parameters.debugDisplaySettings.IsDebugDisplayEnabled() ? s_shadeOpaqueDirectFptlDebugDisplayKernel : s_shadeOpaqueDirectFptlKernel; } cmd.SetComputeTextureParam(parameters.deferredComputeShader, kernel, HDShaderIDs._CameraDepthTexture, resources.depthTexture); From 8e2cdaf74983d768bf1c33ff1f3b754089e2b0e1 Mon Sep 17 00:00:00 2001 From: FrancescoC-Unity Date: Mon, 23 Mar 2020 09:54:56 +0100 Subject: [PATCH 2/8] Changelog --- com.unity.render-pipelines.high-definition/CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/com.unity.render-pipelines.high-definition/CHANGELOG.md b/com.unity.render-pipelines.high-definition/CHANGELOG.md index 90c1e490ae6..5118eb043e3 100644 --- a/com.unity.render-pipelines.high-definition/CHANGELOG.md +++ b/com.unity.render-pipelines.high-definition/CHANGELOG.md @@ -572,6 +572,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. - Renamed "Environment" to "Reflection Probes" in tile/cluster debug menu. - Utilities namespace is obsolete, moved its content to UnityEngine.Rendering (case 1204677) - Obsolete Utilities namespace was removed, instead use UnityEngine.Rendering (case 1204677) +- Use multi_compile API for deferred compute shader with shadow mask. ## [7.1.1] - 2019-09-05 From 7d3abe2057a2b6a2939f66b941576a35c965d52b Mon Sep 17 00:00:00 2001 From: FrancescoC-Unity Date: Mon, 23 Mar 2020 11:23:29 +0100 Subject: [PATCH 3/8] Have shadow quality as multi_compile --- .../Runtime/ShaderConfig.cs | 2 -- .../Runtime/ShaderConfig.cs.hlsl | 1 - .../Editor/RenderPipeline/HDRenderPipelineUI.cs | 9 +-------- .../Runtime/Lighting/LightLoop/Deferred.compute | 2 ++ .../Runtime/Lighting/LightLoop/LightLoop.cs | 16 ++++++++++++++++ .../Lighting/Shadow/HDShadowAlgorithms.hlsl | 2 +- .../Runtime/Lighting/Shadow/HDShadowManager.cs | 8 ++++---- 7 files changed, 24 insertions(+), 16 deletions(-) diff --git a/com.unity.render-pipelines.high-definition-config/Runtime/ShaderConfig.cs b/com.unity.render-pipelines.high-definition-config/Runtime/ShaderConfig.cs index ee5bcb77bd9..a92344d54e4 100644 --- a/com.unity.render-pipelines.high-definition-config/Runtime/ShaderConfig.cs +++ b/com.unity.render-pipelines.high-definition-config/Runtime/ShaderConfig.cs @@ -30,7 +30,6 @@ public enum ShaderOptions #endif AreaLights = 1, - DeferredShadowFiltering = HDShadowFilteringQuality.Medium, BarnDoor = 0 }; @@ -44,6 +43,5 @@ public class ShaderConfig public static int s_PrecomputedAtmosphericAttenuation = (int)ShaderOptions.PrecomputedAtmosphericAttenuation; public static int s_AreaLights = (int)ShaderOptions.AreaLights; public static int s_BarnDoor = (int)ShaderOptions.BarnDoor; - public static HDShadowFilteringQuality s_DeferredShadowFiltering = (HDShadowFilteringQuality)ShaderOptions.DeferredShadowFiltering; } } diff --git a/com.unity.render-pipelines.high-definition-config/Runtime/ShaderConfig.cs.hlsl b/com.unity.render-pipelines.high-definition-config/Runtime/ShaderConfig.cs.hlsl index 9779abebe19..34a5ac302ca 100644 --- a/com.unity.render-pipelines.high-definition-config/Runtime/ShaderConfig.cs.hlsl +++ b/com.unity.render-pipelines.high-definition-config/Runtime/ShaderConfig.cs.hlsl @@ -20,7 +20,6 @@ #define SHADEROPTIONS_RAYTRACING (0) #define SHADEROPTIONS_XR_MAX_VIEWS (2) #define SHADEROPTIONS_AREA_LIGHTS (1) -#define SHADEROPTIONS_DEFERRED_SHADOW_FILTERING (1) #define SHADEROPTIONS_BARN_DOOR (0) diff --git a/com.unity.render-pipelines.high-definition/Editor/RenderPipeline/HDRenderPipelineUI.cs b/com.unity.render-pipelines.high-definition/Editor/RenderPipeline/HDRenderPipelineUI.cs index ccf35595355..15068123595 100644 --- a/com.unity.render-pipelines.high-definition/Editor/RenderPipeline/HDRenderPipelineUI.cs +++ b/com.unity.render-pipelines.high-definition/Editor/RenderPipeline/HDRenderPipelineUI.cs @@ -349,14 +349,7 @@ static void Drawer_SectionShadows(SerializedHDRenderPipelineAsset serialized, Ed if (!serialized.renderPipelineSettings.supportedLitShaderMode.hasMultipleDifferentValues) { - bool isDeferredOnly = serialized.renderPipelineSettings.supportedLitShaderMode.intValue == (int)RenderPipelineSettings.SupportedLitShaderMode.DeferredOnly; - - // Deferred Only mode does not allow to change filtering quality, but rather it is hardcoded. - if (isDeferredOnly) - serialized.renderPipelineSettings.hdShadowInitParams.shadowFilteringQuality.intValue = (int)ShaderConfig.s_DeferredShadowFiltering; - - using (new EditorGUI.DisabledScope(isDeferredOnly)) - EditorGUILayout.PropertyField(serialized.renderPipelineSettings.hdShadowInitParams.shadowFilteringQuality, Styles.filteringQuality); + EditorGUILayout.PropertyField(serialized.renderPipelineSettings.hdShadowInitParams.shadowFilteringQuality, Styles.filteringQuality); } else { diff --git a/com.unity.render-pipelines.high-definition/Runtime/Lighting/LightLoop/Deferred.compute b/com.unity.render-pipelines.high-definition/Runtime/Lighting/LightLoop/Deferred.compute index 8897369216f..a93a082c6cc 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/Lighting/LightLoop/Deferred.compute +++ b/com.unity.render-pipelines.high-definition/Runtime/Lighting/LightLoop/Deferred.compute @@ -34,6 +34,8 @@ #pragma multi_compile _ SHADOWS_SHADOWMASK +#pragma multi_compile SHADOW_LOW SHADOW_MEDIUM SHADOW_HIGH + #ifdef DEBUG_DISPLAY // Don't care about this warning in debug # pragma warning( disable : 4714 ) // sum of temp registers and indexable temp registers times 256 threads exceeds the recommended total 16384. Performance may be reduced at kernel diff --git a/com.unity.render-pipelines.high-definition/Runtime/Lighting/LightLoop/LightLoop.cs b/com.unity.render-pipelines.high-definition/Runtime/Lighting/LightLoop/LightLoop.cs index 11429ef7be8..c4950b6970c 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/Lighting/LightLoop/LightLoop.cs +++ b/com.unity.render-pipelines.high-definition/Runtime/Lighting/LightLoop/LightLoop.cs @@ -3598,6 +3598,22 @@ static void RenderComputeDeferredLighting(in DeferredLightingParameters paramete cmd.SetGlobalBuffer(HDShaderIDs.g_vLightListGlobal, resources.lightListBuffer); parameters.deferredComputeShader.shaderKeywords = null; + switch(HDRenderPipeline.currentAsset.currentPlatformRenderPipelineSettings.hdShadowInitParams.shadowFilteringQuality) + { + case HDShadowFilteringQuality.Low: + parameters.deferredComputeShader.EnableKeyword("SHADOW_LOW"); + break; + case HDShadowFilteringQuality.Medium: + parameters.deferredComputeShader.EnableKeyword("SHADOW_MEDIUM"); + break; + case HDShadowFilteringQuality.High: + parameters.deferredComputeShader.EnableKeyword("SHADOW_HIGH"); + break; + default: + parameters.deferredComputeShader.EnableKeyword("SHADOW_MEDIUM"); + break; + } + if (parameters.enableShadowMasks) { parameters.deferredComputeShader.EnableKeyword("SHADOWS_SHADOWMASK"); diff --git a/com.unity.render-pipelines.high-definition/Runtime/Lighting/Shadow/HDShadowAlgorithms.hlsl b/com.unity.render-pipelines.high-definition/Runtime/Lighting/Shadow/HDShadowAlgorithms.hlsl index 1aa7a294ab4..81bd36e06ad 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/Lighting/Shadow/HDShadowAlgorithms.hlsl +++ b/com.unity.render-pipelines.high-definition/Runtime/Lighting/Shadow/HDShadowAlgorithms.hlsl @@ -10,7 +10,7 @@ #define FIXED_UNIFORM_BIAS (1.0f / 65536.0f) // We can't use multi_compile for compute shaders so we force the shadow algorithm -#if SHADERPASS == SHADERPASS_DEFERRED_LIGHTING || (defined(_ENABLE_SHADOW_MATTE) && SHADERPASS == SHADERPASS_FORWARD_UNLIT) +#if (defined(_ENABLE_SHADOW_MATTE) && SHADERPASS == SHADERPASS_FORWARD_UNLIT) #if SHADEROPTIONS_DEFERRED_SHADOW_FILTERING == HDSHADOWFILTERINGQUALITY_LOW #define SHADOW_LOW diff --git a/com.unity.render-pipelines.high-definition/Runtime/Lighting/Shadow/HDShadowManager.cs b/com.unity.render-pipelines.high-definition/Runtime/Lighting/Shadow/HDShadowManager.cs index 159ac9e7d04..7c749bc57af 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/Lighting/Shadow/HDShadowManager.cs +++ b/com.unity.render-pipelines.high-definition/Runtime/Lighting/Shadow/HDShadowManager.cs @@ -161,10 +161,10 @@ internal static HDShadowAtlasInitParams GetDefault() shadowResolutionDirectional = new IntScalableSetting(new []{ 256, 512, 1024, 2048 }, ScalableSettingSchemaId.With4Levels), shadowResolutionArea = new IntScalableSetting(new []{ 256, 512, 1024, 2048 }, ScalableSettingSchemaId.With4Levels), shadowResolutionPunctual = new IntScalableSetting(new []{ 256, 512, 1024, 2048 }, ScalableSettingSchemaId.With4Levels), - shadowFilteringQuality = ShaderConfig.s_DeferredShadowFiltering, - supportScreenSpaceShadows = false, - maxScreenSpaceShadowSlots = 4, - screenSpaceShadowBufferFormat = ScreenSpaceShadowFormat.R16G16B16A16, + shadowFilteringQuality = HDShadowFilteringQuality.Medium, + supportScreenSpaceShadows = false, + maxScreenSpaceShadowSlots = 4, + screenSpaceShadowBufferFormat = ScreenSpaceShadowFormat.R16G16B16A16, maxDirectionalShadowMapResolution = 2048, maxAreaShadowMapResolution = 2048, maxPunctualShadowMapResolution = 2048, From 0edeb839c8d7ce08d229063f5347c84f1601b11b Mon Sep 17 00:00:00 2001 From: FrancescoC-Unity Date: Mon, 23 Mar 2020 11:41:34 +0100 Subject: [PATCH 4/8] make old API obsolete --- .../Runtime/ShaderConfig.cs | 5 +++++ .../Runtime/ShaderConfig.cs.hlsl | 1 + .../Runtime/Lighting/LightLoop/LightLoop.cs | 2 +- 3 files changed, 7 insertions(+), 1 deletion(-) diff --git a/com.unity.render-pipelines.high-definition-config/Runtime/ShaderConfig.cs b/com.unity.render-pipelines.high-definition-config/Runtime/ShaderConfig.cs index a92344d54e4..4e2b669fb90 100644 --- a/com.unity.render-pipelines.high-definition-config/Runtime/ShaderConfig.cs +++ b/com.unity.render-pipelines.high-definition-config/Runtime/ShaderConfig.cs @@ -30,6 +30,9 @@ public enum ShaderOptions #endif AreaLights = 1, + [System.Obsolete("Deferred shadow can now assume any value, so this field is not used anymore.")] + DeferredShadowFiltering = HDShadowFilteringQuality.Medium, + BarnDoor = 0 }; @@ -43,5 +46,7 @@ public class ShaderConfig public static int s_PrecomputedAtmosphericAttenuation = (int)ShaderOptions.PrecomputedAtmosphericAttenuation; public static int s_AreaLights = (int)ShaderOptions.AreaLights; public static int s_BarnDoor = (int)ShaderOptions.BarnDoor; + [System.Obsolete("Deferred shadow can now assume any value, so this field is not used anymore.")] + public static HDShadowFilteringQuality s_DeferredShadowFiltering = (HDShadowFilteringQuality)ShaderOptions.DeferredShadowFiltering; } } diff --git a/com.unity.render-pipelines.high-definition-config/Runtime/ShaderConfig.cs.hlsl b/com.unity.render-pipelines.high-definition-config/Runtime/ShaderConfig.cs.hlsl index 34a5ac302ca..9779abebe19 100644 --- a/com.unity.render-pipelines.high-definition-config/Runtime/ShaderConfig.cs.hlsl +++ b/com.unity.render-pipelines.high-definition-config/Runtime/ShaderConfig.cs.hlsl @@ -20,6 +20,7 @@ #define SHADEROPTIONS_RAYTRACING (0) #define SHADEROPTIONS_XR_MAX_VIEWS (2) #define SHADEROPTIONS_AREA_LIGHTS (1) +#define SHADEROPTIONS_DEFERRED_SHADOW_FILTERING (1) #define SHADEROPTIONS_BARN_DOOR (0) diff --git a/com.unity.render-pipelines.high-definition/Runtime/Lighting/LightLoop/LightLoop.cs b/com.unity.render-pipelines.high-definition/Runtime/Lighting/LightLoop/LightLoop.cs index c4950b6970c..20ccc4df51d 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/Lighting/LightLoop/LightLoop.cs +++ b/com.unity.render-pipelines.high-definition/Runtime/Lighting/LightLoop/LightLoop.cs @@ -3598,7 +3598,7 @@ static void RenderComputeDeferredLighting(in DeferredLightingParameters paramete cmd.SetGlobalBuffer(HDShaderIDs.g_vLightListGlobal, resources.lightListBuffer); parameters.deferredComputeShader.shaderKeywords = null; - switch(HDRenderPipeline.currentAsset.currentPlatformRenderPipelineSettings.hdShadowInitParams.shadowFilteringQuality) + switch (HDRenderPipeline.currentAsset.currentPlatformRenderPipelineSettings.hdShadowInitParams.shadowFilteringQuality) { case HDShadowFilteringQuality.Low: parameters.deferredComputeShader.EnableKeyword("SHADOW_LOW"); From 1d2821816642d9bf1e1be1644c5e75c4b3893041 Mon Sep 17 00:00:00 2001 From: FrancescoC-Unity Date: Wed, 8 Apr 2020 16:15:40 +0200 Subject: [PATCH 5/8] Update comment --- .../Runtime/Lighting/Shadow/HDShadowAlgorithms.hlsl | 1 - 1 file changed, 1 deletion(-) diff --git a/com.unity.render-pipelines.high-definition/Runtime/Lighting/Shadow/HDShadowAlgorithms.hlsl b/com.unity.render-pipelines.high-definition/Runtime/Lighting/Shadow/HDShadowAlgorithms.hlsl index 81bd36e06ad..7c94fe6cb5a 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/Lighting/Shadow/HDShadowAlgorithms.hlsl +++ b/com.unity.render-pipelines.high-definition/Runtime/Lighting/Shadow/HDShadowAlgorithms.hlsl @@ -9,7 +9,6 @@ // Since we use slope-scale bias, the constant bias is for now set as a small fixed value #define FIXED_UNIFORM_BIAS (1.0f / 65536.0f) -// We can't use multi_compile for compute shaders so we force the shadow algorithm #if (defined(_ENABLE_SHADOW_MATTE) && SHADERPASS == SHADERPASS_FORWARD_UNLIT) #if SHADEROPTIONS_DEFERRED_SHADOW_FILTERING == HDSHADOWFILTERINGQUALITY_LOW From 8b18ee78347c7f30a237958faea999a78e9b337f Mon Sep 17 00:00:00 2001 From: FrancescoC-Unity Date: Wed, 8 Apr 2020 16:20:22 +0200 Subject: [PATCH 6/8] Comment on pre processor --- .../Editor/BuildProcessors/HDRPPreprocessShaders.cs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/com.unity.render-pipelines.high-definition/Editor/BuildProcessors/HDRPPreprocessShaders.cs b/com.unity.render-pipelines.high-definition/Editor/BuildProcessors/HDRPPreprocessShaders.cs index 36e27ddee43..3a5442784b1 100644 --- a/com.unity.render-pipelines.high-definition/Editor/BuildProcessors/HDRPPreprocessShaders.cs +++ b/com.unity.render-pipelines.high-definition/Editor/BuildProcessors/HDRPPreprocessShaders.cs @@ -17,6 +17,8 @@ public CommonShaderPreprocessor() { } protected override bool DoShadersStripper(HDRenderPipelineAsset hdrpAsset, Shader shader, ShaderSnippetData snippet, ShaderCompilerData inputData) { + // TODO: We need to perform compute shader stripping as soon as it is possible. Most egregious case would be the shadow filtering quality for Deferred.compute + // Strip every useless shadow configs var shadowInitParams = hdrpAsset.currentPlatformRenderPipelineSettings.hdShadowInitParams; From bf81e6d0a43b572d30e9381ec3cda0c2eacb65cd Mon Sep 17 00:00:00 2001 From: FrancescoC-Unity Date: Wed, 8 Apr 2020 16:38:04 +0200 Subject: [PATCH 7/8] Update docs --- .../Documentation~/HDRP-Config-Package.md | 7 +++---- .../Documentation~/Shadows-in-HDRP.md | 2 -- .../Documentation~/TableOfContents.md | 1 + .../Documentation~/Upgrading-from-2020.1-to-2020.2.md | 8 ++++++++ 4 files changed, 12 insertions(+), 6 deletions(-) create mode 100644 com.unity.render-pipelines.high-definition/Documentation~/Upgrading-from-2020.1-to-2020.2.md diff --git a/com.unity.render-pipelines.high-definition/Documentation~/HDRP-Config-Package.md b/com.unity.render-pipelines.high-definition/Documentation~/HDRP-Config-Package.md index 0648cf7f790..7bb0541b893 100644 --- a/com.unity.render-pipelines.high-definition/Documentation~/HDRP-Config-Package.md +++ b/com.unity.render-pipelines.high-definition/Documentation~/HDRP-Config-Package.md @@ -6,7 +6,6 @@ For example, you can use it to: * Enable [ray tracing](Ray-Tracing-Getting-Started.html). * Enable [camera-relative rendering](Camera-Relative-Rendering.html). -* Control the shadow filtering mode for deferred rendering. ## Using the HDRP Config package @@ -36,7 +35,7 @@ To ensure that the two files are synchronized, you should follow the first metho ### Example -You can use the method described above to change the shadow filtering mode for the [Lit Shader](Lit-Shader.html) in deferred mode: +You can use the method described above to disable [Camera-Relative rendering](Camera-Relative-Rendering.html): -1. In the **ShaderConfig.cs** file, set **DeferredShadowFiltering** to **HDShadowFilteringQuality.High**. -2. Generate the **ShaderConfig.cs.hlsl** file (**Edit > RenderPipeline > Generate Include Files**). Now, in the **ShaderConfig.cs.hlsl** file, the **SHADEROPTIONS_DEFERRED_SHADOW_FILTERING** define should be set to **2** (**#define SHADEROPTIONS_DEFERRED_SHADOW_FILTERING (2)**). \ No newline at end of file +1. In the **ShaderConfig.cs** file, set **CameraRelativeRendering** to **0**. +2. Generate the **ShaderConfig.cs.hlsl** file (**Edit > RenderPipeline > Generate Include Files**). Now, in the **ShaderConfig.cs.hlsl** file, the **SHADEROPTIONS_CAMERA_RELATIVE_RENDERING** define should be set to **0** \ No newline at end of file diff --git a/com.unity.render-pipelines.high-definition/Documentation~/Shadows-in-HDRP.md b/com.unity.render-pipelines.high-definition/Documentation~/Shadows-in-HDRP.md index 4ecd5cdca8b..3029cc373aa 100644 --- a/com.unity.render-pipelines.high-definition/Documentation~/Shadows-in-HDRP.md +++ b/com.unity.render-pipelines.high-definition/Documentation~/Shadows-in-HDRP.md @@ -55,8 +55,6 @@ After HDRP captures a shadow map, it processes filtering on the map in order to To change which filter HDRP uses, change the **Filtering Quality** property in your Unity Project’s [HDRP Asset](HDRP-Asset.html). There are currently four filter quality presets for directional and punctual lights. For information on the available filter qualities, see the [Filtering Qualities table](HDRP-Asset.html#FilteringQualities). -Currently, if you want to use **High** quality (PCSS) filtering in [deferred](Forward-And-Deferred-Rendering.html) mode, you need to enable it in the [HDRP Config package](HDRP-Config-Package.html). For information on how to do this, see the [Example section](HDRP-Config-Package.html#Example) of the Config package documentation. - ## Shadowmasks HDRP supports two [Mixed Lighting Modes](https://docs.unity3d.com/Manual/LightMode-Mixed.html): diff --git a/com.unity.render-pipelines.high-definition/Documentation~/TableOfContents.md b/com.unity.render-pipelines.high-definition/Documentation~/TableOfContents.md index 96ac363bab4..1891c154f3b 100644 --- a/com.unity.render-pipelines.high-definition/Documentation~/TableOfContents.md +++ b/com.unity.render-pipelines.high-definition/Documentation~/TableOfContents.md @@ -15,6 +15,7 @@ * [2019.1 to 2019.2](Upgrading-from-2019.1-to-2019.2) * [2019.2 to 2019.3](Upgrading-from-2019.2-to-2019.3) * [2019.3 to 2020.1](Upgrading-from-2019.3-to-2020.1) + * [2020.1 to 2020.2](Upgrading-from-2020.1-to-2020.2) * Volume Framework * [Volumes](Volumes) * [Volume Profiles](Volume-Profile) diff --git a/com.unity.render-pipelines.high-definition/Documentation~/Upgrading-from-2020.1-to-2020.2.md b/com.unity.render-pipelines.high-definition/Documentation~/Upgrading-from-2020.1-to-2020.2.md new file mode 100644 index 00000000000..a642921464f --- /dev/null +++ b/com.unity.render-pipelines.high-definition/Documentation~/Upgrading-from-2020.1-to-2020.2.md @@ -0,0 +1,8 @@ +# Upgrading HDRP from Unity 2020.1 to Unity 2020.2 + +In the High Definition Render Pipeline (HDRP), some features work differently between major versions of Unity. This document helps you upgrade HDRP from Unity 2020.1 to 2020.2. + +## Shadows + +From Unity 2020.2, it is not necessary to change the [HDRP Config package](HDRP-Config-Package.html) in order to set the [Shadows filtering quality](HDRP-Asset.html#FilteringQualities) for Deferred rendering. Instead the filtering quality can be simply set on the [HDRP Asset](HDRP-Asset.html#FilteringQualities) similarly to what was previously setting only the quality for Forward. + From 92ffa3780b059bc2855109ddc64cf62c7de30eda Mon Sep 17 00:00:00 2001 From: FrancescoC-Unity Date: Fri, 17 Apr 2020 18:51:57 +0200 Subject: [PATCH 8/8] Change shader versions of deferred --- .../Runtime/Lighting/Deferred.shader | 1 + .../Runtime/Lighting/LightLoop/DeferredTile.shader | 2 ++ 2 files changed, 3 insertions(+) diff --git a/com.unity.render-pipelines.high-definition/Runtime/Lighting/Deferred.shader b/com.unity.render-pipelines.high-definition/Runtime/Lighting/Deferred.shader index abe02eecc79..f8ef1337638 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/Lighting/Deferred.shader +++ b/com.unity.render-pipelines.high-definition/Runtime/Lighting/Deferred.shader @@ -38,6 +38,7 @@ Shader "Hidden/HDRP/Deferred" #pragma multi_compile _ OUTPUT_SPLIT_LIGHTING #pragma multi_compile _ SHADOWS_SHADOWMASK #pragma multi_compile _ DEBUG_DISPLAY + #pragma multi_compile SHADOW_LOW SHADOW_MEDIUM SHADOW_HIGH #define USE_FPTL_LIGHTLIST // deferred opaque always use FPTL diff --git a/com.unity.render-pipelines.high-definition/Runtime/Lighting/LightLoop/DeferredTile.shader b/com.unity.render-pipelines.high-definition/Runtime/Lighting/LightLoop/DeferredTile.shader index bc68896e4f4..e0754fde912 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/Lighting/LightLoop/DeferredTile.shader +++ b/com.unity.render-pipelines.high-definition/Runtime/Lighting/LightLoop/DeferredTile.shader @@ -39,6 +39,7 @@ Shader "Hidden/HDRP/DeferredTile" #pragma multi_compile _ OUTPUT_SPLIT_LIGHTING // Split lighting is utilized during the SSS pass. #pragma multi_compile _ SHADOWS_SHADOWMASK /// Variant with and without shadowmask #pragma multi_compile VARIANT0 VARIANT1 VARIANT2 VARIANT3 VARIANT4 VARIANT5 VARIANT6 VARIANT7 VARIANT8 VARIANT9 VARIANT10 VARIANT11 VARIANT12 VARIANT13 VARIANT14 VARIANT15 VARIANT16 VARIANT17 VARIANT18 VARIANT19 VARIANT20 VARIANT21 VARIANT22 VARIANT23 VARIANT24 VARIANT25 VARIANT26 VARIANT27 VARIANT28 + #pragma multi_compile SHADOW_LOW SHADOW_MEDIUM SHADOW_HIGH #define USE_INDIRECT // otherwise TileVariantToFeatureFlags() will not be defined in Lit.hlsl!!! @@ -301,6 +302,7 @@ Shader "Hidden/HDRP/DeferredTile" #pragma multi_compile _ OUTPUT_SPLIT_LIGHTING #pragma multi_compile _ DEBUG_DISPLAY #pragma multi_compile _ SHADOWS_SHADOWMASK /// Variant with and without shadowmask + #pragma multi_compile SHADOW_LOW SHADOW_MEDIUM SHADOW_HIGH #define USE_FPTL_LIGHTLIST 1 // deferred opaque always use FPTL