diff --git a/features/Screen-Space Shadows/Shaders/ScreenSpaceShadows/ScreenSpaceShadows.hlsli b/features/Screen-Space Shadows/Shaders/ScreenSpaceShadows/ScreenSpaceShadows.hlsli index 6635f454d..3c9df2a84 100644 --- a/features/Screen-Space Shadows/Shaders/ScreenSpaceShadows/ScreenSpaceShadows.hlsli +++ b/features/Screen-Space Shadows/Shaders/ScreenSpaceShadows/ScreenSpaceShadows.hlsli @@ -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; @@ -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); diff --git a/package/Shaders/DistantTree.hlsl b/package/Shaders/DistantTree.hlsl index 954a5618a..6642313c9 100644 --- a/package/Shaders/DistantTree.hlsl +++ b/package/Shaders/DistantTree.hlsl @@ -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) diff --git a/package/Shaders/Lighting.hlsl b/package/Shaders/Lighting.hlsl index d98026b4d..5ef35b8b6 100644 --- a/package/Shaders/Lighting.hlsl +++ b/package/Shaders/Lighting.hlsl @@ -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)) diff --git a/package/Shaders/RunGrass.hlsl b/package/Shaders/RunGrass.hlsl index d9558b309..9d4a434e9 100644 --- a/package/Shaders/RunGrass.hlsl +++ b/package/Shaders/RunGrass.hlsl @@ -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 }