Skip to content

Commit 2dfeab2

Browse files
committed
Add an option to disable shadow bias
1 parent c6aa4cf commit 2dfeab2

File tree

2 files changed

+16
-8
lines changed

2 files changed

+16
-8
lines changed

com.unity.render-pipelines.high-definition/Runtime/Lighting/Shadow/HDShadowAlgorithms.hlsl

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
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
123127
float 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);

com.unity.render-pipelines.high-definition/Runtime/Lighting/VolumetricLighting/VolumetricLighting.compute

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,12 @@
2828
#define VBUFFER_VOXEL_SIZE 8
2929
#endif
3030

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

3638
//--------------------------------------------------------------------------------------------------
3739
// Included headers

0 commit comments

Comments
 (0)