Skip to content

Commit

Permalink
Add an option to disable shadow bias
Browse files Browse the repository at this point in the history
  • Loading branch information
EvgeniiG committed May 14, 2020
1 parent c6aa4cf commit 2dfeab2
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 8 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
// Configure which shadow algorithms to use per shadow level quality

#ifndef SHADOW_USE_NORMAL_BIAS
#define SHADOW_USE_NORMAL_BIAS 1 // Externally define as 0 to disable
#endif

// 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)

Expand Down Expand Up @@ -123,10 +127,12 @@ float3 EvalShadow_NormalBias(float worldTexelSize, float normalBias, float3 norm
float EvalShadow_PunctualDepth(HDShadowData sd, Texture2D tex, SamplerComparisonState samp, float2 positionSS, float3 positionWS, float3 normalWS, float3 L, float L_dist, bool perspective)
{
positionWS = positionWS + sd.cacheTranslationDelta.xyz;
#if SHADOW_USE_NORMAL_BIAS
/* bias the world position */
float worldTexelSize = EvalShadow_WorldTexelSize(sd.worldTexelSize, L_dist, true);
float3 normalBias = EvalShadow_NormalBias(worldTexelSize, sd.normalBias, normalWS);
positionWS += normalBias;
#endif
/* get shadowmap texcoords */
float3 posTC = EvalShadow_GetTexcoordsAtlas(sd, _ShadowAtlasSize.zw, positionWS, perspective);
/* sample the texture */
Expand Down Expand Up @@ -231,12 +237,12 @@ float EvalShadow_CascadedDepth_Blend(HDShadowContext shadowContext, Texture2D te
HDShadowData sd = shadowContext.shadowDatas[index];
LoadDirectionalShadowDatas(sd, shadowContext, index + shadowSplitIndex);
positionWS = positionWS + sd.cacheTranslationDelta.xyz;

#if SHADOW_USE_NORMAL_BIAS
/* normal based bias */
float3 orig_pos = positionWS;
float3 normalBias = EvalShadow_NormalBias(sd.worldTexelSize, sd.normalBias, normalWS);
positionWS += normalBias;

#endif
/* get shadowmap texcoords */
float3 posTC = EvalShadow_GetTexcoordsAtlas(sd, _CascadeShadowAtlasSize.zw, positionWS, false);
/* evalute the first cascade */
Expand Down Expand Up @@ -278,11 +284,10 @@ float EvalShadow_CascadedDepth_Dither(HDShadowContext shadowContext, Texture2D t
HDShadowData sd = shadowContext.shadowDatas[index];
LoadDirectionalShadowDatas(sd, shadowContext, index + shadowSplitIndex);
positionWS = positionWS + sd.cacheTranslationDelta.xyz;

#if SHADOW_USE_NORMAL_BIAS
/* normal based bias */
float worldTexelSize = sd.worldTexelSize;
float3 normalBias = EvalShadow_NormalBias(worldTexelSize, sd.normalBias, normalWS);

/* We select what split we need to sample from */
float nextSplit = min(shadowSplitIndex + 1, cascadeCount - 1);
bool evalNextCascade = nextSplit != shadowSplitIndex && step(InterleavedGradientNoise(positionSS.xy, _TaaFrameInfo.z), alpha);
Expand All @@ -295,6 +300,7 @@ float EvalShadow_CascadedDepth_Dither(HDShadowContext shadowContext, Texture2D t
}

positionWS += normalBias;
#endif
float3 posTC = EvalShadow_GetTexcoordsAtlas(sd, _CascadeShadowAtlasSize.zw, positionWS, false);

shadow = DIRECTIONAL_FILTER_ALGORITHM(sd, positionSS, posTC, tex, samp, FIXED_UNIFORM_BIAS);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,12 @@
#define VBUFFER_VOXEL_SIZE 8
#endif

#define GROUP_SIZE_1D 8
#define SUPPORT_LOCAL_LIGHTS 1 // Local lights contribute to fog lighting
#define SHADOW_USE_DEPTH_BIAS 0
#define PREFER_HALF 0
#define PREFER_HALF 0
#define GROUP_SIZE_1D 8
#define SUPPORT_LOCAL_LIGHTS 1 // Local lights contribute to fog lighting
#define SHADOW_USE_DEPTH_BIAS 0 // Too expensive
#define SHADOW_USE_NORMAL_BIAS 0 // There may be no geometry along the ray, and even if there is geometry along the ray,
// it only occupies certain slices, and may not have a normal G-buffer to sample.

//--------------------------------------------------------------------------------------------------
// Included headers
Expand Down

0 comments on commit 2dfeab2

Please sign in to comment.