From 40c435251e799cc1f122c2db59d98484e80b7dde Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tur=C3=A1nszki=20J=C3=A1nos?= Date: Tue, 2 Apr 2024 18:00:51 +0200 Subject: [PATCH] SSGI depth rejection slider --- Editor/GraphicsWindow.cpp | 53 +++++++++++++++++++++----------- Editor/GraphicsWindow.h | 1 + WickedEngine/shaders/ssgiCS.hlsl | 7 ++--- WickedEngine/wiRenderPath3D.cpp | 3 +- WickedEngine/wiRenderPath3D.h | 3 ++ WickedEngine/wiRenderer.cpp | 5 ++- WickedEngine/wiRenderer.h | 3 +- WickedEngine/wiVersion.cpp | 2 +- features.txt | 1 + 9 files changed, 51 insertions(+), 27 deletions(-) diff --git a/Editor/GraphicsWindow.cpp b/Editor/GraphicsWindow.cpp index 0af03fb53..221082c1e 100644 --- a/Editor/GraphicsWindow.cpp +++ b/Editor/GraphicsWindow.cpp @@ -940,22 +940,6 @@ void GraphicsWindow::Create(EditorComponent* _editor) AddWidget(&raytracedDiffuseCheckBox); raytracedDiffuseCheckBox.SetEnabled(wi::graphics::GetDevice()->CheckCapability(GraphicsDeviceCapability::RAYTRACING)); - ssgiCheckBox.Create("SSGI: "); - ssgiCheckBox.SetTooltip("Enable Screen Space Global Illumination, this can add a light bounce effect coming from objects on the screen."); - ssgiCheckBox.SetScriptTip("RenderPath3D::SetSSGIEnabled(bool value)"); - ssgiCheckBox.SetSize(XMFLOAT2(hei, hei)); - ssgiCheckBox.SetPos(XMFLOAT2(x + 140, y)); - if (editor->main->config.GetSection("graphics").Has("ssgi")) - { - editor->renderPath->setSSGIEnabled(editor->main->config.GetSection("graphics").GetBool("ssgi")); - } - ssgiCheckBox.OnClick([=](wi::gui::EventArgs args) { - editor->renderPath->setSSGIEnabled(args.bValue); - editor->main->config.GetSection("graphics").Set("ssgi", args.bValue); - editor->main->config.Commit(); - }); - AddWidget(&ssgiCheckBox); - raytracedDiffuseRangeSlider.Create(1.0f, 100.0f, 1, 1000, "RTDiffuse.Range: "); raytracedDiffuseRangeSlider.SetText("Range: "); raytracedDiffuseRangeSlider.SetTooltip("Set Reflection ray length for Ray traced diffuse."); @@ -973,6 +957,38 @@ void GraphicsWindow::Create(EditorComponent* _editor) AddWidget(&raytracedDiffuseRangeSlider); raytracedDiffuseRangeSlider.SetEnabled(wi::graphics::GetDevice()->CheckCapability(GraphicsDeviceCapability::RAYTRACING)); + ssgiCheckBox.Create("SSGI: "); + ssgiCheckBox.SetTooltip("Enable Screen Space Global Illumination, this can add a light bounce effect coming from objects on the screen."); + ssgiCheckBox.SetScriptTip("RenderPath3D::SetSSGIEnabled(bool value)"); + ssgiCheckBox.SetSize(XMFLOAT2(hei, hei)); + ssgiCheckBox.SetPos(XMFLOAT2(x + 140, y)); + if (editor->main->config.GetSection("graphics").Has("ssgi")) + { + editor->renderPath->setSSGIEnabled(editor->main->config.GetSection("graphics").GetBool("ssgi")); + } + ssgiCheckBox.OnClick([=](wi::gui::EventArgs args) { + editor->renderPath->setSSGIEnabled(args.bValue); + editor->main->config.GetSection("graphics").Set("ssgi", args.bValue); + editor->main->config.Commit(); + }); + AddWidget(&ssgiCheckBox); + + ssgiDepthRejectionSlider.Create(0.1f, 100.0f, 8, 1000, "SSGI.DepthRejection"); + ssgiDepthRejectionSlider.SetText("Depth: "); + ssgiDepthRejectionSlider.SetTooltip("SSGI depth rejection distance."); + ssgiDepthRejectionSlider.SetSize(XMFLOAT2(mod_wid, hei)); + ssgiDepthRejectionSlider.SetPos(XMFLOAT2(x + 100, y)); + if (editor->main->config.GetSection("graphics").Has("ssgi_depthrejection")) + { + editor->renderPath->setSSGIDepthRejection(editor->main->config.GetSection("graphics").GetFloat("ssgi_depthrejection")); + } + ssgiDepthRejectionSlider.OnSlide([=](wi::gui::EventArgs args) { + editor->renderPath->setSSGIDepthRejection(args.fValue); + editor->main->config.GetSection("graphics").Set("ssgi_depthrejection", args.fValue); + editor->main->config.Commit(); + }); + AddWidget(&ssgiDepthRejectionSlider); + screenSpaceShadowsCheckBox.Create("Screen Shadows: "); screenSpaceShadowsCheckBox.SetTooltip("Enable screen space contact shadows. This can add small shadows details to shadow maps in screen space."); screenSpaceShadowsCheckBox.SetSize(XMFLOAT2(hei, hei)); @@ -1545,6 +1561,7 @@ void GraphicsWindow::Update() raytracedDiffuseRangeSlider.SetValue(editor->renderPath->getRaytracedDiffuseRange()); screenSpaceShadowsCheckBox.SetCheck(wi::renderer::GetScreenSpaceShadowsEnabled()); screenSpaceShadowsRangeSlider.SetValue((float)editor->renderPath->getScreenSpaceShadowRange()); + ssgiDepthRejectionSlider.SetValue((float)editor->renderPath->getSSGIDepthRejection()); screenSpaceShadowsStepCountSlider.SetValue((float)editor->renderPath->getScreenSpaceShadowSampleCount()); eyeAdaptionCheckBox.SetCheck(editor->renderPath->getEyeAdaptionEnabled()); eyeAdaptionKeySlider.SetValue(editor->renderPath->getEyeAdaptionKey()); @@ -1804,8 +1821,8 @@ void GraphicsWindow::ResizeLayout() ssrCheckBox.SetPos(XMFLOAT2(reflectionsRoughnessCutoffSlider.GetPos().x - ssrCheckBox.GetSize().x - 80, reflectionsRoughnessCutoffSlider.GetPos().y)); add_right(raytracedReflectionsRangeSlider); raytracedReflectionsCheckBox.SetPos(XMFLOAT2(raytracedReflectionsRangeSlider.GetPos().x - raytracedReflectionsCheckBox.GetSize().x - 80, raytracedReflectionsRangeSlider.GetPos().y)); - add_right(ssgiCheckBox); - ssgiCheckBox.SetPos(XMFLOAT2(raytracedReflectionsCheckBox.GetPos().x, ssgiCheckBox.GetPos().y)); + add_right(ssgiDepthRejectionSlider); + ssgiCheckBox.SetPos(XMFLOAT2(ssgiDepthRejectionSlider.GetPos().x - ssgiCheckBox.GetSize().x - 80, ssgiDepthRejectionSlider.GetPos().y)); add_right(raytracedDiffuseRangeSlider); raytracedDiffuseCheckBox.SetPos(XMFLOAT2(raytracedDiffuseRangeSlider.GetPos().x - raytracedDiffuseCheckBox.GetSize().x - 80, raytracedDiffuseRangeSlider.GetPos().y)); add_right(screenSpaceShadowsStepCountSlider); diff --git a/Editor/GraphicsWindow.h b/Editor/GraphicsWindow.h index 34406d946..3d26b74f2 100644 --- a/Editor/GraphicsWindow.h +++ b/Editor/GraphicsWindow.h @@ -64,6 +64,7 @@ public: wi::gui::CheckBox raytracedDiffuseCheckBox; wi::gui::Slider raytracedDiffuseRangeSlider; wi::gui::CheckBox ssgiCheckBox; + wi::gui::Slider ssgiDepthRejectionSlider; wi::gui::CheckBox screenSpaceShadowsCheckBox; wi::gui::Slider screenSpaceShadowsStepCountSlider; wi::gui::Slider screenSpaceShadowsRangeSlider; diff --git a/WickedEngine/shaders/ssgiCS.hlsl b/WickedEngine/shaders/ssgiCS.hlsl index fb73290d4..87a361f55 100644 --- a/WickedEngine/shaders/ssgiCS.hlsl +++ b/WickedEngine/shaders/ssgiCS.hlsl @@ -28,9 +28,6 @@ inline uint coord_to_cache(int2 coord) return flatten2D(clamp(coord, 0, TILE_SIZE - 1), TILE_SIZE); } -static const float depthRejection = 8; -static const float depthRejection_rcp = rcp(depthRejection); - float3 compute_diffuse( float3 origin_position, float3 origin_normal, @@ -46,8 +43,8 @@ float3 compute_diffuse( sample_position.z = cache_z[t]; sample_position.xy = unpack_half2(cache_xy[t]); const float3 origin_to_sample = sample_position - origin_position; - float occlusion = saturate(dot(origin_normal, origin_to_sample)); // normal falloff - occlusion *= saturate(1 + origin_to_sample.z * depthRejection_rcp); // depth falloff + float occlusion = saturate(dot(origin_normal, origin_to_sample)); // normal falloff + occlusion *= saturate(1 + origin_to_sample.z * postprocess.params0.w); // depth rejection if(occlusion > 0) { diff --git a/WickedEngine/wiRenderPath3D.cpp b/WickedEngine/wiRenderPath3D.cpp index be2ad8ba3..d7cbcab52 100644 --- a/WickedEngine/wiRenderPath3D.cpp +++ b/WickedEngine/wiRenderPath3D.cpp @@ -1749,7 +1749,8 @@ namespace wi depthBuffer_Copy, visibilityResources.texture_normals, rtSSGI, - cmd + cmd, + getSSGIDepthRejection() ); } } diff --git a/WickedEngine/wiRenderPath3D.h b/WickedEngine/wiRenderPath3D.h index 961063f27..341c5909a 100644 --- a/WickedEngine/wiRenderPath3D.h +++ b/WickedEngine/wiRenderPath3D.h @@ -55,6 +55,7 @@ namespace wi float raytracedDiffuseRange = 10; float raytracedReflectionsRange = 10000.0f; float reflectionRoughnessCutoff = 0.6f; + float ssgiDepthRejection = 8; wi::renderer::Tonemap tonemap = wi::renderer::Tonemap::ACES; AO ao = AO_DISABLED; @@ -235,6 +236,7 @@ namespace wi constexpr float getRaytracedDiffuseRange() const { return raytracedDiffuseRange; } constexpr float getRaytracedReflectionsRange() const { return raytracedReflectionsRange; } constexpr float getReflectionRoughnessCutoff() const { return reflectionRoughnessCutoff; } + constexpr float getSSGIDepthRejection() const { return ssgiDepthRejection; } constexpr wi::renderer::Tonemap getTonemap() const { return tonemap; } constexpr bool getAOEnabled() const { return ao != AO_DISABLED; } @@ -290,6 +292,7 @@ namespace wi constexpr void setRaytracedDiffuseRange(float value) { raytracedDiffuseRange = value; } constexpr void setRaytracedReflectionsRange(float value) { raytracedReflectionsRange = value; } constexpr void setReflectionRoughnessCutoff(float value) { reflectionRoughnessCutoff = value; } + constexpr void setSSGIDepthRejection(float value) { ssgiDepthRejection = value; } constexpr void setTonemap(wi::renderer::Tonemap value) { tonemap = value; } void setAO(AO value); diff --git a/WickedEngine/wiRenderer.cpp b/WickedEngine/wiRenderer.cpp index a9f6a7d7a..9442552f5 100644 --- a/WickedEngine/wiRenderer.cpp +++ b/WickedEngine/wiRenderer.cpp @@ -12506,7 +12506,8 @@ void Postprocess_SSGI( const Texture& input_depth, const Texture& input_normal, const Texture& output, - CommandList cmd + CommandList cmd, + float depthRejection ) { device->EventBegin("Postprocess_SSGI", cmd); @@ -12596,6 +12597,8 @@ void Postprocess_SSGI( { device->EventBegin("SSGI - diffuse", cmd); + postprocess.params0.w = 1.0f / depthRejection; + // Wide sampling passes: device->BindComputeShader(&shaders[CSTYPE_POSTPROCESS_SSGI_WIDE], cmd); diff --git a/WickedEngine/wiRenderer.h b/WickedEngine/wiRenderer.h index 90f9aa787..6e58f18b1 100644 --- a/WickedEngine/wiRenderer.h +++ b/WickedEngine/wiRenderer.h @@ -568,7 +568,8 @@ namespace wi::renderer const wi::graphics::Texture& input_depth, const wi::graphics::Texture& input_normal, const wi::graphics::Texture& output, - wi::graphics::CommandList cmd + wi::graphics::CommandList cmd, + float depthRejection = 8 ); struct RTReflectionResources { diff --git a/WickedEngine/wiVersion.cpp b/WickedEngine/wiVersion.cpp index 1d1a26b80..aea2fd8d6 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 = 419; + const int revision = 420; const std::string version_string = std::to_string(major) + "." + std::to_string(minor) + "." + std::to_string(revision); diff --git a/features.txt b/features.txt index 00754fda7..bc98f5e6e 100644 --- a/features.txt +++ b/features.txt @@ -88,6 +88,7 @@ Humanoid rig Animation retargeting Video decoding: H264 3D path finding +Screen Space Global Illumination (SSGI) GLTF 2.0 - KHR extensions supported: KHR_materials_unlit