Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ internal class ShadowKeywords
ShaderKeyword ShadowLow;
ShaderKeyword ShadowMedium;
ShaderKeyword ShadowHigh;
ShaderKeyword ShadowVeryHigh;

public Dictionary<HDShadowFilteringQuality, ShaderKeyword> ShadowVariants;

Expand All @@ -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, ShaderKeyword>
{
{HDShadowFilteringQuality.Low, ShadowLow},
{HDShadowFilteringQuality.Medium, ShadowMedium},
{HDShadowFilteringQuality.High, ShadowHigh},
{HDShadowFilteringQuality.VeryHigh, ShadowVeryHigh},
};
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 SHADOW_LOW SHADOW_MEDIUM SHADOW_HIGH SHADOW_VERY_HIGH
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure why it looks differently indented here, can't see to get this to change locally with fork :/

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe running the formatting tool can work?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did try but did not work :-(

#pragma multi_compile _ DEBUG_DISPLAY
//#pragma enable_d3d11_debug_symbols

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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!!!

Expand Down Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -152,30 +162,31 @@ 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;

positionWS = positionWS + sd.cacheTranslationDelta.xyz;

/* get shadowmap texcoords */
float3 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;
float2 maxCoord;
float2 minCoord;
EvalShadow_Area_GetMinMaxCoords(sd, texelSize, minCoord, maxCoord);

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);
}
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);
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ public enum HDShadowFilteringQuality
/// High Shadow Filtering Quality
/// </summary>
High = 2,
/// <summary>
/// Very High Shadow Filtering Quality
/// </summary>
VeryHigh = 3,
}

enum ShadowMapType
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down