From eb3277093f46f185083bf6588efd4fe13e38c208 Mon Sep 17 00:00:00 2001 From: AdamYuan Date: Fri, 6 Aug 2021 19:43:00 +0800 Subject: [PATCH] Improve UI --- CMakeLists.txt | 4 ++-- README.md | 8 ++++++++ src/Application.cpp | 12 ++++++------ src/Camera.cpp | 4 ++-- src/Camera.hpp | 5 ++--- src/{UIHelper.cpp => ImGuiUtil.cpp} | 4 ++-- src/{UIHelper.hpp => ImGuiUtil.hpp} | 6 +++--- src/PathTracerViewer.cpp | 4 +++- src/UICamera.cpp | 12 +++++++----- src/UILighting.cpp | 20 ++++++++++---------- src/UILighting.hpp | 2 +- src/UILoader.cpp | 10 +++++----- src/UILog.cpp | 9 +++++++-- src/UILog.hpp | 3 ++- src/UIOctreeTracer.cpp | 4 +++- src/UIPathTracer.cpp | 10 +++++----- 16 files changed, 68 insertions(+), 49 deletions(-) rename src/{UIHelper.cpp => ImGuiUtil.cpp} (99%) rename src/{UIHelper.hpp => ImGuiUtil.hpp} (93%) diff --git a/CMakeLists.txt b/CMakeLists.txt index 1aa1d77..8aaaece 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -59,8 +59,8 @@ add_executable(SparseVoxelOctree src/PathTracerThread.hpp src/Lighting.cpp src/Lighting.hpp - src/UIHelper.cpp - src/UIHelper.hpp + src/ImGuiUtil.cpp + src/ImGuiUtil.hpp src/UILog.cpp src/UILog.hpp src/UICamera.cpp diff --git a/README.md b/README.md index 680db4f..4710ab6 100644 --- a/README.md +++ b/README.md @@ -26,6 +26,14 @@ make * [spdlog](https://github.com/gabime/spdlog) - Logging system * [FontAwesome](https://fontawesome.com/) - Icon font +## Usage +* **Camera** + * **W A S D** - move around (horizontally) + * **SPACE** - go up + * **LSHIFT** - go down + * **Drag** - change perspective +* **X** - toggle ui display + ## Improvements The new Vulkan version is much faster than the old OpenGL version, given the comparison below: #### GTX 1660 Ti diff --git a/src/Application.cpp b/src/Application.cpp index 47800c0..312c62f 100644 --- a/src/Application.cpp +++ b/src/Application.cpp @@ -7,8 +7,8 @@ #include #include +#include "ImGuiUtil.hpp" #include "UICamera.hpp" -#include "UIHelper.hpp" #include "UILighting.hpp" #include "UILoader.hpp" #include "UILog.hpp" @@ -46,8 +46,8 @@ void Application::create_window() { IMGUI_CHECKVERSION(); ImGui::CreateContext(); - UI::LoadFontAwesome(); - UI::StyleCinder(); + ImGui::LoadFontAwesome(); + ImGui::StyleCinder(); ImGui_ImplGlfw_InitForVulkan(m_window, true); } @@ -308,7 +308,7 @@ void Application::initialize_vulkan() { Application::Application() { m_log_sink = std::make_shared(kLogLimit); - m_log_sink->set_pattern("%H:%M:%S.%e"); // only display time + UI::LogSetRequiredPattern(m_log_sink); spdlog::default_logger()->sinks().push_back(m_log_sink); create_window(); @@ -426,10 +426,10 @@ void Application::ui_menubar() { else if (m_ui_state == UIStates::kOctreeTracer) { UI::OctreeTracerMenuItems(m_octree_tracer); UI::CameraMenuItems(m_camera); - UI::LightingMenuItem(m_main_command_pool, m_lighting, &open_modal); + UI::LightingMenuItems(m_main_command_pool, m_lighting, &open_modal); } - UI::LogMenuItem(m_log_sink); + UI::LogMenuItems(m_log_sink); // Status bar if (m_ui_state == UIStates::kOctreeTracer) diff --git a/src/Camera.cpp b/src/Camera.cpp index daef961..17ae89d 100644 --- a/src/Camera.cpp +++ b/src/Camera.cpp @@ -59,8 +59,8 @@ void Camera::Control(GLFWwindow *window, float delta) { if (glfwGetMouseButton(window, GLFW_MOUSE_BUTTON_LEFT)) { glfwGetCursorPos(window, &cur_pos.x, &cur_pos.y); - float offset_x = float(cur_pos.x - m_last_mouse_pos.x) * m_sensitive; - float offset_y = float(cur_pos.y - m_last_mouse_pos.y) * m_sensitive; + float offset_x = float(cur_pos.x - m_last_mouse_pos.x) * m_sensitivity; + float offset_y = float(cur_pos.y - m_last_mouse_pos.y) * m_sensitivity; m_yaw -= offset_x; m_pitch -= offset_y; diff --git a/src/Camera.hpp b/src/Camera.hpp index 6195de0..81b1c8f 100644 --- a/src/Camera.hpp +++ b/src/Camera.hpp @@ -14,9 +14,8 @@ struct GLFWwindow; class Camera { public: glm::vec3 m_position{0.0f, 0.0f, 0.0f}; - float m_yaw{0.0f}, m_pitch{0.0f}; - float m_sensitive{0.005f}, m_speed{0.0625f}, m_fov{PIF / 3.0f}, - m_aspect_ratio{float(kDefaultWidth) / float(kDefaultHeight)}; + float m_yaw{0.0f}, m_pitch{0.0f}, m_fov{PIF / 3.0f}, m_aspect_ratio{float(kDefaultWidth) / float(kDefaultHeight)}; + float m_sensitivity{0.005f}, m_speed{0.0625f}; private: glm::dvec2 m_last_mouse_pos{0.0, 0.0}; diff --git a/src/UIHelper.cpp b/src/ImGuiUtil.cpp similarity index 99% rename from src/UIHelper.cpp rename to src/ImGuiUtil.cpp index 68fbeb3..972acf2 100644 --- a/src/UIHelper.cpp +++ b/src/ImGuiUtil.cpp @@ -1,11 +1,11 @@ -#include "UIHelper.hpp" +#include "ImGuiUtil.hpp" #include #include #include #include -namespace UI { +namespace ImGui { void LoadFontAwesome() { ImGuiIO &io = ImGui::GetIO(); io.Fonts->AddFontDefault(); diff --git a/src/UIHelper.hpp b/src/ImGuiUtil.hpp similarity index 93% rename from src/UIHelper.hpp rename to src/ImGuiUtil.hpp index 38baed9..a16636a 100644 --- a/src/UIHelper.hpp +++ b/src/ImGuiUtil.hpp @@ -1,9 +1,9 @@ -#ifndef IMGUI_HELPER_HPP -#define IMGUI_HELPER_HPP +#ifndef IMGUI_UTIL_HPP +#define IMGUI_UTIL_HPP #include -namespace UI { +namespace ImGui { void LoadFontAwesome(); bool Spinner(const char *label, float radius, int thickness, const ImU32 &color); void StyleCinder(ImGuiStyle *dst = nullptr); diff --git a/src/PathTracerViewer.cpp b/src/PathTracerViewer.cpp index c483c05..65cb2c7 100644 --- a/src/PathTracerViewer.cpp +++ b/src/PathTracerViewer.cpp @@ -1,5 +1,5 @@ -#include "Config.hpp" #include "PathTracerViewer.hpp" +#include "Config.hpp" #include "QuadSpirv.hpp" #include @@ -267,6 +267,8 @@ std::shared_ptr PathTracerViewer::Create(const std::shared_ptr } void PathTracerViewer::Reset(const std::shared_ptr &command_pool) { + m_view_type = ViewTypes::kColor; + m_image = myvk::Image::CreateTexture2D( m_gen_render_pass->GetDevicePtr(), {m_path_tracer_ptr->m_width, m_path_tracer_ptr->m_height}, 1, VK_FORMAT_R8G8B8A8_UNORM, diff --git a/src/UICamera.cpp b/src/UICamera.cpp index 0f5b8e1..a213455 100644 --- a/src/UICamera.cpp +++ b/src/UICamera.cpp @@ -1,15 +1,17 @@ #include "UICamera.hpp" -#include "UIHelper.hpp" +#include "ImGuiUtil.hpp" namespace UI { void CameraMenuItems(const std::shared_ptr &camera) { if (ImGui::BeginMenu("Camera")) { - UI::DragAngle("FOV", &camera->m_fov, 1, 10, 179); - ImGui::DragFloat("Speed", &camera->m_speed, 0.005f, 0.005f, 0.2f); + ImGui::DragAngle("FOV", &camera->m_fov, 1, 10, 179); ImGui::InputFloat3("Position", &camera->m_position[0]); - UI::DragAngle("Yaw", &camera->m_yaw, 1, 0, 360); - UI::DragAngle("Pitch", &camera->m_pitch, 1, -90, 90); + ImGui::DragAngle("Yaw", &camera->m_yaw, 1, 0, 360); + ImGui::DragAngle("Pitch", &camera->m_pitch, 1, -90, 90); + ImGui::Separator(); + ImGui::DragFloat("Speed", &camera->m_speed, 0.005f, 0.005f, 0.2f); + ImGui::DragFloat("Sensitivity", &camera->m_sensitivity, 0.001f, 0.001f, 0.02f); ImGui::EndMenu(); } } diff --git a/src/UILighting.cpp b/src/UILighting.cpp index 9edb8a2..00c5617 100644 --- a/src/UILighting.cpp +++ b/src/UILighting.cpp @@ -1,13 +1,13 @@ #include "UILighting.hpp" #include "Config.hpp" -#include "UIHelper.hpp" +#include "ImGuiUtil.hpp" #include namespace UI { -void LightingMenuItem(const std::shared_ptr &command_pool, const std::shared_ptr &lighting, - const char **open_modal) { +void LightingMenuItems(const std::shared_ptr &command_pool, + const std::shared_ptr &lighting, const char **open_modal) { if (ImGui::BeginMenu("Light")) { auto type = lighting->m_light_type; bool active; @@ -18,10 +18,10 @@ void LightingMenuItem(const std::shared_ptr &command_pool, co lighting->m_light_type = Lighting::LightTypes::kConstantColor; if (!active) - UI::PushDisabled(); + ImGui::PushDisabled(); ImGui::DragFloat3("", &lighting->m_sun_radiance[0], 0.1f, 0.0f, kMaxConstantColor); if (!active) - UI::PopDisabled(); + ImGui::PopDisabled(); } ImGui::Separator(); @@ -32,7 +32,7 @@ void LightingMenuItem(const std::shared_ptr &command_pool, co lighting->m_light_type = Lighting::LightTypes::kEnvironmentMap; if (!active) - UI::PushDisabled(); + ImGui::PushDisabled(); if (ImGui::Button("Load")) *open_modal = kLightingLoadEnvMapModal; if (!lighting->GetEnvironmentMapPtr()->Empty()) { @@ -49,9 +49,9 @@ void LightingMenuItem(const std::shared_ptr &command_pool, co ImGui::InputFloat("Multiplier", &lighting->GetEnvironmentMapPtr()->m_multiplier); if (lighting->GetEnvironmentMapPtr()->m_multiplier < 0.0f) lighting->GetEnvironmentMapPtr()->m_multiplier = 0.0f; - UI::DragAngle("Rotation", &lighting->GetEnvironmentMapPtr()->m_rotation, 1, 0, 360); + ImGui::DragAngle("Rotation", &lighting->GetEnvironmentMapPtr()->m_rotation, 1, 0, 360); if (!active) - UI::PopDisabled(); + ImGui::PopDisabled(); } ImGui::EndMenu(); @@ -59,7 +59,7 @@ void LightingMenuItem(const std::shared_ptr &command_pool, co } void LightingLoadEnvMapModal(const std::shared_ptr &command_pool, const std::shared_ptr &lighting) { - UI::SetNextWindowCentering(); + ImGui::SetNextWindowCentering(); if (ImGui::BeginPopupModal(kLightingLoadEnvMapModal, nullptr, ImGuiWindowFlags_AlwaysAutoResize | ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoMove)) { @@ -67,7 +67,7 @@ void LightingLoadEnvMapModal(const std::shared_ptr &command_p constexpr const char *kFilter[] = {"*.hdr", "*.exr"}; - UI::FileOpen("Env Map Filename", "...", name_buf, kFilenameBufSize, "Environment Map Filename", 2, kFilter); + ImGui::FileOpen("Env Map Filename", "...", name_buf, kFilenameBufSize, "Environment Map Filename", 2, kFilter); float button_width = (ImGui::GetWindowContentRegionWidth() - ImGui::GetStyle().ItemSpacing.x) * 0.5f; diff --git a/src/UILighting.hpp b/src/UILighting.hpp index 48732db..d798b1c 100644 --- a/src/UILighting.hpp +++ b/src/UILighting.hpp @@ -6,7 +6,7 @@ namespace UI { constexpr const char *kLightingLoadEnvMapModal = "Load Environment Map"; -void LightingMenuItem(const std::shared_ptr &command_pool, const std::shared_ptr &lighting, +void LightingMenuItems(const std::shared_ptr &command_pool, const std::shared_ptr &lighting, const char **open_modal); void LightingLoadEnvMapModal(const std::shared_ptr &command_pool, diff --git a/src/UILoader.cpp b/src/UILoader.cpp index 93b8fc4..71b8969 100644 --- a/src/UILoader.cpp +++ b/src/UILoader.cpp @@ -1,7 +1,7 @@ #include "UILoader.hpp" #include "Config.hpp" -#include "UIHelper.hpp" +#include "ImGuiUtil.hpp" #include #include @@ -17,7 +17,7 @@ void LoaderLoadButton(const std::shared_ptr &loader_thread, const } } void LoaderLoadSceneModal(const std::shared_ptr &loader_thread) { - UI::SetNextWindowCentering(); + ImGui::SetNextWindowCentering(); if (ImGui::BeginPopupModal(kLoaderLoadSceneModal, nullptr, ImGuiWindowFlags_AlwaysAutoResize | ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoMove)) { @@ -26,7 +26,7 @@ void LoaderLoadSceneModal(const std::shared_ptr &loader_thread) { constexpr const char *kFilter[] = {"*.obj"}; - UI::FileOpen("OBJ Filename", "...", name_buf, kFilenameBufSize, "OBJ Filename", 1, kFilter); + ImGui::FileOpen("OBJ Filename", "...", name_buf, kFilenameBufSize, "OBJ Filename", 1, kFilter); ImGui::DragInt("Octree Level", &octree_leve, 1, kOctreeLevelMin, kOctreeLevelMax); float button_width = (ImGui::GetWindowContentRegionWidth() - ImGui::GetStyle().ItemSpacing.x) * 0.5f; @@ -44,11 +44,11 @@ void LoaderLoadSceneModal(const std::shared_ptr &loader_thread) { } } void LoaderLoadingModal(const std::shared_ptr &loader_thread) { - UI::SetNextWindowCentering(); + ImGui::SetNextWindowCentering(); if (ImGui::BeginPopupModal(kLoaderLoadingModal, nullptr, ImGuiWindowFlags_AlwaysAutoResize | ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoMove)) { - UI::Spinner("##spinner", 12, 6, ImGui::GetColorU32(ImGuiCol_ButtonHovered)); + ImGui::Spinner("##spinner", 12, 6, ImGui::GetColorU32(ImGuiCol_ButtonHovered)); ImGui::SameLine(); ImGui::TextUnformatted(loader_thread->GetNotification()); diff --git a/src/UILog.cpp b/src/UILog.cpp index e15a3f5..cee2e17 100644 --- a/src/UILog.cpp +++ b/src/UILog.cpp @@ -5,7 +5,11 @@ #include namespace UI { -void LogMenuItem(const std::shared_ptr &log_sink) { +void LogSetRequiredPattern(const std::shared_ptr &log_sink) { + log_sink->set_pattern("%H:%M:%S.%e"); // only display time +} + +void LogMenuItems(const std::shared_ptr &log_sink) { if (ImGui::BeginMenu("Log")) { const auto &logs_raw = log_sink->last_raw(); const auto &logs_time = log_sink->last_formatted(); @@ -17,7 +21,8 @@ void LogMenuItem(const std::shared_ptr &log_s ImGuiTableFlags flags = ImGuiTableFlags_SizingFixedFit | ImGuiTableFlags_ScrollX | ImGuiTableFlags_ScrollY | ImGuiTableFlags_RowBg; - if (ImGui::BeginTable("Log Table", 4, flags, {ImGui::GetIO().DisplaySize.x * 0.5f, ImGui::GetIO().DisplaySize.y * 0.5f})) { + if (ImGui::BeginTable("Log Table", 4, flags, + {ImGui::GetIO().DisplaySize.x * 0.5f, ImGui::GetIO().DisplaySize.y * 0.5f})) { if (ImGui::IsMouseReleased(1)) ImGui::OpenPopup("Filter"); if (ImGui::BeginPopup("Filter")) { diff --git a/src/UILog.hpp b/src/UILog.hpp index 9a9e4cb..a5aa4fa 100644 --- a/src/UILog.hpp +++ b/src/UILog.hpp @@ -4,7 +4,8 @@ #include namespace UI { -void LogMenuItem(const std::shared_ptr &log_sink); +void LogSetRequiredPattern(const std::shared_ptr &log_sink); +void LogMenuItems(const std::shared_ptr &log_sink); } // namespace UI #endif diff --git a/src/UIOctreeTracer.cpp b/src/UIOctreeTracer.cpp index a0419af..db49e49 100644 --- a/src/UIOctreeTracer.cpp +++ b/src/UIOctreeTracer.cpp @@ -1,6 +1,6 @@ #include "UIOctreeTracer.hpp" -#include "UIHelper.hpp" +#include "ImGuiUtil.hpp" #include namespace UI { @@ -13,6 +13,8 @@ void OctreeTracerMenuItems(const std::shared_ptr &octree_tracer) { if (ImGui::MenuItem("Iterations", nullptr, octree_tracer->m_view_type == OctreeTracer::ViewTypes::kIteration)) octree_tracer->m_view_type = OctreeTracer::ViewTypes::kIteration; + ImGui::Separator(); + ImGui::Checkbox("Beam Optimization", &octree_tracer->m_beam_enable); ImGui::EndMenu(); } diff --git a/src/UIPathTracer.cpp b/src/UIPathTracer.cpp index af81ee6..4b2d7f0 100644 --- a/src/UIPathTracer.cpp +++ b/src/UIPathTracer.cpp @@ -1,7 +1,7 @@ #include "UIPathTracer.hpp" #include "Config.hpp" -#include "UIHelper.hpp" +#include "ImGuiUtil.hpp" #include #include #include @@ -140,7 +140,7 @@ void PathTracerRightStatus(const std::shared_ptr &path_tracer_ } } void PathTracerStartModal(const std::shared_ptr &path_tracer_thread) { - UI::SetNextWindowCentering(); + ImGui::SetNextWindowCentering(); if (ImGui::BeginPopupModal(kPathTracerStartModal, nullptr, ImGuiWindowFlags_AlwaysAutoResize | ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoMove)) { @@ -177,7 +177,7 @@ void PathTracerStartModal(const std::shared_ptr &path_tracer_t } } void PathTracerStopModal(const std::shared_ptr &path_tracer_thread) { - UI::SetNextWindowCentering(); + ImGui::SetNextWindowCentering(); if (ImGui::BeginPopupModal(kPathTracerStopModal, nullptr, ImGuiWindowFlags_AlwaysAutoResize | ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoMove)) { @@ -198,7 +198,7 @@ void PathTracerStopModal(const std::shared_ptr &path_tracer_th } } void PathTracerExportEXRModal(const std::shared_ptr &path_tracer_thread) { - UI::SetNextWindowCentering(); + ImGui::SetNextWindowCentering(); if (ImGui::BeginPopupModal(kPathTracerExportEXRModal, nullptr, ImGuiWindowFlags_AlwaysAutoResize | ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoMove)) { @@ -221,7 +221,7 @@ void PathTracerExportEXRModal(const std::shared_ptr &path_trac static bool save_as_fp16{false}; constexpr const char *kFilter[] = {"*.exr"}; - UI::FileSave("OpenEXR Filename", "...", exr_name_buf, kFilenameBufSize, "Export OpenEXR", 1, kFilter); + ImGui::FileSave("OpenEXR Filename", "...", exr_name_buf, kFilenameBufSize, "Export OpenEXR", 1, kFilter); ImGui::Checkbox("Export as FP16", &save_as_fp16);