Skip to content

Commit

Permalink
fix: screenspace shadow blur in distance (doodlum#523)
Browse files Browse the repository at this point in the history
  • Loading branch information
doodlum authored Sep 12, 2024
1 parent 1ec916b commit 0c09c36
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@ namespace ScreenSpaceShadows
{
float4 GetBlurWeights(float4 depths, float centerDepth)
{
float4 depthDifference = (depths - centerDepth) * 1000;
centerDepth += 1.0;
float depthSharpness = saturate((1024.0 * 1024.0) / (centerDepth * centerDepth));
float4 depthDifference = (depths - centerDepth) * depthSharpness;
return exp2(-depthDifference * depthDifference);
}

float GetScreenSpaceShadow(float3 screenPosition, float2 uv, float noise, uint eyeIndex)
float GetScreenSpaceShadow(float3 screenPosition, float2 uv, float noise, float3 viewPosition, uint eyeIndex)
{
noise *= 2.0 * M_PI;

Expand Down Expand Up @@ -39,7 +41,9 @@ namespace ScreenSpaceShadows
shadowSamples[i] = ScreenSpaceShadowsTexture.Load(sampleCoord);
}

float4 blurWeights = GetBlurWeights(depthSamples, screenPosition.z);
depthSamples = GetScreenDepths(depthSamples);

float4 blurWeights = GetBlurWeights(depthSamples, viewPosition.z);
float shadow = dot(shadowSamples, blurWeights);

float blurWeightsTotal = dot(blurWeights, 1.0);
Expand Down
2 changes: 1 addition & 1 deletion package/Shaders/DistantTree.hlsl
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ PS_OUTPUT main(PS_INPUT input)
float dirShadow = 1;

# if defined(SCREEN_SPACE_SHADOWS)
dirShadow = ScreenSpaceShadows::GetScreenSpaceShadow(input.Position, screenUV, screenNoise, eyeIndex);
dirShadow = ScreenSpaceShadows::GetScreenSpaceShadow(input.Position, screenUV, screenNoise, viewPosition, eyeIndex);
# endif

# if defined(TERRAIN_SHADOWS)
Expand Down
2 changes: 1 addition & 1 deletion package/Shaders/Lighting.hlsl
Original file line number Diff line number Diff line change
Expand Up @@ -1915,7 +1915,7 @@ PS_OUTPUT main(PS_INPUT input, bool frontFace
# if defined(SOFT_LIGHTING) || defined(BACK_LIGHTING) || defined(RIM_LIGHTING)
if (dirLightAngle > 0.0)
# endif
dirDetailShadow = ScreenSpaceShadows::GetScreenSpaceShadow(input.Position, screenUV, screenNoise, eyeIndex);
dirDetailShadow = ScreenSpaceShadows::GetScreenSpaceShadow(input.Position, screenUV, screenNoise, viewPosition, eyeIndex);
# endif

# if defined(EMAT) && (defined(SKINNED) || !defined(MODELSPACENORMALS))
Expand Down
2 changes: 1 addition & 1 deletion package/Shaders/RunGrass.hlsl
Original file line number Diff line number Diff line change
Expand Up @@ -513,7 +513,7 @@ PS_OUTPUT main(PS_INPUT input, bool frontFace
if (dirShadowColor > 0.0) {
if (dirLightAngle > 0.0) {
# if defined(SCREEN_SPACE_SHADOWS)
dirDetailShadow = ScreenSpaceShadows::GetScreenSpaceShadow(input.HPosition, screenUV, screenNoise, eyeIndex);
dirDetailShadow = ScreenSpaceShadows::GetScreenSpaceShadow(input.HPosition, screenUV, screenNoise, viewPosition, eyeIndex);
# endif // SCREEN_SPACE_SHADOWS
}

Expand Down

0 comments on commit 0c09c36

Please sign in to comment.