From 019e92a4a71575e5c04d82f200cb8187f03dbb7f Mon Sep 17 00:00:00 2001 From: FrancescoC-Unity Date: Tue, 27 Apr 2021 14:40:11 +0200 Subject: [PATCH 1/4] Bulk of work --- .../Editor/Material/BaseShaderPreprocessor.cs | 3 ++ .../PlanarPrimitive/PassForward.template | 2 +- .../Runtime/Lighting/Deferred.shader | 2 +- .../Lighting/LightLoop/Deferred.compute | 2 +- .../Lighting/LightLoop/DeferredTile.shader | 4 +- .../Runtime/Lighting/LightLoop/LightLoop.cs | 2 +- .../Lighting/Shadow/HDShadowAlgorithms.hlsl | 45 ++++++++++++------- .../Lighting/Shadow/HDShadowManager.cs | 4 ++ .../Lighting/Shadow/ScreenSpaceShadows.shader | 2 +- .../Runtime/Material/AxF/AxF.shader | 2 +- .../Material/LayeredLit/LayeredLit.shader | 2 +- .../LayeredLit/LayeredLitTessellation.shader | 2 +- .../Runtime/Material/Lit/Lit.shader | 4 +- .../Material/Lit/LitTessellation.shader | 4 +- .../Material/TerrainLit/TerrainLit.shader | 2 +- .../TerrainLit/TerrainLit_Basemap.shader | 2 +- .../Runtime/Sky/HDRISky/HDRISky.shader | 2 +- 17 files changed, 52 insertions(+), 34 deletions(-) diff --git a/com.unity.render-pipelines.high-definition/Editor/Material/BaseShaderPreprocessor.cs b/com.unity.render-pipelines.high-definition/Editor/Material/BaseShaderPreprocessor.cs index 25bcad959fa..44618e7cc28 100644 --- a/com.unity.render-pipelines.high-definition/Editor/Material/BaseShaderPreprocessor.cs +++ b/com.unity.render-pipelines.high-definition/Editor/Material/BaseShaderPreprocessor.cs @@ -12,6 +12,7 @@ internal class ShadowKeywords ShaderKeyword ShadowLow; ShaderKeyword ShadowMedium; ShaderKeyword ShadowHigh; + ShaderKeyword ShadowVeryHigh; public Dictionary ShadowVariants; @@ -20,12 +21,14 @@ public ShadowKeywords() ShadowLow = new ShaderKeyword("SHADOW_LOW"); ShadowMedium = new ShaderKeyword("SHADOW_MEDIUM"); ShadowHigh = new ShaderKeyword("SHADOW_HIGH"); + ShadowVeryHigh = new ShaderKeyword("SHADOW_VERY_HIGH"); ShadowVariants = new Dictionary { {HDShadowFilteringQuality.Low, ShadowLow}, {HDShadowFilteringQuality.Medium, ShadowMedium}, {HDShadowFilteringQuality.High, ShadowHigh}, + {HDShadowFilteringQuality.VeryHigh, ShadowVeryHigh}, }; } } diff --git a/com.unity.render-pipelines.high-definition/Editor/VFXGraph/Shaders/Templates/PlanarPrimitive/PassForward.template b/com.unity.render-pipelines.high-definition/Editor/VFXGraph/Shaders/Templates/PlanarPrimitive/PassForward.template index 730ee37ace4..f298c97ff96 100644 --- a/com.unity.render-pipelines.high-definition/Editor/VFXGraph/Shaders/Templates/PlanarPrimitive/PassForward.template +++ b/com.unity.render-pipelines.high-definition/Editor/VFXGraph/Shaders/Templates/PlanarPrimitive/PassForward.template @@ -10,7 +10,7 @@ Pass #define LIGHTLOOP_TILE_PASS ${VFXHDRPForwardDefines} #pragma multi_compile USE_FPTL_LIGHTLIST USE_CLUSTERED_LIGHTLIST - #pragma multi_compile SHADOW_LOW SHADOW_MEDIUM SHADOW_HIGH + #pragma multi_compile_fragment SHADOW_LOW SHADOW_MEDIUM SHADOW_HIGH SHADOW_VERY_HIGH #pragma multi_compile _ DEBUG_DISPLAY //#pragma enable_d3d11_debug_symbols 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 a1fe387488d..4cf2248eaf3 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/Lighting/Deferred.shader +++ b/com.unity.render-pipelines.high-definition/Runtime/Lighting/Deferred.shader @@ -40,7 +40,7 @@ Shader "Hidden/HDRP/Deferred" #pragma multi_compile_fragment PROBE_VOLUMES_OFF PROBE_VOLUMES_L1 PROBE_VOLUMES_L2 #pragma multi_compile_fragment SCREEN_SPACE_SHADOWS_OFF SCREEN_SPACE_SHADOWS_ON #pragma multi_compile_fragment _ DEBUG_DISPLAY - #pragma multi_compile_fragment SHADOW_LOW SHADOW_MEDIUM SHADOW_HIGH + #pragma multi_compile_fragment SHADOW_LOW SHADOW_MEDIUM SHADOW_HIGH SHADOW_VERY_HIGH #define USE_FPTL_LIGHTLIST // deferred opaque always use FPTL 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 53ea2a577de..86d727fc389 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 @@ -35,7 +35,7 @@ #pragma multi_compile _ SHADOWS_SHADOWMASK #pragma multi_compile SCREEN_SPACE_SHADOWS_OFF SCREEN_SPACE_SHADOWS_ON #pragma multi_compile PROBE_VOLUMES_OFF PROBE_VOLUMES_L1 PROBE_VOLUMES_L2 -#pragma multi_compile SHADOW_LOW SHADOW_MEDIUM SHADOW_HIGH +#pragma multi_compile SHADOW_LOW SHADOW_MEDIUM SHADOW_HIGH SHADOW_VERY_HIGH #ifdef DEBUG_DISPLAY // Don't care about this warning in debug 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 2a618ebf07f..2d76c2f15f9 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,7 +39,7 @@ Shader "Hidden/HDRP/DeferredTile" #pragma multi_compile_fragment _ OUTPUT_SPLIT_LIGHTING // Split lighting is utilized during the SSS pass. #pragma multi_compile_fragment _ SHADOWS_SHADOWMASK /// Variant with and without shadowmask #pragma multi_compile_local_fragment 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_fragment SHADOW_LOW SHADOW_MEDIUM SHADOW_HIGH + #pragma multi_compile_fragment SHADOW_LOW SHADOW_MEDIUM SHADOW_HIGH SHADOW_VERY_HIGH #define USE_INDIRECT // otherwise TileVariantToFeatureFlags() will not be defined in Lit.hlsl!!! @@ -311,7 +311,7 @@ Shader "Hidden/HDRP/DeferredTile" #pragma multi_compile_fragment _ SHADOWS_SHADOWMASK /// Variant with and without shadowmask #pragma multi_compile_fragment PROBE_VOLUMES_OFF PROBE_VOLUMES_L1 PROBE_VOLUMES_L2 #pragma multi_compile_fragment SCREEN_SPACE_SHADOWS_OFF SCREEN_SPACE_SHADOWS_ON - #pragma multi_compile_fragment SHADOW_LOW SHADOW_MEDIUM SHADOW_HIGH + #pragma multi_compile_fragment SHADOW_LOW SHADOW_MEDIUM SHADOW_HIGH SHADOW_VERY_HIGH #define USE_FPTL_LIGHTLIST 1 // deferred opaque always use FPTL 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 c6419650b8e..c2f77c4e492 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 @@ -855,7 +855,7 @@ void InitializeLightLoop(IBLFilterBSDF[] iBLFilterBSDFArray) // Setup shadow algorithms var shadowParams = asset.currentPlatformRenderPipelineSettings.hdShadowInitParams; - var shadowKeywords = new[] {"SHADOW_LOW", "SHADOW_MEDIUM", "SHADOW_HIGH"}; + var shadowKeywords = new[] {"SHADOW_LOW", "SHADOW_MEDIUM", "SHADOW_HIGH", "SHADOW_VERY_HIGH"}; foreach (var p in shadowKeywords) Shader.DisableKeyword(p); Shader.EnableKeyword(shadowKeywords[(int)shadowParams.shadowFilteringQuality]); 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 f40cb0eb12e..d7e0f7d9e98 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 @@ -7,7 +7,7 @@ // For non-fragment shaders we might skip the variant with the quality as shadows might not be used, if that's the case define something just to make the compiler happy in case the quality is not defined. #ifndef SHADER_STAGE_FRAGMENT - #if !defined(SHADOW_ULTRA_LOW) && !defined(SHADOW_LOW) && !defined(SHADOW_MEDIUM) && !defined(SHADOW_HIGH) + #if !defined(SHADOW_ULTRA_LOW) && !defined(SHADOW_LOW) && !defined(SHADOW_MEDIUM) && !defined(SHADOW_HIGH) && !defined(SHADOW_VERY_HIGH) #define SHADOW_MEDIUM #endif #endif @@ -18,18 +18,28 @@ #ifdef SHADOW_ULTRA_LOW #define PUNCTUAL_FILTER_ALGORITHM(sd, posSS, posTC, tex, samp, bias) SampleShadow_PCF_Tent_3x3(sd.isInCachedAtlas ? _CachedShadowAtlasSize.zwxy : _ShadowAtlasSize.zwxy, posTC, tex, samp, bias) #define DIRECTIONAL_FILTER_ALGORITHM(sd, posSS, posTC, tex, samp, bias) SampleShadow_Gather_PCF(_CascadeShadowAtlasSize.zwxy, posTC, tex, samp, bias) +#define AREA_FILTER_ALGORITHM(sd, posSS, posTC, tex, samp, bias) SampleShadow_EVSM_1tap(posTC, sd.shadowFilterParams0.y, sd.shadowFilterParams0.z, sd.shadowFilterParams0.xx, false, tex, s_linear_clamp_sampler) #elif defined(SHADOW_LOW) #define PUNCTUAL_FILTER_ALGORITHM(sd, posSS, posTC, tex, samp, bias) SampleShadow_PCF_Tent_3x3(sd.isInCachedAtlas ? _CachedShadowAtlasSize.zwxy : _ShadowAtlasSize.zwxy, posTC, tex, samp, bias) #define DIRECTIONAL_FILTER_ALGORITHM(sd, posSS, posTC, tex, samp, bias) SampleShadow_PCF_Tent_5x5(_CascadeShadowAtlasSize.zwxy, posTC, tex, samp, bias) +#define AREA_FILTER_ALGORITHM(sd, posSS, posTC, tex, samp, bias) SampleShadow_EVSM_1tap(posTC, sd.shadowFilterParams0.y, sd.shadowFilterParams0.z, sd.shadowFilterParams0.xx, false, tex, s_linear_clamp_sampler) #elif defined(SHADOW_MEDIUM) #define PUNCTUAL_FILTER_ALGORITHM(sd, posSS, posTC, tex, samp, bias) SampleShadow_PCF_Tent_5x5(sd.isInCachedAtlas ? _CachedShadowAtlasSize.zwxy : _ShadowAtlasSize.zwxy, posTC, tex, samp, bias) #define DIRECTIONAL_FILTER_ALGORITHM(sd, posSS, posTC, tex, samp, bias) SampleShadow_PCF_Tent_7x7(_CascadeShadowAtlasSize.zwxy, posTC, tex, samp, bias) +#define AREA_FILTER_ALGORITHM(sd, posSS, posTC, tex, samp, bias) SampleShadow_EVSM_1tap(posTC, sd.shadowFilterParams0.y, sd.shadowFilterParams0.z, sd.shadowFilterParams0.xx, false, tex, s_linear_clamp_sampler) // Note: currently quality settings for PCSS need to be expose in UI and is control in HDLightUI.cs file IsShadowSettings #elif defined(SHADOW_HIGH) #define PUNCTUAL_FILTER_ALGORITHM(sd, posSS, posTC, tex, samp, bias) SampleShadow_PCSS(posTC, posSS, sd.shadowMapSize.xy * (sd.isInCachedAtlas ? _CachedShadowAtlasSize.zw : _ShadowAtlasSize.zw), sd.atlasOffset, sd.shadowFilterParams0.x, sd.shadowFilterParams0.w, asint(sd.shadowFilterParams0.y), asint(sd.shadowFilterParams0.z), tex, samp, s_point_clamp_sampler, bias, sd.zBufferParam, true, (sd.isInCachedAtlas ? _CachedShadowAtlasSize.xz : _ShadowAtlasSize.xz)) #define DIRECTIONAL_FILTER_ALGORITHM(sd, posSS, posTC, tex, samp, bias) SampleShadow_PCSS(posTC, posSS, sd.shadowMapSize.xy * _CascadeShadowAtlasSize.zw, sd.atlasOffset, sd.shadowFilterParams0.x, sd.shadowFilterParams0.w, asint(sd.shadowFilterParams0.y), asint(sd.shadowFilterParams0.z), tex, samp, s_point_clamp_sampler, bias, sd.zBufferParam, false, _CascadeShadowAtlasSize.xz) +#define AREA_FILTER_ALGORITHM(sd, posSS, posTC, tex, samp, bias) SampleShadow_EVSM_1tap(posTC, sd.shadowFilterParams0.y, sd.shadowFilterParams0.z, sd.shadowFilterParams0.xx, false, tex, s_linear_clamp_sampler) +#elif defined(SHADOW_VERY_HIGH) +#define PUNCTUAL_FILTER_ALGORITHM(sd, posSS, posTC, tex, samp, bias) SampleShadow_PCSS(posTC, posSS, sd.shadowMapSize.xy * (sd.isInCachedAtlas ? _CachedShadowAtlasSize.zw : _ShadowAtlasSize.zw), sd.atlasOffset, sd.shadowFilterParams0.x, sd.shadowFilterParams0.w, asint(sd.shadowFilterParams0.y), asint(sd.shadowFilterParams0.z), tex, samp, s_point_clamp_sampler, bias, sd.zBufferParam, true, (sd.isInCachedAtlas ? _CachedShadowAtlasSize.xz : _ShadowAtlasSize.xz)) +#define DIRECTIONAL_FILTER_ALGORITHM(sd, posSS, posTC, tex, samp, bias) SampleShadow_PCSS(posTC, posSS, sd.shadowMapSize.xy * _CascadeShadowAtlasSize.zw, sd.atlasOffset, sd.shadowFilterParams0.x, sd.shadowFilterParams0.w, asint(sd.shadowFilterParams0.y), asint(sd.shadowFilterParams0.z), tex, samp, s_point_clamp_sampler, bias, sd.zBufferParam, false, _CascadeShadowAtlasSize.xz) +#define AREA_FILTER_ALGORITHM(sd, posSS, posTC, tex, samp, bias) SampleShadow_EVSM_1tap(posTC, sd.shadowFilterParams0.y, sd.shadowFilterParams0.z, sd.shadowFilterParams0.xx, false, tex, s_linear_clamp_sampler) #endif +#define AREA_LIGHT_SHADOW_IS_EVSM 1 // TODO: Change when adding PCSS for VERY_HIGH in area light + #ifndef PUNCTUAL_FILTER_ALGORITHM #error "Undefined punctual shadow filter algorithm" #endif @@ -156,26 +166,27 @@ float EvalShadow_AreaDepth(HDShadowData sd, Texture2D tex, float2 positionSS, fl { float2 texelSize = sd.isInCachedAtlas ? _CachedAreaShadowAtlasSize.zw : _AreaShadowAtlasSize.zw; + float3 posTC; + float bias = 0; + + float2 maxCoord = (sd.shadowMapSize.xy - 0.5f) * texelSize + sd.atlasOffset; + float2 minCoord = sd.atlasOffset; + +#if AREA_LIGHT_SHADOW_IS_EVSM + positionWS = positionWS + sd.cacheTranslationDelta.xyz; /* get shadowmap texcoords */ - float3 posTC = EvalShadow_GetTexcoordsAtlas(sd, texelSize, positionWS, perspective); + posTC = EvalShadow_GetTexcoordsAtlas(sd, texelSize, positionWS, perspective); - int blurPassesScale = (1 + min(4, sd.shadowFilterParams0.w) * 4.0f);// This is needed as blurring might cause some leaks. It might be overclipping, but empirically is a good value. - float2 maxCoord = (sd.shadowMapSize.xy - 0.5f * blurPassesScale) * texelSize + sd.atlasOffset; - float2 minCoord = sd.atlasOffset + texelSize * blurPassesScale; - - if (any(posTC.xy > maxCoord || posTC.xy < minCoord)) - { - return 1.0f; - } - else - { - float2 exponents = sd.shadowFilterParams0.xx; - float lightLeakBias = sd.shadowFilterParams0.y; - float varianceBias = sd.shadowFilterParams0.z; - return SampleShadow_EVSM_1tap(posTC, lightLeakBias, varianceBias, exponents, false, tex, s_linear_clamp_sampler); - } + int blurPassesScale = (min(4, sd.shadowFilterParams0.w) * 4.0f);// This is needed as blurring might cause some leaks. It might be overclipping, but empirically is a good value. + maxCoord -= 0.5f * blurPassesScale * texelSize; + minCoord += texelSize * blurPassesScale; +#else + // TODO + return 1.0f; +#endif + return any(posTC.xy > maxCoord || posTC.xy < minCoord) ? 1.0f : AREA_FILTER_ALGORITHM(sd, positionSS, posTC, tex, s_linear_clamp_compare_sampler, FIXED_UNIFORM_BIAS); } 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 72569f623f7..8516d78d2e5 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 @@ -23,6 +23,10 @@ public enum HDShadowFilteringQuality /// High Shadow Filtering Quality /// High = 2, + /// + /// Very High Shadow Filtering Quality + /// + VeryHigh = 3, } enum ShadowMapType diff --git a/com.unity.render-pipelines.high-definition/Runtime/Lighting/Shadow/ScreenSpaceShadows.shader b/com.unity.render-pipelines.high-definition/Runtime/Lighting/Shadow/ScreenSpaceShadows.shader index 41ea26c4454..c415fd75a8a 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/Lighting/Shadow/ScreenSpaceShadows.shader +++ b/com.unity.render-pipelines.high-definition/Runtime/Lighting/Shadow/ScreenSpaceShadows.shader @@ -5,7 +5,7 @@ Shader "Hidden/HDRP/ScreenSpaceShadows" #pragma target 4.5 #pragma only_renderers d3d11 playstation xboxone xboxseries vulkan metal switch - #pragma multi_compile_fragment SHADOW_LOW SHADOW_MEDIUM SHADOW_HIGH + #pragma multi_compile_fragment SHADOW_LOW SHADOW_MEDIUM SHADOW_HIGH SHADOW_VERY_HIGH #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Common.hlsl" #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/CommonLighting.hlsl" diff --git a/com.unity.render-pipelines.high-definition/Runtime/Material/AxF/AxF.shader b/com.unity.render-pipelines.high-definition/Runtime/Material/AxF/AxF.shader index bc81449b2fe..8eb44e13c81 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/Material/AxF/AxF.shader +++ b/com.unity.render-pipelines.high-definition/Runtime/Material/AxF/AxF.shader @@ -499,7 +499,7 @@ Shader "HDRP/AxF" #pragma multi_compile_fragment DECALS_OFF DECALS_3RT DECALS_4RT // Supported shadow modes per light type - #pragma multi_compile_fragment SHADOW_LOW SHADOW_MEDIUM SHADOW_HIGH + #pragma multi_compile_fragment SHADOW_LOW SHADOW_MEDIUM SHADOW_HIGH SHADOW_VERY_HIGH #pragma multi_compile_fragment USE_FPTL_LIGHTLIST USE_CLUSTERED_LIGHTLIST diff --git a/com.unity.render-pipelines.high-definition/Runtime/Material/LayeredLit/LayeredLit.shader b/com.unity.render-pipelines.high-definition/Runtime/Material/LayeredLit/LayeredLit.shader index 670f21c8149..3298ea920c9 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/Material/LayeredLit/LayeredLit.shader +++ b/com.unity.render-pipelines.high-definition/Runtime/Material/LayeredLit/LayeredLit.shader @@ -934,7 +934,7 @@ Shader "HDRP/LayeredLit" #pragma multi_compile_fragment DECALS_OFF DECALS_3RT DECALS_4RT // Supported shadow modes per light type - #pragma multi_compile_fragment SHADOW_LOW SHADOW_MEDIUM SHADOW_HIGH + #pragma multi_compile_fragment SHADOW_LOW SHADOW_MEDIUM SHADOW_HIGH SHADOW_VERY_HIGH #pragma multi_compile_fragment USE_FPTL_LIGHTLIST USE_CLUSTERED_LIGHTLIST diff --git a/com.unity.render-pipelines.high-definition/Runtime/Material/LayeredLit/LayeredLitTessellation.shader b/com.unity.render-pipelines.high-definition/Runtime/Material/LayeredLit/LayeredLitTessellation.shader index c6bdb30ec45..dbb209bec74 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/Material/LayeredLit/LayeredLitTessellation.shader +++ b/com.unity.render-pipelines.high-definition/Runtime/Material/LayeredLit/LayeredLitTessellation.shader @@ -913,7 +913,7 @@ Shader "HDRP/LayeredLitTessellation" #pragma multi_compile_fragment DECALS_OFF DECALS_3RT DECALS_4RT // Supported shadow modes per light type - #pragma multi_compile_fragment SHADOW_LOW SHADOW_MEDIUM SHADOW_HIGH + #pragma multi_compile_fragment SHADOW_LOW SHADOW_MEDIUM SHADOW_HIGH SHADOW_VERY_HIGH #pragma multi_compile_fragment USE_FPTL_LIGHTLIST USE_CLUSTERED_LIGHTLIST diff --git a/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/Lit.shader b/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/Lit.shader index c8d500e84e6..373355e19aa 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/Lit.shader +++ b/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/Lit.shader @@ -774,7 +774,7 @@ Shader "HDRP/Lit" #pragma multi_compile_fragment DECALS_OFF DECALS_3RT DECALS_4RT // Supported shadow modes per light type - #pragma multi_compile_fragment SHADOW_LOW SHADOW_MEDIUM SHADOW_HIGH + #pragma multi_compile_fragment SHADOW_LOW SHADOW_MEDIUM SHADOW_HIGH SHADOW_VERY_HIGH #ifndef SHADER_STAGE_FRAGMENT #define SHADOW_LOW @@ -854,7 +854,7 @@ Shader "HDRP/Lit" #pragma multi_compile_fragment DECALS_OFF DECALS_3RT DECALS_4RT // Supported shadow modes per light type - #pragma multi_compile_fragment SHADOW_LOW SHADOW_MEDIUM SHADOW_HIGH + #pragma multi_compile_fragment SHADOW_LOW SHADOW_MEDIUM SHADOW_HIGH SHADOW_VERY_HIGH #pragma multi_compile_fragment USE_FPTL_LIGHTLIST USE_CLUSTERED_LIGHTLIST diff --git a/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/LitTessellation.shader b/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/LitTessellation.shader index d72c2c28d6b..4c389896a49 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/LitTessellation.shader +++ b/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/LitTessellation.shader @@ -714,7 +714,7 @@ Shader "HDRP/LitTessellation" #pragma multi_compile_fragment DECALS_OFF DECALS_3RT DECALS_4RT // Supported shadow modes per light type - #pragma multi_compile_fragment SHADOW_LOW SHADOW_MEDIUM SHADOW_HIGH + #pragma multi_compile_fragment SHADOW_LOW SHADOW_MEDIUM SHADOW_HIGH SHADOW_VERY_HIGH #ifndef SHADER_STAGE_FRAGMENT #define SHADOW_LOW @@ -787,7 +787,7 @@ Shader "HDRP/LitTessellation" #pragma multi_compile_fragment DECALS_OFF DECALS_3RT DECALS_4RT // Supported shadow modes per light type - #pragma multi_compile_fragment SHADOW_LOW SHADOW_MEDIUM SHADOW_HIGH + #pragma multi_compile_fragment SHADOW_LOW SHADOW_MEDIUM SHADOW_HIGH SHADOW_VERY_HIGH #pragma multi_compile_fragment USE_FPTL_LIGHTLIST USE_CLUSTERED_LIGHTLIST diff --git a/com.unity.render-pipelines.high-definition/Runtime/Material/TerrainLit/TerrainLit.shader b/com.unity.render-pipelines.high-definition/Runtime/Material/TerrainLit/TerrainLit.shader index 6c1bdc923f2..d8051955c36 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/Material/TerrainLit/TerrainLit.shader +++ b/com.unity.render-pipelines.high-definition/Runtime/Material/TerrainLit/TerrainLit.shader @@ -261,7 +261,7 @@ Shader "HDRP/TerrainLit" #pragma multi_compile_fragment DECALS_OFF DECALS_3RT DECALS_4RT // Supported shadow modes per light type - #pragma multi_compile_fragment SHADOW_LOW SHADOW_MEDIUM SHADOW_HIGH + #pragma multi_compile_fragment SHADOW_LOW SHADOW_MEDIUM SHADOW_HIGH SHADOW_VERY_HIGH #pragma multi_compile USE_FPTL_LIGHTLIST USE_CLUSTERED_LIGHTLIST diff --git a/com.unity.render-pipelines.high-definition/Runtime/Material/TerrainLit/TerrainLit_Basemap.shader b/com.unity.render-pipelines.high-definition/Runtime/Material/TerrainLit/TerrainLit_Basemap.shader index 5c7b933346c..1cecab35f55 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/Material/TerrainLit/TerrainLit_Basemap.shader +++ b/com.unity.render-pipelines.high-definition/Runtime/Material/TerrainLit/TerrainLit_Basemap.shader @@ -209,7 +209,7 @@ Shader "Hidden/HDRP/TerrainLit_Basemap" #pragma multi_compile_fragment DECALS_OFF DECALS_3RT DECALS_4RT // Supported shadow modes per light type - #pragma multi_compile_fragment SHADOW_LOW SHADOW_MEDIUM SHADOW_HIGH + #pragma multi_compile_fragment SHADOW_LOW SHADOW_MEDIUM SHADOW_HIGH SHADOW_VERY_HIGH #pragma multi_compile USE_FPTL_LIGHTLIST USE_CLUSTERED_LIGHTLIST diff --git a/com.unity.render-pipelines.high-definition/Runtime/Sky/HDRISky/HDRISky.shader b/com.unity.render-pipelines.high-definition/Runtime/Sky/HDRISky/HDRISky.shader index 431cecbef58..0768292fdcb 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/Sky/HDRISky/HDRISky.shader +++ b/com.unity.render-pipelines.high-definition/Runtime/Sky/HDRISky/HDRISky.shader @@ -14,7 +14,7 @@ Shader "Hidden/HDRP/Sky/HDRISky" #pragma multi_compile_local_fragment _ USE_FLOWMAP #pragma multi_compile_fragment _ DEBUG_DISPLAY - #pragma multi_compile_local_fragment SHADOW_LOW SHADOW_MEDIUM SHADOW_HIGH + #pragma multi_compile_local_fragment SHADOW_LOW SHADOW_MEDIUM SHADOW_HIGH SHADOW_VERY_HIGH #pragma multi_compile USE_FPTL_LIGHTLIST USE_CLUSTERED_LIGHTLIST From ab4e108f92974339632969c6a0f02335b663cf53 Mon Sep 17 00:00:00 2001 From: FrancescoC-Unity Date: Tue, 27 Apr 2021 18:05:27 +0200 Subject: [PATCH 2/4] Fixes --- .../Runtime/Lighting/Shadow/HDShadowAlgorithms.hlsl | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) 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 d7e0f7d9e98..9b10e9506fd 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 @@ -167,21 +167,17 @@ float EvalShadow_AreaDepth(HDShadowData sd, Texture2D tex, float2 positionSS, fl float2 texelSize = sd.isInCachedAtlas ? _CachedAreaShadowAtlasSize.zw : _AreaShadowAtlasSize.zw; float3 posTC; - float bias = 0; float2 maxCoord = (sd.shadowMapSize.xy - 0.5f) * texelSize + sd.atlasOffset; float2 minCoord = sd.atlasOffset; #if AREA_LIGHT_SHADOW_IS_EVSM - positionWS = positionWS + sd.cacheTranslationDelta.xyz; - /* get shadowmap texcoords */ posTC = EvalShadow_GetTexcoordsAtlas(sd, texelSize, positionWS, perspective); - int blurPassesScale = (min(4, sd.shadowFilterParams0.w) * 4.0f);// This is needed as blurring might cause some leaks. It might be overclipping, but empirically is a good value. maxCoord -= 0.5f * blurPassesScale * texelSize; - minCoord += texelSize * blurPassesScale; + minCoord += texelSize * (1 + blurPassesScale); #else // TODO return 1.0f; From 440a6cb0423a9948e4101479edee774ff958d752 Mon Sep 17 00:00:00 2001 From: FrancescoC-Unity Date: Tue, 27 Apr 2021 19:37:56 +0200 Subject: [PATCH 3/4] Add funciton for min/max coords --- .../Lighting/Shadow/HDShadowAlgorithms.hlsl | 32 +++++++++++-------- 1 file changed, 18 insertions(+), 14 deletions(-) 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 9b10e9506fd..9558b094323 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 @@ -162,26 +162,30 @@ float EvalShadow_PunctualDepth(HDShadowData sd, Texture2D tex, SamplerComparison // // Area light shadows // + +void EvalShadow_Area_GetMinMaxCoords(HDShadowData sd, float2 texelSize, out float2 minCoord, out float2 maxCoord) +{ +#if AREA_LIGHT_SHADOW_IS_EVSM + int blurPassesScale = (1 + min(4, sd.shadowFilterParams0.w) * 4.0f); // This is needed as blurring might cause some leaks. It might be overclipping, but empirically is a good value. + maxCoord = (sd.shadowMapSize.xy - 0.5f * blurPassesScale) * texelSize + sd.atlasOffset; + minCoord = sd.atlasOffset + texelSize * blurPassesScale; +#else + maxCoord = (sd.shadowMapSize.xy - 0.5f) * texelSize + sd.atlasOffset; + minCoord = sd.atlasOffset; +#endif +} + float EvalShadow_AreaDepth(HDShadowData sd, Texture2D tex, float2 positionSS, float3 positionWS, float3 normalWS, float3 L, float L_dist, bool perspective) { float2 texelSize = sd.isInCachedAtlas ? _CachedAreaShadowAtlasSize.zw : _AreaShadowAtlasSize.zw; - float3 posTC; - - float2 maxCoord = (sd.shadowMapSize.xy - 0.5f) * texelSize + sd.atlasOffset; - float2 minCoord = sd.atlasOffset; - -#if AREA_LIGHT_SHADOW_IS_EVSM positionWS = positionWS + sd.cacheTranslationDelta.xyz; + float3 posTC = EvalShadow_GetTexcoordsAtlas(sd, texelSize, positionWS, perspective); + + float2 maxCoord; + float2 minCoord; + EvalShadow_Area_GetMinMaxCoords(sd, texelSize, minCoord, maxCoord); - posTC = EvalShadow_GetTexcoordsAtlas(sd, texelSize, positionWS, perspective); - int blurPassesScale = (min(4, sd.shadowFilterParams0.w) * 4.0f);// This is needed as blurring might cause some leaks. It might be overclipping, but empirically is a good value. - maxCoord -= 0.5f * blurPassesScale * texelSize; - minCoord += texelSize * (1 + blurPassesScale); -#else - // TODO - return 1.0f; -#endif return any(posTC.xy > maxCoord || posTC.xy < minCoord) ? 1.0f : AREA_FILTER_ALGORITHM(sd, positionSS, posTC, tex, s_linear_clamp_compare_sampler, FIXED_UNIFORM_BIAS); } From abf8e8a592dc3d43d05fcc387b8d7829016b3aaf Mon Sep 17 00:00:00 2001 From: FrancescoC-Unity Date: Tue, 27 Apr 2021 19:44:26 +0200 Subject: [PATCH 4/4] Fixup --- .../Shaders/Templates/PlanarPrimitive/PassForward.template | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/com.unity.render-pipelines.high-definition/Editor/VFXGraph/Shaders/Templates/PlanarPrimitive/PassForward.template b/com.unity.render-pipelines.high-definition/Editor/VFXGraph/Shaders/Templates/PlanarPrimitive/PassForward.template index f298c97ff96..ddb73c674a2 100644 --- a/com.unity.render-pipelines.high-definition/Editor/VFXGraph/Shaders/Templates/PlanarPrimitive/PassForward.template +++ b/com.unity.render-pipelines.high-definition/Editor/VFXGraph/Shaders/Templates/PlanarPrimitive/PassForward.template @@ -10,7 +10,7 @@ Pass #define LIGHTLOOP_TILE_PASS ${VFXHDRPForwardDefines} #pragma multi_compile USE_FPTL_LIGHTLIST USE_CLUSTERED_LIGHTLIST - #pragma multi_compile_fragment SHADOW_LOW SHADOW_MEDIUM SHADOW_HIGH SHADOW_VERY_HIGH + #pragma multi_compile SHADOW_LOW SHADOW_MEDIUM SHADOW_HIGH SHADOW_VERY_HIGH #pragma multi_compile _ DEBUG_DISPLAY //#pragma enable_d3d11_debug_symbols