From ac1db17e559c9037920c8bf341111152fc80d70e Mon Sep 17 00:00:00 2001 From: Antoine Pilote Date: Mon, 2 Oct 2023 17:39:17 -0400 Subject: [PATCH] added DOF UI --- Editor/src/Windows/EditorInterface.cpp | 176 ++++++++++++++++++ Editor/src/Windows/EditorInterface.h | 2 +- .../TrenchbroomConfiguratorWindow.cpp | 0 .../Windows}/TrenchbroomConfiguratorWindow.h | 0 Nuake/src/Rendering/SceneRenderer.cpp | 68 +++---- Nuake/src/Scene/Lighting/Environment.h | 19 ++ 6 files changed, 219 insertions(+), 46 deletions(-) rename Editor/{ => src/Windows}/TrenchbroomConfiguratorWindow.cpp (100%) rename Editor/{ => src/Windows}/TrenchbroomConfiguratorWindow.h (100%) diff --git a/Editor/src/Windows/EditorInterface.cpp b/Editor/src/Windows/EditorInterface.cpp index b7382655..8cca8793 100644 --- a/Editor/src/Windows/EditorInterface.cpp +++ b/Editor/src/Windows/EditorInterface.cpp @@ -1102,6 +1102,182 @@ namespace Nuake { ImGui::PopStyleColor(); } + { + ImGui::TableNextColumn(); + // Title + ImGui::Text("Focal Depth"); + ImGui::TableNextColumn(); + + ImGui::DragFloat("##doffocalDepth", &env->DOFFocalDepth); + ImGui::TableNextColumn(); + + // Reset button + ImGui::PushStyleColor(ImGuiCol_Button, ImVec4(1, 1, 1, 0)); + std::string resetdofFocalDepth = ICON_FA_UNDO + std::string("##resetdofFocalDepth"); + if (ImGui::Button(resetdofFocalDepth.c_str())) env->DOFFocalDepth = 1.0f; + ImGui::PopStyleColor(); + } + + { + ImGui::TableNextColumn(); + // Title + ImGui::Text("Focal Length"); + ImGui::TableNextColumn(); + + ImGui::DragFloat("##doffocalLength", &env->DOFFocalLength); + ImGui::TableNextColumn(); + + // Reset button + ImGui::PushStyleColor(ImGuiCol_Button, ImVec4(1, 1, 1, 0)); + std::string resetDOFFocalLength = ICON_FA_UNDO + std::string("##resetDOFFocalLength"); + if (ImGui::Button(resetDOFFocalLength.c_str())) env->DOFFocalLength = 1.0f; + ImGui::PopStyleColor(); + } + + { + ImGui::TableNextColumn(); + // Title + ImGui::Text("fStop"); + ImGui::TableNextColumn(); + + ImGui::DragFloat("##doffstop", &env->DOFFstop); + ImGui::TableNextColumn(); + + // Reset button + ImGui::PushStyleColor(ImGuiCol_Button, ImVec4(1, 1, 1, 0)); + std::string resetDOFFstop = ICON_FA_UNDO + std::string("##resetDOFFstop"); + if (ImGui::Button(resetDOFFstop.c_str())) env->DOFFstop = 1.0f; + ImGui::PopStyleColor(); + } + + { + ImGui::TableNextColumn(); + // Title + ImGui::Text("Auto focus"); + ImGui::TableNextColumn(); + + ImGui::Checkbox("##dofautofocus", &env->DOFAutoFocus); + ImGui::TableNextColumn(); + + // Reset button + ImGui::PushStyleColor(ImGuiCol_Button, ImVec4(1, 1, 1, 0)); + std::string resetDOFFstop = ICON_FA_UNDO + std::string("##resetdofautofocus"); + if (ImGui::Button(resetDOFFstop.c_str())) env->DOFAutoFocus = false; + ImGui::PopStyleColor(); + } + + { + ImGui::TableNextColumn(); + // Title + ImGui::Text("Display auto focus"); + ImGui::TableNextColumn(); + + ImGui::Checkbox("##dofshowautofocus", &env->DOFShowFocus); + ImGui::TableNextColumn(); + + // Reset button + ImGui::PushStyleColor(ImGuiCol_Button, ImVec4(1, 1, 1, 0)); + std::string resetDOFShowautofocus = ICON_FA_UNDO + std::string("##resetdofshowautofocus"); + if (ImGui::Button(resetDOFShowautofocus.c_str())) env->DOFShowFocus = false; + ImGui::PopStyleColor(); + } + + { + ImGui::TableNextColumn(); + // Title + ImGui::Text("Manual focus"); + ImGui::TableNextColumn(); + + ImGui::Checkbox("##dofmanualfocus", &env->DOFManualFocus); + ImGui::TableNextColumn(); + + // Reset button + ImGui::PushStyleColor(ImGuiCol_Button, ImVec4(1, 1, 1, 0)); + std::string resetDOFShowautofocus = ICON_FA_UNDO + std::string("##resetdofshowautofocus"); + if (ImGui::Button(resetDOFShowautofocus.c_str())) env->DOFShowFocus = false; + ImGui::PopStyleColor(); + } + + { + ImGui::TableNextColumn(); + // Title + ImGui::Text("fStop"); + ImGui::TableNextColumn(); + + ImGui::DragFloat("##doffstop", &env->DOFFstop); + ImGui::TableNextColumn(); + + // Reset button + ImGui::PushStyleColor(ImGuiCol_Button, ImVec4(1, 1, 1, 0)); + std::string resetDOFFstop = ICON_FA_UNDO + std::string("##resetDOFFstop"); + if (ImGui::Button(resetDOFFstop.c_str())) env->DOFFstop = 1.0f; + ImGui::PopStyleColor(); + } + + { + ImGui::TableNextColumn(); + // Title + ImGui::Text("DOF Start"); + ImGui::TableNextColumn(); + + ImGui::DragFloat("##dofstart", &env->DOFStart); + ImGui::TableNextColumn(); + + // Reset button + ImGui::PushStyleColor(ImGuiCol_Button, ImVec4(1, 1, 1, 0)); + std::string resetDOFFstop = ICON_FA_UNDO + std::string("##resetdofstartp"); + if (ImGui::Button(resetDOFFstop.c_str())) env->DOFStart = 1.0f; + ImGui::PopStyleColor(); + } + + { + ImGui::TableNextColumn(); + // Title + ImGui::Text("DOF Distance"); + ImGui::TableNextColumn(); + + ImGui::DragFloat("##dofdistance", &env->DOFDist); + ImGui::TableNextColumn(); + + // Reset button + ImGui::PushStyleColor(ImGuiCol_Button, ImVec4(1, 1, 1, 0)); + std::string resetDOFDist = ICON_FA_UNDO + std::string("##resetDOFDist"); + if (ImGui::Button(resetDOFDist.c_str())) env->DOFDist = 1.0f; + ImGui::PopStyleColor(); + } + + { + ImGui::TableNextColumn(); + // Title + ImGui::Text("DOF Threshold"); + ImGui::TableNextColumn(); + + ImGui::DragFloat("##dofthreshold", &env->DOFThreshold, 0.001f, 0.0f); + ImGui::TableNextColumn(); + + // Reset button + ImGui::PushStyleColor(ImGuiCol_Button, ImVec4(1, 1, 1, 0)); + std::string resetDOFDist = ICON_FA_UNDO + std::string("##resetDOFDist"); + if (ImGui::Button(resetDOFDist.c_str())) env->DOFDist = 1.0f; + ImGui::PopStyleColor(); + } + + { + ImGui::TableNextColumn(); + // Title + ImGui::Text("DOF Feather"); + ImGui::TableNextColumn(); + + ImGui::DragFloat("##doffeather", &env->DOFFeather, 0.001f, 0.0f, 1.0f); + ImGui::TableNextColumn(); + + // Reset button + ImGui::PushStyleColor(ImGuiCol_Button, ImVec4(1, 1, 1, 0)); + std::string resetDOFDist = ICON_FA_UNDO + std::string("##resetdoffeather"); + if (ImGui::Button(resetDOFDist.c_str())) env->DOFDist = 1.0f; + ImGui::PopStyleColor(); + } + ImGui::EndTable(); } END_COLLAPSE_HEADER() diff --git a/Editor/src/Windows/EditorInterface.h b/Editor/src/Windows/EditorInterface.h index c8d3bf9a..137f8def 100644 --- a/Editor/src/Windows/EditorInterface.h +++ b/Editor/src/Windows/EditorInterface.h @@ -9,7 +9,7 @@ #include "EditorSelectionPanel.h" #include "WelcomeWindow.h" #include "AudioWindow.h" -#include "../../TrenchbroomConfiguratorWindow.h" +#include "../Windows/TrenchbroomConfiguratorWindow.h" namespace Nuake { diff --git a/Editor/TrenchbroomConfiguratorWindow.cpp b/Editor/src/Windows/TrenchbroomConfiguratorWindow.cpp similarity index 100% rename from Editor/TrenchbroomConfiguratorWindow.cpp rename to Editor/src/Windows/TrenchbroomConfiguratorWindow.cpp diff --git a/Editor/TrenchbroomConfiguratorWindow.h b/Editor/src/Windows/TrenchbroomConfiguratorWindow.h similarity index 100% rename from Editor/TrenchbroomConfiguratorWindow.h rename to Editor/src/Windows/TrenchbroomConfiguratorWindow.h diff --git a/Nuake/src/Rendering/SceneRenderer.cpp b/Nuake/src/Rendering/SceneRenderer.cpp index 33d32177..490610da 100644 --- a/Nuake/src/Rendering/SceneRenderer.cpp +++ b/Nuake/src/Rendering/SceneRenderer.cpp @@ -142,8 +142,8 @@ namespace Nuake Shader* shader = ShaderManager::GetShader("Resources/Shaders/tonemap.shader"); shader->Bind(); - shader->SetUniform1f("u_Exposure", scene.GetEnvironment()->Exposure); - shader->SetUniform1f("u_Gamma", scene.GetEnvironment()->Gamma); + shader->SetUniform1f("u_Exposure", sceneEnv->Exposure); + shader->SetUniform1f("u_Gamma", sceneEnv->Gamma); shader->SetUniformTex("u_Source", finalOutput.get()); Renderer::DrawQuad(); } @@ -180,28 +180,6 @@ namespace Nuake framebuffer.Unbind(); } - static float focalDepth = 100.0f; - static float focalLength = 16.0f; - static float fstop = 6.0f; - static bool autoFocus = false; - static bool showFocus = false; - static bool manualdof = true; - static int samples = 3; - static int rings = 3; - static float ndofstart = 1.0f; - static float ndofDist = 2.0f; - static float fdofstart = 1.0f; - static float fdofdist = 3.0f; - static float coc = 0.03f; - static float maxBlue = 1.0f; - static float threshold = 0.7f; - static float gain = 100.0f; - static float biaos = 0.0f; - static float fringe = 0.0f; - static float nammount = 0.0001; - static float dbsize = 1.25f; - static float feather = 1.0f; - mDOFBuffer->QueueResize(framebuffer.GetSize()); mDOFBuffer->Bind(); { @@ -209,27 +187,27 @@ namespace Nuake Shader* shader = ShaderManager::GetShader("Resources/Shaders/dof.shader"); shader->Bind(); - shader->SetUniform1f("focalDepth", focalDepth); - shader->SetUniform1f("focalLength", focalLength); - shader->SetUniform1f("fstop", fstop); - shader->SetUniform1i("showFocus", showFocus); - shader->SetUniform1i("autofocus", autoFocus); - shader->SetUniform1i("samples", samples); - shader->SetUniform1i("manualdof", manualdof); - shader->SetUniform1f("rings", rings); - shader->SetUniform1f("ndofstart", ndofstart); - shader->SetUniform1f("ndofdist", ndofDist); - shader->SetUniform1f("fdofstart", fdofstart); - shader->SetUniform1f("fdofdist", fdofdist); - shader->SetUniform1f("CoC", coc); - shader->SetUniform1f("maxblur", maxBlue); - shader->SetUniform1f("threshold", threshold); - shader->SetUniform1f("gain", gain); - shader->SetUniform1f("bias", biaos); - shader->SetUniform1f("fringe", fringe); - shader->SetUniform1f("namount", nammount); - shader->SetUniform1f("dbsize", dbsize); - shader->SetUniform1f("feather", feather); + shader->SetUniform1f("focalDepth", sceneEnv->DOFFocalDepth); + shader->SetUniform1f("focalLength", sceneEnv->DOFFocalLength); + shader->SetUniform1f("fstop", sceneEnv->DOFFstop); + shader->SetUniform1i("showFocus", sceneEnv->DOFShowFocus); + shader->SetUniform1i("autofocus", sceneEnv->DOFAutoFocus); + shader->SetUniform1i("samples", sceneEnv->DOFSamples); + shader->SetUniform1i("manualdof", sceneEnv->DOFManualFocus); + shader->SetUniform1f("rings", sceneEnv->DOFrings); + shader->SetUniform1f("ndofstart", sceneEnv->DOFStart); + shader->SetUniform1f("ndofdist", sceneEnv->DOFDist); + shader->SetUniform1f("fdofstart", sceneEnv->DOFStart); + shader->SetUniform1f("fdofdist", sceneEnv->DOFDist); + shader->SetUniform1f("CoC", sceneEnv->DOFCoc); + shader->SetUniform1f("maxblur", sceneEnv->DOFMaxBlue); + shader->SetUniform1f("threshold", sceneEnv->DOFThreshold); + shader->SetUniform1f("gain", sceneEnv->DOFGain); + shader->SetUniform1f("bias", sceneEnv->DOFBias); + shader->SetUniform1f("fringe", sceneEnv->DOFFringe); + shader->SetUniform1f("namount", sceneEnv->DOFNAmmount); + shader->SetUniform1f("dbsize", sceneEnv->DOFDbSize); + shader->SetUniform1f("feather", sceneEnv->DOFFeather); shader->SetUniform1f("u_Distortion", sceneEnv->BarrelDistortion); shader->SetUniform1f("height", finalOutput->GetHeight()); shader->SetUniform1f("width", finalOutput->GetWidth()); diff --git a/Nuake/src/Scene/Lighting/Environment.h b/Nuake/src/Scene/Lighting/Environment.h index 0d81b1b4..7ea407f2 100644 --- a/Nuake/src/Scene/Lighting/Environment.h +++ b/Nuake/src/Scene/Lighting/Environment.h @@ -48,6 +48,25 @@ namespace Nuake Scope mSSR; bool DOFEnabled = false; + float DOFFocalDepth = 1.0f; + float DOFFocalLength = 16.0f; + float DOFFstop = 1.0f; + bool DOFAutoFocus = false; + bool DOFShowFocus = false; + bool DOFManualFocus = false; + int DOFSamples = 3; + int DOFrings = 3; + float DOFStart = 1.0f; + float DOFDist = 3.0f; + float DOFCoc = 0.03f; + float DOFMaxBlue = 1.0f; + float DOFThreshold = 1.0f; + float DOFGain = 100.f; + float DOFBias = 0.0f; + float DOFFringe = 0.0f; + float DOFNAmmount = 0.0001; + float DOFDbSize = 1.25f; + float DOFFeather = 1.0f; bool BarrelDistortionEnabled = true; float BarrelDistortion = 0.f;