diff --git a/Editor/RendererWindow.cpp b/Editor/RendererWindow.cpp index 333720484..36818c2db 100644 --- a/Editor/RendererWindow.cpp +++ b/Editor/RendererWindow.cpp @@ -68,15 +68,21 @@ void RendererWindow::Create(EditorComponent* editor) surfelGICheckBox.SetCheck(wi::renderer::GetSurfelGIEnabled()); AddWidget(&surfelGICheckBox); - surfelGIDebugCheckBox.Create("DEBUG: "); - surfelGIDebugCheckBox.SetTooltip("Toggle Surfel GI visualization."); - surfelGIDebugCheckBox.SetPos(XMFLOAT2(x + 122, y)); - surfelGIDebugCheckBox.SetSize(XMFLOAT2(itemheight, itemheight)); - surfelGIDebugCheckBox.OnClick([](wi::gui::EventArgs args) { - wi::renderer::SetSurfelGIDebugEnabled(args.bValue); - }); - surfelGIDebugCheckBox.SetCheck(wi::renderer::GetSurfelGIDebugEnabled()); - AddWidget(&surfelGIDebugCheckBox); + surfelGIDebugComboBox.Create(""); + surfelGIDebugComboBox.SetTooltip("Choose Surfel GI debug visualization."); + surfelGIDebugComboBox.SetPos(XMFLOAT2(x + 40, y)); + surfelGIDebugComboBox.SetSize(XMFLOAT2(80, itemheight)); + surfelGIDebugComboBox.AddItem("No Debug", SURFEL_DEBUG_NONE); + surfelGIDebugComboBox.AddItem("Normal", SURFEL_DEBUG_NORMAL); + surfelGIDebugComboBox.AddItem("Color", SURFEL_DEBUG_COLOR); + surfelGIDebugComboBox.AddItem("Point", SURFEL_DEBUG_POINT); + surfelGIDebugComboBox.AddItem("Random", SURFEL_DEBUG_RANDOM); + surfelGIDebugComboBox.AddItem("Heatmap", SURFEL_DEBUG_HEATMAP); + surfelGIDebugComboBox.AddItem("Inconsist.", SURFEL_DEBUG_INCONSISTENCY); + surfelGIDebugComboBox.OnSelect([](wi::gui::EventArgs args) { + wi::renderer::SetSurfelGIDebugEnabled((SURFEL_DEBUG)args.userdata); + }); + AddWidget(&surfelGIDebugComboBox); voxelRadianceCheckBox.Create("Voxel GI: "); voxelRadianceCheckBox.SetTooltip("Toggle voxel Global Illumination computation."); diff --git a/Editor/RendererWindow.h b/Editor/RendererWindow.h index e933792d0..9db94041c 100644 --- a/Editor/RendererWindow.h +++ b/Editor/RendererWindow.h @@ -28,7 +28,7 @@ public: wi::gui::CheckBox occlusionCullingCheckBox; wi::gui::Slider resolutionScaleSlider; wi::gui::CheckBox surfelGICheckBox; - wi::gui::CheckBox surfelGIDebugCheckBox; + wi::gui::ComboBox surfelGIDebugComboBox; wi::gui::CheckBox voxelRadianceCheckBox; wi::gui::CheckBox voxelRadianceDebugCheckBox; wi::gui::CheckBox voxelRadianceSecondaryBounceCheckBox; diff --git a/WickedEngine/shaders/ShaderInterop_SurfelGI.h b/WickedEngine/shaders/ShaderInterop_SurfelGI.h index 9e0d4cfe2..87e09ebf5 100644 --- a/WickedEngine/shaders/ShaderInterop_SurfelGI.h +++ b/WickedEngine/shaders/ShaderInterop_SurfelGI.h @@ -69,6 +69,23 @@ static const uint SURFEL_RAY_BOOST_MAX = 32; // max amount of rays per surfel #define SURFEL_ENABLE_INFINITE_BOUNCES // if defined, previous frame's surfel data will be sampled at ray tracing hit points #define SURFEL_ENABLE_IRRADIANCE_SHARING // if defined, surfels will pull color from nearby surfels, this can smooth out the GI a bit +enum SURFEL_DEBUG +{ + SURFEL_DEBUG_NONE, + SURFEL_DEBUG_NORMAL, + SURFEL_DEBUG_COLOR, + SURFEL_DEBUG_POINT, + SURFEL_DEBUG_RANDOM, + SURFEL_DEBUG_HEATMAP, + SURFEL_DEBUG_INCONSISTENCY, + + SURFEL_DEBUG_FORCE_UINT = 0xFFFFFFFF, +}; +struct SurfelDebugPushConstants +{ + SURFEL_DEBUG debug; +}; + #ifndef __cplusplus inline int3 surfel_cell(float3 position) { diff --git a/WickedEngine/shaders/surfel_coverageCS.hlsl b/WickedEngine/shaders/surfel_coverageCS.hlsl index ad3676d23..062fdd82e 100644 --- a/WickedEngine/shaders/surfel_coverageCS.hlsl +++ b/WickedEngine/shaders/surfel_coverageCS.hlsl @@ -2,13 +2,7 @@ #include "ShaderInterop_SurfelGI.h" #include "brdf.hlsli" -//#define SURFEL_DEBUG_NORMAL -//#define SURFEL_DEBUG_COLOR -#define SURFEL_DEBUG_POINT -//#define SURFEL_DEBUG_RANDOM -//#define SURFEL_DEBUG_HEATMAP -//#define SURFEL_DEBUG_INCONSISTENCY - +PUSHCONSTANT(push, SurfelDebugPushConstants); static const uint random_colors_size = 11; static const float3 random_colors[random_colors_size] = { @@ -149,25 +143,29 @@ void main(uint3 DTid : SV_DispatchThreadID, uint groupIndex : SV_GroupIndex, uin color += float4(surfel.color, 1) * contribution; -#ifdef SURFEL_DEBUG_NORMAL - debug.rgb += normal * contribution; - debug.a = 1; -#endif // SURFEL_DEBUG_NORMAL + if (push.debug == SURFEL_DEBUG_NORMAL) + { + debug.rgb += normal * contribution; + debug.a = 1; + } -#ifdef SURFEL_DEBUG_RANDOM - debug += float4(random_color(surfel_index), 1) * contribution; -#endif // SURFEL_DEBUG_RANDOM + if (push.debug == SURFEL_DEBUG_RANDOM) + { + debug += float4(random_color(surfel_index), 1) * contribution; + } -#ifdef SURFEL_DEBUG_INCONSISTENCY - debug += float4(surfelDataBuffer[surfel_index].inconsistency.xxx, 1) * contribution; -#endif // SURFEL_DEBUG_INCONSISTENCY + if (push.debug == SURFEL_DEBUG_INCONSISTENCY) + { + debug += float4(surfelDataBuffer[surfel_index].inconsistency.xxx, 1) * contribution; + } } -#ifdef SURFEL_DEBUG_POINT - if (dist2 <= sqr(0.05)) - debug = float4(1, 0, 1, 1); -#endif // SURFEL_DEBUG_POINT + if (push.debug == SURFEL_DEBUG_POINT) + { + if (dist2 <= sqr(0.05)) + debug = float4(1, 0, 1, 1); + } } } @@ -188,54 +186,59 @@ void main(uint3 DTid : SV_DispatchThreadID, uint groupIndex : SV_GroupIndex, uin color.a = saturate(color.a); } -#ifdef SURFEL_DEBUG_NORMAL - debug.rgb = normalize(debug.rgb) * 0.5 + 0.5; -#endif // SURFEL_DEBUG_NORMAL - -#ifdef SURFEL_DEBUG_COLOR - debug = color; - debug.rgb = tonemap(debug.rgb); -#endif // SURFEL_DEBUG_COLOR - -#if defined(SURFEL_DEBUG_RANDOM) - if (debug.a > 0) + if (push.debug == SURFEL_DEBUG_NORMAL) { - debug /= debug.a; + debug.rgb = normalize(debug.rgb) * 0.5 + 0.5; } - else - { - debug = 0; - } -#endif // SURFEL_DEBUG_RANDOM -#ifdef SURFEL_DEBUG_HEATMAP - const float3 mapTex[] = { - float3(0,0,0), - float3(0,0,1), - float3(0,1,1), - float3(0,1,0), - float3(1,1,0), - float3(1,0,0), - }; - const uint mapTexLen = 5; - const uint maxHeat = 50; - float l = saturate((float)cell.count / maxHeat) * mapTexLen; - float3 a = mapTex[floor(l)]; - float3 b = mapTex[ceil(l)]; - float4 heatmap = float4(lerp(a, b, l - floor(l)), 0.8); - debug = heatmap; -#endif // SURFEL_DEBUG_HEATMAP + if (push.debug == SURFEL_DEBUG_COLOR) + { + debug = color; + debug.rgb = tonemap(debug.rgb); + } -#if defined(SURFEL_DEBUG_INCONSISTENCY) - if (debug.a > 0) + if (push.debug == SURFEL_DEBUG_RANDOM) { - debug /= debug.a; + if (debug.a > 0) + { + debug /= debug.a; + } + else + { + debug = 0; + } } - else + + if (push.debug == SURFEL_DEBUG_HEATMAP) { - debug = 0; + const float3 mapTex[] = { + float3(0,0,0), + float3(0,0,1), + float3(0,1,1), + float3(0,1,0), + float3(1,1,0), + float3(1,0,0), + }; + const uint mapTexLen = 5; + const uint maxHeat = 50; + float l = saturate((float)cell.count / maxHeat) * mapTexLen; + float3 a = mapTex[floor(l)]; + float3 b = mapTex[ceil(l)]; + float4 heatmap = float4(lerp(a, b, l - floor(l)), 0.8); + debug = heatmap; + } + + if (push.debug == SURFEL_DEBUG_INCONSISTENCY) + { + if (debug.a > 0) + { + debug /= debug.a; + } + else + { + debug = 0; + } } -#endif // SURFEL_DEBUG_INCONSISTENCY GroupMemoryBarrierWithGroupSync(); diff --git a/WickedEngine/wiRenderer.cpp b/WickedEngine/wiRenderer.cpp index a9a41825d..79cfc1f76 100644 --- a/WickedEngine/wiRenderer.cpp +++ b/WickedEngine/wiRenderer.cpp @@ -24,7 +24,6 @@ #include "shaders/ShaderInterop_Postprocess.h" #include "shaders/ShaderInterop_Raytracing.h" #include "shaders/ShaderInterop_BVH.h" -#include "shaders/ShaderInterop_SurfelGI.h" #include #include @@ -97,7 +96,7 @@ bool disableAlbedoMaps = false; bool forceDiffuseLighting = false; bool SCREENSPACESHADOWS = false; bool SURFELGI = false; -bool SURFELGI_DEBUG = false; +SURFEL_DEBUG SURFELGI_DEBUG = SURFEL_DEBUG_NONE; struct VoxelizedSceneData @@ -7676,6 +7675,10 @@ void SurfelGI_Coverage( device->EventBegin("Coverage", cmd); device->BindComputeShader(&shaders[CSTYPE_SURFEL_COVERAGE], cmd); + SurfelDebugPushConstants push; + push.debug = GetSurfelGIDebugEnabled(); + device->PushConstants(&push, sizeof(push), cmd); + device->BindResource(&scene.surfelBuffer, 0, cmd); device->BindResource(&scene.surfelGridBuffer, 1, cmd); device->BindResource(&scene.surfelCellBuffer, 2, cmd); @@ -11823,11 +11826,11 @@ bool GetSurfelGIEnabled() { return SURFELGI; } -void SetSurfelGIDebugEnabled(bool value) +void SetSurfelGIDebugEnabled(SURFEL_DEBUG value) { SURFELGI_DEBUG = value; } -bool GetSurfelGIDebugEnabled() +SURFEL_DEBUG GetSurfelGIDebugEnabled() { return SURFELGI_DEBUG; } diff --git a/WickedEngine/wiRenderer.h b/WickedEngine/wiRenderer.h index 6496292be..9372b948a 100644 --- a/WickedEngine/wiRenderer.h +++ b/WickedEngine/wiRenderer.h @@ -8,6 +8,7 @@ #include "wiCanvas.h" #include "wiMath.h" #include "shaders/ShaderInterop_Renderer.h" +#include "shaders/ShaderInterop_SurfelGI.h" #include "wiVector.h" #include @@ -769,8 +770,8 @@ namespace wi::renderer bool GetScreenSpaceShadowsEnabled(); void SetSurfelGIEnabled(bool value); bool GetSurfelGIEnabled(); - void SetSurfelGIDebugEnabled(bool value); - bool GetSurfelGIDebugEnabled(); + void SetSurfelGIDebugEnabled(SURFEL_DEBUG value); + SURFEL_DEBUG GetSurfelGIDebugEnabled(); // Gets pick ray according to the current screen resolution and pointer coordinates. Can be used as input into RayIntersectWorld() wi::primitive::Ray GetPickRay(long cursorX, long cursorY, const wi::Canvas& canvas, const wi::scene::CameraComponent& camera = wi::scene::GetCamera());