Skip to content

Commit

Permalink
SSGI depth rejection slider
Browse files Browse the repository at this point in the history
  • Loading branch information
turanszkij committed Apr 2, 2024
1 parent af983fa commit 40c4352
Show file tree
Hide file tree
Showing 9 changed files with 47 additions and 23 deletions.
45 changes: 31 additions & 14 deletions Editor/GraphicsWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -940,6 +940,23 @@ void GraphicsWindow::Create(EditorComponent* _editor)
AddWidget(&raytracedDiffuseCheckBox);
raytracedDiffuseCheckBox.SetEnabled(wi::graphics::GetDevice()->CheckCapability(GraphicsDeviceCapability::RAYTRACING));

raytracedDiffuseRangeSlider.Create(1.0f, 100.0f, 1, 1000, "RTDiffuse.Range: ");
raytracedDiffuseRangeSlider.SetText("Range: ");
raytracedDiffuseRangeSlider.SetTooltip("Set Reflection ray length for Ray traced diffuse.");
raytracedDiffuseRangeSlider.SetSize(XMFLOAT2(mod_wid, hei));
raytracedDiffuseRangeSlider.SetPos(XMFLOAT2(x + 100, y += step));
if (editor->main->config.GetSection("graphics").Has("rtdiffuse_range"))
{
editor->renderPath->setRaytracedDiffuseRange(editor->main->config.GetSection("graphics").GetFloat("rtdiffuse_range"));
}
raytracedDiffuseRangeSlider.OnSlide([=](wi::gui::EventArgs args) {
editor->renderPath->setRaytracedDiffuseRange(args.fValue);
editor->main->config.GetSection("graphics").Set("rtdiffuse_range", args.fValue);
editor->main->config.Commit();
});
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)");
Expand All @@ -956,22 +973,21 @@ void GraphicsWindow::Create(EditorComponent* _editor)
});
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.");
raytracedDiffuseRangeSlider.SetSize(XMFLOAT2(mod_wid, hei));
raytracedDiffuseRangeSlider.SetPos(XMFLOAT2(x + 100, y += step));
if (editor->main->config.GetSection("graphics").Has("rtdiffuse_range"))
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->setRaytracedDiffuseRange(editor->main->config.GetSection("graphics").GetFloat("rtdiffuse_range"));
editor->renderPath->setSSGIDepthRejection(editor->main->config.GetSection("graphics").GetFloat("ssgi_depthrejection"));
}
raytracedDiffuseRangeSlider.OnSlide([=](wi::gui::EventArgs args) {
editor->renderPath->setRaytracedDiffuseRange(args.fValue);
editor->main->config.GetSection("graphics").Set("rtdiffuse_range", args.fValue);
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(&raytracedDiffuseRangeSlider);
raytracedDiffuseRangeSlider.SetEnabled(wi::graphics::GetDevice()->CheckCapability(GraphicsDeviceCapability::RAYTRACING));
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.");
Expand Down Expand Up @@ -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());
Expand Down Expand Up @@ -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);
Expand Down
1 change: 1 addition & 0 deletions Editor/GraphicsWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ class GraphicsWindow : public wi::gui::Window
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;
Expand Down
7 changes: 2 additions & 5 deletions WickedEngine/shaders/ssgiCS.hlsl
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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)
{
Expand Down
3 changes: 2 additions & 1 deletion WickedEngine/wiRenderPath3D.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1749,7 +1749,8 @@ namespace wi
depthBuffer_Copy,
visibilityResources.texture_normals,
rtSSGI,
cmd
cmd,
getSSGIDepthRejection()
);
}
}
Expand Down
3 changes: 3 additions & 0 deletions WickedEngine/wiRenderPath3D.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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; }
Expand Down Expand Up @@ -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);
Expand Down
5 changes: 4 additions & 1 deletion WickedEngine/wiRenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);

Expand Down
3 changes: 2 additions & 1 deletion WickedEngine/wiRenderer.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down
2 changes: 1 addition & 1 deletion WickedEngine/wiVersion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
1 change: 1 addition & 0 deletions features.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 40c4352

Please sign in to comment.