From f3c1a7ba0b16cfa16626ba79b3dd6fd3ba0e09cb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tur=C3=A1nszki=20J=C3=A1nos?= Date: Thu, 22 May 2025 09:25:45 +0200 Subject: [PATCH] rain blocker fix --- WickedEngine/shaders/ShaderInterop_Renderer.h | 20 +++++++++---------- WickedEngine/shaders/lightingHF.hlsli | 8 ++++---- WickedEngine/shaders/shadowHF.hlsli | 8 ++++---- WickedEngine/shaders/shadow_filterCS.hlsl | 2 +- .../shaders/volumetricLight_PointPS.hlsl | 2 +- WickedEngine/wiRenderer.cpp | 6 +++++- 6 files changed, 25 insertions(+), 21 deletions(-) diff --git a/WickedEngine/shaders/ShaderInterop_Renderer.h b/WickedEngine/shaders/ShaderInterop_Renderer.h index eb07bf79f..14ef575dd 100644 --- a/WickedEngine/shaders/ShaderInterop_Renderer.h +++ b/WickedEngine/shaders/ShaderInterop_Renderer.h @@ -1175,24 +1175,21 @@ struct alignas(16) FrameCB uint frame_count; uint temporalaa_samplerotation; - int texture_shadowatlas_index; - int texture_shadowatlas_transparent_index; + uint entity_culling_count; + uint capsuleshadow_fade_angle; uint2 shadow_atlas_resolution; float2 shadow_atlas_resolution_rcp; - float4x4 cloudShadowLightSpaceMatrix; - float4x4 cloudShadowLightSpaceMatrixInverse; - + int texture_shadowatlas_index; + int texture_shadowatlas_filtered_index; + int texture_shadowatlas_transparent_index; float cloudShadowFarPlaneKm; - int texture_volumetricclouds_shadow_index; - uint giboost_packed; // force fp16 load - uint entity_culling_count; - uint capsuleshadow_fade_angle; + uint giboost_packed; // force fp16 load + int texture_volumetricclouds_shadow_index; int indirect_debugbufferindex; int padding0; - int padding1; float blue_noise_phase; int texture_random64x64_index; @@ -1217,6 +1214,9 @@ struct alignas(16) FrameCB float4x4 rain_blocker_matrix_prev; float4x4 rain_blocker_matrix_inverse_prev; + float4x4 cloudShadowLightSpaceMatrix; + float4x4 cloudShadowLightSpaceMatrixInverse; + ShaderScene scene; VXGI vxgi; diff --git a/WickedEngine/shaders/lightingHF.hlsli b/WickedEngine/shaders/lightingHF.hlsli index 2d1a79fd0..c0f0099cb 100644 --- a/WickedEngine/shaders/lightingHF.hlsli +++ b/WickedEngine/shaders/lightingHF.hlsli @@ -98,7 +98,7 @@ inline void light_directional(in ShaderEntity light, in Surface surface, inout L if (cascade_fade > 0 && dither(surface.pixel + GetTemporalAASampleRotation()) < cascade_fade) continue; - light_color *= shadow_2D(light, 1 - shadow_pos.z, shadow_uv.xy, cascade, 16); + light_color *= shadow_2D(light, 1 - shadow_pos.z, shadow_uv.xy, cascade); break; } } @@ -205,7 +205,7 @@ inline void light_point(in ShaderEntity light, in Surface surface, inout Lightin if ((GetFrame().options & OPTION_BIT_RAYTRACED_SHADOWS) == 0 || GetCamera().texture_rtshadow_index < 0 || (GetCamera().options & SHADERCAMERA_OPTION_USE_SHADOW_MASK) == 0) #endif // SHADOW_MASK_ENABLED { - light_color *= shadow_cube(light, LunnormalizedShadow, 1); + light_color *= shadow_cube(light, LunnormalizedShadow); } if (!any(light_color)) @@ -319,7 +319,7 @@ inline void light_spot(in ShaderEntity light, in Surface surface, inout Lighting [branch] if (is_saturated(shadow_uv)) { - light_color *= shadow_2D(light, rcp(dist_rcp) / range, shadow_uv.xy, 0, 1); + light_color *= shadow_2D(light, rcp(dist_rcp) / range, shadow_uv.xy, 0); } } @@ -452,7 +452,7 @@ inline void light_rect(in ShaderEntity light, in Surface surface, inout Lighting [branch] if (is_saturated(shadow_uv)) { - light_color *= shadow_2D(light, rcp(dist_rcp) / range, shadow_uv.xy, 0, 1); + light_color *= shadow_2D(light, rcp(dist_rcp) / range, shadow_uv.xy, 0); } } diff --git a/WickedEngine/shaders/shadowHF.hlsli b/WickedEngine/shaders/shadowHF.hlsli index 28b78113e..32cbf0efc 100644 --- a/WickedEngine/shaders/shadowHF.hlsli +++ b/WickedEngine/shaders/shadowHF.hlsli @@ -6,9 +6,9 @@ static const float exponential_shadow_bias = 80; inline half3 sample_shadow(float2 uv, float cmp) { - Texture2D texture_shadowatlas = bindless_textures_float[descriptor_index(GetFrame().texture_shadowatlas_index)]; + Texture2D texture_shadowatlas = bindless_textures_float[descriptor_index(GetFrame().texture_shadowatlas_filtered_index)]; float shadowMapValue = texture_shadowatlas.SampleLevel(sampler_linear_clamp, uv, 0); - half3 shadow = saturate(shadowMapValue * exp(-exponential_shadow_bias * cmp)); + half3 shadow = sqr(saturate(shadowMapValue * exp(-exponential_shadow_bias * cmp))); #ifndef DISABLE_TRANSPARENT_SHADOWMAP Texture2D texture_shadowatlas_transparent = bindless_textures_half4[descriptor_index(GetFrame().texture_shadowatlas_transparent_index)]; @@ -33,7 +33,7 @@ inline void shadow_border_clamp(in ShaderEntity light, in float slice, inout flo uv = clamp(uv, topleft, bottomright); } -inline half3 shadow_2D(in ShaderEntity light, in float z, in float2 shadow_uv, in uint cascade, in float shadow_power = 1) +inline half3 shadow_2D(in ShaderEntity light, in float z, in float2 shadow_uv, in uint cascade) { shadow_uv.x += cascade; shadow_uv = mad(shadow_uv, light.shadowAtlasMulAdd.xy, light.shadowAtlasMulAdd.zw); @@ -41,7 +41,7 @@ inline half3 shadow_2D(in ShaderEntity light, in float z, in float2 shadow_uv, i return sample_shadow(shadow_uv, z); } -inline half3 shadow_cube(in ShaderEntity light, in float3 Lunnormalized, in float shadow_power = 1) +inline half3 shadow_cube(in ShaderEntity light, in float3 Lunnormalized) { const float3 uv_slice = cubemap_to_uv(-Lunnormalized); float2 shadow_uv = uv_slice.xy; diff --git a/WickedEngine/shaders/shadow_filterCS.hlsl b/WickedEngine/shaders/shadow_filterCS.hlsl index 015375b66..42c03dcc1 100644 --- a/WickedEngine/shaders/shadow_filterCS.hlsl +++ b/WickedEngine/shaders/shadow_filterCS.hlsl @@ -27,7 +27,7 @@ void main(uint3 DTid : SV_DispatchThreadID) 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))); + const uint soft_shadow_sample_count = (uint)lerp(8.0, 12.0, saturate(length(filter.spread))); const float soft_shadow_sample_count_rcp = 1.0 / (float)soft_shadow_sample_count; const float soft_shadow_sample_count_sqrt_rcp = rsqrt((float)soft_shadow_sample_count); diff --git a/WickedEngine/shaders/volumetricLight_PointPS.hlsl b/WickedEngine/shaders/volumetricLight_PointPS.hlsl index f57fb0415..2576f4a5b 100644 --- a/WickedEngine/shaders/volumetricLight_PointPS.hlsl +++ b/WickedEngine/shaders/volumetricLight_PointPS.hlsl @@ -66,7 +66,7 @@ float4 main(VertexToPixel input) : SV_TARGET [branch] if (light.IsCastingShadow()) { - attenuation *= shadow_cube(light, Lunnormalized, input.pos.xy); + attenuation *= shadow_cube(light, Lunnormalized); } [branch] diff --git a/WickedEngine/wiRenderer.cpp b/WickedEngine/wiRenderer.cpp index d7bdf9ca2..bb4e7286b 100644 --- a/WickedEngine/wiRenderer.cpp +++ b/WickedEngine/wiRenderer.cpp @@ -4245,9 +4245,11 @@ void UpdatePerFrameData( frameCB.indirect_debugbufferindex = device->GetDescriptorIndex(&buffers[BUFFERTYPE_INDIRECT_DEBUG_0], SubresourceType::UAV); // Note: shadow maps always assumed to be valid to avoid shader branching logic - const Texture& shadowMap = shadowMapAtlas_Filtered.IsValid() ? shadowMapAtlas_Filtered : *wi::texturehelper::getBlack(); + const Texture& shadowMap = shadowMapAtlas.IsValid() ? shadowMapAtlas : *wi::texturehelper::getBlack(); + const Texture& shadowMapFiltered = shadowMapAtlas_Filtered.IsValid() ? shadowMapAtlas_Filtered : *wi::texturehelper::getBlack(); const Texture& shadowMapTransparent = shadowMapAtlas_Transparent_Filtered.IsValid() ? shadowMapAtlas_Transparent_Filtered : *wi::texturehelper::getWhite(); frameCB.texture_shadowatlas_index = device->GetDescriptorIndex(&shadowMap, SubresourceType::SRV); + frameCB.texture_shadowatlas_filtered_index = device->GetDescriptorIndex(&shadowMapFiltered, SubresourceType::SRV); frameCB.texture_shadowatlas_transparent_index = device->GetDescriptorIndex(&shadowMapTransparent, SubresourceType::SRV); frameCB.shadow_atlas_resolution.x = shadowMap.desc.width; frameCB.shadow_atlas_resolution.y = shadowMap.desc.height; @@ -7157,6 +7159,7 @@ void DrawShadowmaps( break; } // terminate switch } +#if 0 // note: rain blocker doesn't use filtering for now, it uses pcf // Rain blocker filtering: if (vis.scene->weather.rain_amount > 0) { @@ -7173,6 +7176,7 @@ void DrawShadowmaps( device->BindDynamicConstantBuffer(filter, 2, cmd); device->Dispatch((filter.rect.z + 7u) / 8u, (filter.rect.w + 7u) / 8u, 1, cmd); } +#endif device->Barrier(GPUBarrier::Image(&shadowMapAtlas_Filtered, ResourceState::UNORDERED_ACCESS, ResourceState::SHADER_RESOURCE), cmd); device->Barrier(GPUBarrier::Image(&shadowMapAtlas_Transparent_Filtered, ResourceState::UNORDERED_ACCESS, ResourceState::SHADER_RESOURCE), cmd); device->EventEnd(cmd);