Skip to content

Commit

Permalink
Improve UI
Browse files Browse the repository at this point in the history
  • Loading branch information
AdamYuan committed Aug 6, 2021
1 parent 407325a commit eb32770
Show file tree
Hide file tree
Showing 16 changed files with 68 additions and 49 deletions.
4 changes: 2 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 6 additions & 6 deletions src/Application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
#include <imgui/imgui_impl_glfw.h>
#include <imgui/imgui_internal.h>

#include "ImGuiUtil.hpp"
#include "UICamera.hpp"
#include "UIHelper.hpp"
#include "UILighting.hpp"
#include "UILoader.hpp"
#include "UILog.hpp"
Expand Down Expand Up @@ -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);
}

Expand Down Expand Up @@ -308,7 +308,7 @@ void Application::initialize_vulkan() {

Application::Application() {
m_log_sink = std::make_shared<spdlog::sinks::ringbuffer_sink_mt>(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();
Expand Down Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions src/Camera.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
5 changes: 2 additions & 3 deletions src/Camera.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down
4 changes: 2 additions & 2 deletions src/UIHelper.cpp → src/ImGuiUtil.cpp
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
#include "UIHelper.hpp"
#include "ImGuiUtil.hpp"

#include <font-awesome/IconsFontAwesome5.h>
#include <font-awesome/fa_solid_900.inl>
#include <imgui/imgui_internal.h>
#include <tinyfiledialogs.h>

namespace UI {
namespace ImGui {
void LoadFontAwesome() {
ImGuiIO &io = ImGui::GetIO();
io.Fonts->AddFontDefault();
Expand Down
6 changes: 3 additions & 3 deletions src/UIHelper.hpp → src/ImGuiUtil.hpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
#ifndef IMGUI_HELPER_HPP
#define IMGUI_HELPER_HPP
#ifndef IMGUI_UTIL_HPP
#define IMGUI_UTIL_HPP

#include <imgui/imgui.h>

namespace UI {
namespace ImGui {
void LoadFontAwesome();
bool Spinner(const char *label, float radius, int thickness, const ImU32 &color);
void StyleCinder(ImGuiStyle *dst = nullptr);
Expand Down
4 changes: 3 additions & 1 deletion src/PathTracerViewer.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#include "Config.hpp"
#include "PathTracerViewer.hpp"
#include "Config.hpp"
#include "QuadSpirv.hpp"

#include <spdlog/spdlog.h>
Expand Down Expand Up @@ -267,6 +267,8 @@ std::shared_ptr<PathTracerViewer> PathTracerViewer::Create(const std::shared_ptr
}

void PathTracerViewer::Reset(const std::shared_ptr<myvk::CommandPool> &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,
Expand Down
12 changes: 7 additions & 5 deletions src/UICamera.cpp
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
#include "UICamera.hpp"

#include "UIHelper.hpp"
#include "ImGuiUtil.hpp"

namespace UI {
void CameraMenuItems(const std::shared_ptr<Camera> &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();
}
}
Expand Down
20 changes: 10 additions & 10 deletions src/UILighting.cpp
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
#include "UILighting.hpp"

#include "Config.hpp"
#include "UIHelper.hpp"
#include "ImGuiUtil.hpp"

#include <imgui/imgui.h>

namespace UI {
void LightingMenuItem(const std::shared_ptr<myvk::CommandPool> &command_pool, const std::shared_ptr<Lighting> &lighting,
const char **open_modal) {
void LightingMenuItems(const std::shared_ptr<myvk::CommandPool> &command_pool,
const std::shared_ptr<Lighting> &lighting, const char **open_modal) {
if (ImGui::BeginMenu("Light")) {
auto type = lighting->m_light_type;
bool active;
Expand All @@ -18,10 +18,10 @@ void LightingMenuItem(const std::shared_ptr<myvk::CommandPool> &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();
Expand All @@ -32,7 +32,7 @@ void LightingMenuItem(const std::shared_ptr<myvk::CommandPool> &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()) {
Expand All @@ -49,25 +49,25 @@ void LightingMenuItem(const std::shared_ptr<myvk::CommandPool> &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();
}
}
void LightingLoadEnvMapModal(const std::shared_ptr<myvk::CommandPool> &command_pool,
const std::shared_ptr<Lighting> &lighting) {
UI::SetNextWindowCentering();
ImGui::SetNextWindowCentering();
if (ImGui::BeginPopupModal(kLightingLoadEnvMapModal, nullptr,
ImGuiWindowFlags_AlwaysAutoResize | ImGuiWindowFlags_NoTitleBar |
ImGuiWindowFlags_NoMove)) {
static char name_buf[kFilenameBufSize];

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;

Expand Down
2 changes: 1 addition & 1 deletion src/UILighting.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
namespace UI {
constexpr const char *kLightingLoadEnvMapModal = "Load Environment Map";

void LightingMenuItem(const std::shared_ptr<myvk::CommandPool> &command_pool, const std::shared_ptr<Lighting> &lighting,
void LightingMenuItems(const std::shared_ptr<myvk::CommandPool> &command_pool, const std::shared_ptr<Lighting> &lighting,
const char **open_modal);

void LightingLoadEnvMapModal(const std::shared_ptr<myvk::CommandPool> &command_pool,
Expand Down
10 changes: 5 additions & 5 deletions src/UILoader.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#include "UILoader.hpp"

#include "Config.hpp"
#include "UIHelper.hpp"
#include "ImGuiUtil.hpp"
#include <font-awesome/IconsFontAwesome5.h>
#include <imgui/imgui.h>

Expand All @@ -17,7 +17,7 @@ void LoaderLoadButton(const std::shared_ptr<LoaderThread> &loader_thread, const
}
}
void LoaderLoadSceneModal(const std::shared_ptr<LoaderThread> &loader_thread) {
UI::SetNextWindowCentering();
ImGui::SetNextWindowCentering();
if (ImGui::BeginPopupModal(kLoaderLoadSceneModal, nullptr,
ImGuiWindowFlags_AlwaysAutoResize | ImGuiWindowFlags_NoTitleBar |
ImGuiWindowFlags_NoMove)) {
Expand All @@ -26,7 +26,7 @@ void LoaderLoadSceneModal(const std::shared_ptr<LoaderThread> &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;
Expand All @@ -44,11 +44,11 @@ void LoaderLoadSceneModal(const std::shared_ptr<LoaderThread> &loader_thread) {
}
}
void LoaderLoadingModal(const std::shared_ptr<LoaderThread> &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());

Expand Down
9 changes: 7 additions & 2 deletions src/UILog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@
#include <imgui/imgui.h>

namespace UI {
void LogMenuItem(const std::shared_ptr<spdlog::sinks::ringbuffer_sink_mt> &log_sink) {
void LogSetRequiredPattern(const std::shared_ptr<spdlog::sinks::ringbuffer_sink_mt> &log_sink) {
log_sink->set_pattern("%H:%M:%S.%e"); // only display time
}

void LogMenuItems(const std::shared_ptr<spdlog::sinks::ringbuffer_sink_mt> &log_sink) {
if (ImGui::BeginMenu("Log")) {
const auto &logs_raw = log_sink->last_raw();
const auto &logs_time = log_sink->last_formatted();
Expand All @@ -17,7 +21,8 @@ void LogMenuItem(const std::shared_ptr<spdlog::sinks::ringbuffer_sink_mt> &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")) {
Expand Down
3 changes: 2 additions & 1 deletion src/UILog.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
#include <spdlog/sinks/ringbuffer_sink.h>

namespace UI {
void LogMenuItem(const std::shared_ptr<spdlog::sinks::ringbuffer_sink_mt> &log_sink);
void LogSetRequiredPattern(const std::shared_ptr<spdlog::sinks::ringbuffer_sink_mt> &log_sink);
void LogMenuItems(const std::shared_ptr<spdlog::sinks::ringbuffer_sink_mt> &log_sink);
} // namespace UI

#endif
4 changes: 3 additions & 1 deletion src/UIOctreeTracer.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include "UIOctreeTracer.hpp"

#include "UIHelper.hpp"
#include "ImGuiUtil.hpp"
#include <font-awesome/IconsFontAwesome5.h>

namespace UI {
Expand All @@ -13,6 +13,8 @@ void OctreeTracerMenuItems(const std::shared_ptr<OctreeTracer> &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();
}
Expand Down
10 changes: 5 additions & 5 deletions src/UIPathTracer.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#include "UIPathTracer.hpp"

#include "Config.hpp"
#include "UIHelper.hpp"
#include "ImGuiUtil.hpp"
#include <font-awesome/IconsFontAwesome5.h>
#include <imgui/imgui.h>
#include <imgui/imgui_internal.h>
Expand Down Expand Up @@ -140,7 +140,7 @@ void PathTracerRightStatus(const std::shared_ptr<PathTracerThread> &path_tracer_
}
}
void PathTracerStartModal(const std::shared_ptr<PathTracerThread> &path_tracer_thread) {
UI::SetNextWindowCentering();
ImGui::SetNextWindowCentering();
if (ImGui::BeginPopupModal(kPathTracerStartModal, nullptr,
ImGuiWindowFlags_AlwaysAutoResize | ImGuiWindowFlags_NoTitleBar |
ImGuiWindowFlags_NoMove)) {
Expand Down Expand Up @@ -177,7 +177,7 @@ void PathTracerStartModal(const std::shared_ptr<PathTracerThread> &path_tracer_t
}
}
void PathTracerStopModal(const std::shared_ptr<PathTracerThread> &path_tracer_thread) {
UI::SetNextWindowCentering();
ImGui::SetNextWindowCentering();
if (ImGui::BeginPopupModal(kPathTracerStopModal, nullptr,
ImGuiWindowFlags_AlwaysAutoResize | ImGuiWindowFlags_NoTitleBar |
ImGuiWindowFlags_NoMove)) {
Expand All @@ -198,7 +198,7 @@ void PathTracerStopModal(const std::shared_ptr<PathTracerThread> &path_tracer_th
}
}
void PathTracerExportEXRModal(const std::shared_ptr<PathTracerThread> &path_tracer_thread) {
UI::SetNextWindowCentering();
ImGui::SetNextWindowCentering();
if (ImGui::BeginPopupModal(kPathTracerExportEXRModal, nullptr,
ImGuiWindowFlags_AlwaysAutoResize | ImGuiWindowFlags_NoTitleBar |
ImGuiWindowFlags_NoMove)) {
Expand All @@ -221,7 +221,7 @@ void PathTracerExportEXRModal(const std::shared_ptr<PathTracerThread> &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);

Expand Down

0 comments on commit eb32770

Please sign in to comment.