11// Configure which shadow algorithms to use per shadow level quality
22
3+ #ifndef SHADOW_USE_NORMAL_BIAS
4+ #define SHADOW_USE_NORMAL_BIAS 1 // Externally define as 0 to disable
5+ #endif
6+
37// Since we use slope-scale bias, the constant bias is for now set as a small fixed value
48#define FIXED_UNIFORM_BIAS (1.0f / 65536.0f )
59
@@ -123,10 +127,12 @@ float3 EvalShadow_NormalBias(float worldTexelSize, float normalBias, float3 norm
123127float EvalShadow_PunctualDepth (HDShadowData sd, Texture2D tex, SamplerComparisonState samp, float2 positionSS, float3 positionWS, float3 normalWS, float3 L, float L_dist, bool perspective)
124128{
125129 positionWS = positionWS + sd.cacheTranslationDelta.xyz;
130+ #if SHADOW_USE_NORMAL_BIAS
126131 /* bias the world position */
127132 float worldTexelSize = EvalShadow_WorldTexelSize (sd.worldTexelSize, L_dist, true );
128133 float3 normalBias = EvalShadow_NormalBias (worldTexelSize, sd.normalBias, normalWS);
129134 positionWS += normalBias;
135+ #endif
130136 /* get shadowmap texcoords */
131137 float3 posTC = EvalShadow_GetTexcoordsAtlas (sd, _ShadowAtlasSize.zw, positionWS, perspective);
132138 /* sample the texture */
@@ -231,12 +237,12 @@ float EvalShadow_CascadedDepth_Blend(HDShadowContext shadowContext, Texture2D te
231237 HDShadowData sd = shadowContext.shadowDatas[index];
232238 LoadDirectionalShadowDatas (sd, shadowContext, index + shadowSplitIndex);
233239 positionWS = positionWS + sd.cacheTranslationDelta.xyz;
234-
240+ #if SHADOW_USE_NORMAL_BIAS
235241 /* normal based bias */
236242 float3 orig_pos = positionWS;
237243 float3 normalBias = EvalShadow_NormalBias (sd.worldTexelSize, sd.normalBias, normalWS);
238244 positionWS += normalBias;
239-
245+ #endif
240246 /* get shadowmap texcoords */
241247 float3 posTC = EvalShadow_GetTexcoordsAtlas (sd, _CascadeShadowAtlasSize.zw, positionWS, false );
242248 /* evalute the first cascade */
@@ -278,11 +284,10 @@ float EvalShadow_CascadedDepth_Dither(HDShadowContext shadowContext, Texture2D t
278284 HDShadowData sd = shadowContext.shadowDatas[index];
279285 LoadDirectionalShadowDatas (sd, shadowContext, index + shadowSplitIndex);
280286 positionWS = positionWS + sd.cacheTranslationDelta.xyz;
281-
287+ #if SHADOW_USE_NORMAL_BIAS
282288 /* normal based bias */
283289 float worldTexelSize = sd.worldTexelSize;
284290 float3 normalBias = EvalShadow_NormalBias (worldTexelSize, sd.normalBias, normalWS);
285-
286291 /* We select what split we need to sample from */
287292 float nextSplit = min (shadowSplitIndex + 1 , cascadeCount - 1 );
288293 bool evalNextCascade = nextSplit != shadowSplitIndex && step (InterleavedGradientNoise (positionSS.xy, _TaaFrameInfo.z), alpha);
@@ -295,6 +300,7 @@ float EvalShadow_CascadedDepth_Dither(HDShadowContext shadowContext, Texture2D t
295300 }
296301
297302 positionWS += normalBias;
303+ #endif
298304 float3 posTC = EvalShadow_GetTexcoordsAtlas (sd, _CascadeShadowAtlasSize.zw, positionWS, false );
299305
300306 shadow = DIRECTIONAL_FILTER_ALGORITHM (sd, positionSS, posTC, tex, samp, FIXED_UNIFORM_BIAS);
0 commit comments