From 3dfd578778d92b6ed095acf94d37df8bc04b1c29 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tur=C3=A1nszki=20J=C3=A1nos?= Date: Mon, 10 Mar 2025 08:08:58 +0100 Subject: [PATCH] ddgi backface pulling leak improvement --- WickedEngine/shaders/ddgi_raytraceCS.hlsl | 13 ++++++++----- WickedEngine/shaders/surfel_raytraceCS.hlsl | 15 +++++++++++---- WickedEngine/wiRenderer.cpp | 2 +- WickedEngine/wiScene.cpp | 20 ++++++++++++-------- WickedEngine/wiVersion.cpp | 2 +- 5 files changed, 33 insertions(+), 19 deletions(-) diff --git a/WickedEngine/shaders/ddgi_raytraceCS.hlsl b/WickedEngine/shaders/ddgi_raytraceCS.hlsl index 3ccc2f371..551b42521 100644 --- a/WickedEngine/shaders/ddgi_raytraceCS.hlsl +++ b/WickedEngine/shaders/ddgi_raytraceCS.hlsl @@ -173,9 +173,8 @@ void main(uint3 DTid : SV_DispatchThreadID, uint3 Gid : SV_GroupID, uint groupIn wiRayQuery q; q.TraceRayInline( scene_acceleration_structure, // RaytracingAccelerationStructure AccelerationStructure - RAY_FLAG_CULL_FRONT_FACING_TRIANGLES | + //RAY_FLAG_CULL_FRONT_FACING_TRIANGLES | RAY_FLAG_SKIP_PROCEDURAL_PRIMITIVES | - RAY_FLAG_CULL_FRONT_FACING_TRIANGLES | RAY_FLAG_ACCEPT_FIRST_HIT_AND_END_SEARCH, // uint RayFlags 0xFF, // uint InstanceInclusionMask newRay // RayDesc Ray @@ -205,7 +204,7 @@ void main(uint3 DTid : SV_DispatchThreadID, uint3 Gid : SV_GroupID, uint groupIn wiRayQuery q; q.TraceRayInline( scene_acceleration_structure, // RaytracingAccelerationStructure AccelerationStructure - RAY_FLAG_CULL_BACK_FACING_TRIANGLES | + //RAY_FLAG_CULL_BACK_FACING_TRIANGLES | RAY_FLAG_SKIP_PROCEDURAL_PRIMITIVES | RAY_FLAG_FORCE_OPAQUE, // uint RayFlags push.instanceInclusionMask, // uint InstanceInclusionMask @@ -278,6 +277,11 @@ void main(uint3 DTid : SV_DispatchThreadID, uint3 Gid : SV_GroupID, uint groupIn #endif // RTAPI + if (surface.IsBackface()) + { + hit_depth *= 0.9; // push inwards to help avoid shadow leaks from inwards to outside + } + surface.P = ray.Origin; surface.V = -ray.Direction; surface.update(); @@ -395,9 +399,8 @@ void main(uint3 DTid : SV_DispatchThreadID, uint3 Gid : SV_GroupID, uint groupIn #ifdef RTAPI q.TraceRayInline( scene_acceleration_structure, // RaytracingAccelerationStructure AccelerationStructure - RAY_FLAG_CULL_FRONT_FACING_TRIANGLES | + //RAY_FLAG_CULL_FRONT_FACING_TRIANGLES | RAY_FLAG_SKIP_PROCEDURAL_PRIMITIVES | - RAY_FLAG_CULL_FRONT_FACING_TRIANGLES | RAY_FLAG_ACCEPT_FIRST_HIT_AND_END_SEARCH, // uint RayFlags 0xFF, // uint InstanceInclusionMask newRay // RayDesc Ray diff --git a/WickedEngine/shaders/surfel_raytraceCS.hlsl b/WickedEngine/shaders/surfel_raytraceCS.hlsl index b62724191..6e89f977b 100644 --- a/WickedEngine/shaders/surfel_raytraceCS.hlsl +++ b/WickedEngine/shaders/surfel_raytraceCS.hlsl @@ -160,7 +160,8 @@ void main(uint3 DTid : SV_DispatchThreadID) scene_acceleration_structure, // RaytracingAccelerationStructure AccelerationStructure RAY_FLAG_SKIP_PROCEDURAL_PRIMITIVES | RAY_FLAG_FORCE_OPAQUE | - RAY_FLAG_CULL_FRONT_FACING_TRIANGLES | RAY_FLAG_ACCEPT_FIRST_HIT_AND_END_SEARCH, // uint RayFlags + //RAY_FLAG_CULL_FRONT_FACING_TRIANGLES | + RAY_FLAG_ACCEPT_FIRST_HIT_AND_END_SEARCH, // uint RayFlags 0xFF, // uint InstanceInclusionMask newRay // RayDesc Ray ); @@ -193,8 +194,8 @@ void main(uint3 DTid : SV_DispatchThreadID) q.TraceRayInline( scene_acceleration_structure, // RaytracingAccelerationStructure AccelerationStructure RAY_FLAG_SKIP_PROCEDURAL_PRIMITIVES | - RAY_FLAG_FORCE_OPAQUE | - RAY_FLAG_CULL_BACK_FACING_TRIANGLES, // uint RayFlags + //RAY_FLAG_CULL_BACK_FACING_TRIANGLES | + RAY_FLAG_FORCE_OPAQUE, // uint RayFlags push.instanceInclusionMask, // uint InstanceInclusionMask ray // RayDesc Ray ); @@ -261,6 +262,11 @@ void main(uint3 DTid : SV_DispatchThreadID) #endif // RTAPI + if (surface.IsBackface()) + { + hit_depth *= 0.5; // push inwards to help avoid shadow leaks from inwards to outside + } + surface.P = ray.Origin; surface.V = -ray.Direction; surface.update(); @@ -382,7 +388,8 @@ void main(uint3 DTid : SV_DispatchThreadID) scene_acceleration_structure, // RaytracingAccelerationStructure AccelerationStructure RAY_FLAG_SKIP_PROCEDURAL_PRIMITIVES | RAY_FLAG_FORCE_OPAQUE | - RAY_FLAG_CULL_FRONT_FACING_TRIANGLES | RAY_FLAG_ACCEPT_FIRST_HIT_AND_END_SEARCH, // uint RayFlags + //RAY_FLAG_CULL_FRONT_FACING_TRIANGLES | + RAY_FLAG_ACCEPT_FIRST_HIT_AND_END_SEARCH, // uint RayFlags 0xFF, // uint InstanceInclusionMask newRay // RayDesc Ray ); diff --git a/WickedEngine/wiRenderer.cpp b/WickedEngine/wiRenderer.cpp index 9b9b7b66d..d5c78a14f 100644 --- a/WickedEngine/wiRenderer.cpp +++ b/WickedEngine/wiRenderer.cpp @@ -142,7 +142,7 @@ bool VXGI_ENABLED = false; bool VXGI_REFLECTIONS_ENABLED = true; bool VXGI_DEBUG = false; int VXGI_DEBUG_CLIPMAP = 0; -bool CAPSULE_SHADOW_ENABLED = true; +bool CAPSULE_SHADOW_ENABLED = false; float CAPSULE_SHADOW_ANGLE = XM_PIDIV4; float CAPSULE_SHADOW_FADE = 0.2f; diff --git a/WickedEngine/wiScene.cpp b/WickedEngine/wiScene.cpp index a1cad8afc..c5606cf5f 100644 --- a/WickedEngine/wiScene.cpp +++ b/WickedEngine/wiScene.cpp @@ -555,6 +555,7 @@ namespace wi::scene if (wi::renderer::GetDDGIEnabled()) { + float bounds_blend = 0.01f; ddgi.frame_index++; if (!TLAS.IsValid() && !BVH.IsValid()) { @@ -563,6 +564,7 @@ namespace wi::scene if (!ddgi.ray_buffer.IsValid()) // Check the ray_buffer here because that is invalid with serialized DDGI data, and we can detect if dynamic resources need recreation when serialized is loaded { ddgi.frame_index = 0; + bounds_blend = 1; const uint32_t probe_count = ddgi.grid_dimensions.x * ddgi.grid_dimensions.y * ddgi.grid_dimensions.z; @@ -611,14 +613,16 @@ namespace wi::scene device->CreateTexture(&tex, nullptr, &ddgi.depth_texture); device->SetName(&ddgi.depth_texture, "ddgi.depth_texture"); } - ddgi.grid_min = bounds.getMin(); - ddgi.grid_min.x -= 1; - ddgi.grid_min.y -= 1; - ddgi.grid_min.z -= 1; - ddgi.grid_max = bounds.getMax(); - ddgi.grid_max.x += 1; - ddgi.grid_max.y += 1; - ddgi.grid_max.z += 1; + float3 grid_min = bounds.getMin(); + grid_min.x -= 1; + grid_min.y -= 1; + grid_min.z -= 1; + float3 grid_max = bounds.getMax(); + grid_max.x += 1; + grid_max.y += 1; + grid_max.z += 1; + ddgi.grid_min = wi::math::Lerp(ddgi.grid_min, grid_min, bounds_blend); + ddgi.grid_max = wi::math::Lerp(ddgi.grid_max, grid_max, bounds_blend); } else if (ddgi.ray_buffer.IsValid()) // if ray_buffer is valid, it means DDGI was not from serialization, so it will be deleted when DDGI is disabled { diff --git a/WickedEngine/wiVersion.cpp b/WickedEngine/wiVersion.cpp index c66263d50..1e0af9b6c 100644 --- a/WickedEngine/wiVersion.cpp +++ b/WickedEngine/wiVersion.cpp @@ -9,7 +9,7 @@ namespace wi::version // minor features, major updates, breaking compatibility changes const int minor = 71; // minor bug fixes, alterations, refactors, updates - const int revision = 697; + const int revision = 698; const std::string version_string = std::to_string(major) + "." + std::to_string(minor) + "." + std::to_string(revision);