From 843a6ec1af596bb5c6307afa64ed9d2ac7a301ca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tur=C3=A1nszki=20J=C3=A1nos?= Date: Thu, 22 May 2025 08:39:07 +0200 Subject: [PATCH] transparent shadow fix --- WickedEngine/shaders/shadowHF.hlsli | 2 +- WickedEngine/shaders/shadow_filterCS.hlsl | 23 +++++++++++++++++++++-- 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/WickedEngine/shaders/shadowHF.hlsli b/WickedEngine/shaders/shadowHF.hlsli index 5388907d4..28b78113e 100644 --- a/WickedEngine/shaders/shadowHF.hlsli +++ b/WickedEngine/shaders/shadowHF.hlsli @@ -14,7 +14,7 @@ inline half3 sample_shadow(float2 uv, float cmp) Texture2D texture_shadowatlas_transparent = bindless_textures_half4[descriptor_index(GetFrame().texture_shadowatlas_transparent_index)]; half4 transparent_shadow = texture_shadowatlas_transparent.SampleLevel(sampler_linear_clamp, uv, 0); #ifdef TRANSPARENT_SHADOWMAP_SECONDARY_DEPTH_CHECK - if (transparent_shadow.a > cmp) + if (transparent_shadow.a < cmp) #endif // TRANSPARENT_SHADOWMAP_SECONDARY_DEPTH_CHECK { shadow *= transparent_shadow.rgb; diff --git a/WickedEngine/shaders/shadow_filterCS.hlsl b/WickedEngine/shaders/shadow_filterCS.hlsl index ba3d3434c..015375b66 100644 --- a/WickedEngine/shaders/shadow_filterCS.hlsl +++ b/WickedEngine/shaders/shadow_filterCS.hlsl @@ -24,7 +24,7 @@ void main(uint3 DTid : SV_DispatchThreadID) const float2 bottomright = (filter.rect.xy + filter.rect.zw - border) * filter.atlas_resolution_rcp; float filtered = 0; - float transparent_filtered = 0; + float4 transparent_filtered = 0; const float2 spread_offset = filter.atlas_resolution_rcp * (2 + filter.spread * 8); const uint soft_shadow_sample_count = (uint)lerp(8.0, 128.0, saturate(length(filter.spread))); @@ -58,7 +58,26 @@ void main(uint3 DTid : SV_DispatchThreadID) zzzz = saturate(zzzz); zzzz = exp(exponential_shadow_bias * zzzz); filtered += bilinear(zzzz, frac(sample_uv * filter.atlas_resolution)); - transparent_filtered += shadowAtlas_transparent.SampleLevel(sampler_linear_clamp, sample_uv, 0); + + float4 aaaa = shadowAtlas_transparent.GatherAlpha(sampler_linear_clamp, sample_uv); + if (ortho) + { + aaaa = 1 - aaaa; + } + else + { + const float2 origin_uv = inverse_lerp(uv_remap.xy, uv_remap.zw, sample_uv); + aaaa = float4( + distance(filter.eye, reconstruct_position(origin_uv, aaaa.x, filter.inverse_view_projection)), + distance(filter.eye, reconstruct_position(origin_uv, aaaa.y, filter.inverse_view_projection)), + distance(filter.eye, reconstruct_position(origin_uv, aaaa.z, filter.inverse_view_projection)), + distance(filter.eye, reconstruct_position(origin_uv, aaaa.w, filter.inverse_view_projection)) + ); + aaaa = (aaaa * filter.range_rcp); + } + aaaa = saturate(aaaa); + float a = bilinear(aaaa, frac(sample_uv * filter.atlas_resolution)); + transparent_filtered += float4(shadowAtlas_transparent.SampleLevel(sampler_linear_clamp, sample_uv, 0).rgb, a); } filtered *= soft_shadow_sample_count_rcp; transparent_filtered *= soft_shadow_sample_count_rcp;