aboutsummaryrefslogtreecommitdiff
path: root/src/ui/ui_layer.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/ui/ui_layer.cpp')
-rw-r--r--src/ui/ui_layer.cpp275
1 files changed, 275 insertions, 0 deletions
diff --git a/src/ui/ui_layer.cpp b/src/ui/ui_layer.cpp
new file mode 100644
index 0000000..6748be2
--- /dev/null
+++ b/src/ui/ui_layer.cpp
@@ -0,0 +1,275 @@
+#include "ui_layer.h"
+
+#include "scene/scene.h"
+#include "core/settings_manager.h"
+#include "core/hdri_manager.h"
+#include "rendering/render_api.h"
+
+#include <imgui.h>
+#include <glm/glm.hpp>
+#include <string>
+
+namespace Donut
+{
+ // One-time ImGui theme: rounded, roomy, dark with a warm accretion-disk accent.
+ static auto apply_donut_style() -> void
+ {
+ ImGuiStyle& s = ImGui::GetStyle();
+ s.WindowRounding = 7.0f; s.ChildRounding = 5.0f; s.FrameRounding = 4.0f;
+ s.GrabRounding = 4.0f; s.PopupRounding = 4.0f; s.ScrollbarRounding = 5.0f; s.TabRounding = 4.0f;
+ s.WindowPadding = ImVec2(12, 12); s.FramePadding = ImVec2(9, 5);
+ s.ItemSpacing = ImVec2(9, 8); s.ItemInnerSpacing = ImVec2(7, 5);
+ s.WindowBorderSize = 0.0f; s.FrameBorderSize = 0.0f; s.WindowTitleAlign = ImVec2(0.02f, 0.5f);
+
+ const ImVec4 amber = ImVec4(0.98f, 0.62f, 0.20f, 1.00f);
+ const ImVec4 amberHi = ImVec4(1.00f, 0.73f, 0.36f, 1.00f);
+ ImVec4* c = s.Colors;
+ c[ImGuiCol_WindowBg] = ImVec4(0.07f, 0.08f, 0.10f, 0.97f);
+ c[ImGuiCol_ChildBg] = ImVec4(0.10f, 0.11f, 0.13f, 0.55f);
+ c[ImGuiCol_PopupBg] = ImVec4(0.09f, 0.10f, 0.12f, 0.98f);
+ c[ImGuiCol_TitleBg] = ImVec4(0.09f, 0.10f, 0.12f, 1.00f);
+ c[ImGuiCol_TitleBgActive] = ImVec4(0.13f, 0.14f, 0.17f, 1.00f);
+ c[ImGuiCol_Text] = ImVec4(0.90f, 0.91f, 0.93f, 1.00f);
+ c[ImGuiCol_TextDisabled] = ImVec4(0.48f, 0.50f, 0.54f, 1.00f);
+ c[ImGuiCol_FrameBg] = ImVec4(0.16f, 0.17f, 0.20f, 1.00f);
+ c[ImGuiCol_FrameBgHovered] = ImVec4(0.22f, 0.24f, 0.28f, 1.00f);
+ c[ImGuiCol_FrameBgActive] = ImVec4(0.26f, 0.28f, 0.33f, 1.00f);
+ c[ImGuiCol_Header] = ImVec4(0.17f, 0.19f, 0.23f, 1.00f);
+ c[ImGuiCol_HeaderHovered] = ImVec4(0.24f, 0.27f, 0.32f, 1.00f);
+ c[ImGuiCol_HeaderActive] = ImVec4(0.28f, 0.31f, 0.37f, 1.00f);
+ c[ImGuiCol_Button] = ImVec4(0.20f, 0.22f, 0.26f, 1.00f);
+ c[ImGuiCol_ButtonHovered] = ImVec4(0.27f, 0.30f, 0.35f, 1.00f);
+ c[ImGuiCol_ButtonActive] = amber;
+ c[ImGuiCol_SliderGrab] = amber;
+ c[ImGuiCol_SliderGrabActive]= amberHi;
+ c[ImGuiCol_CheckMark] = amberHi;
+ c[ImGuiCol_Tab] = ImVec4(0.13f, 0.14f, 0.17f, 1.00f);
+ c[ImGuiCol_TabHovered] = ImVec4(0.28f, 0.31f, 0.37f, 1.00f);
+ c[ImGuiCol_TabActive] = ImVec4(0.22f, 0.24f, 0.28f, 1.00f);
+ c[ImGuiCol_Separator] = ImVec4(0.20f, 0.22f, 0.26f, 1.00f);
+ c[ImGuiCol_ScrollbarGrab] = ImVec4(0.24f, 0.26f, 0.30f, 1.00f);
+ }
+
+ namespace
+ {
+ // Setup: renderer backend + environment
+ class SetupWorkspace : public Workspace
+ {
+ public:
+ auto name() const -> const char* override { return "Setup"; }
+ auto view() const -> View override { return View::None; }
+ auto on_ui(const UIContext& ctx) -> void override
+ {
+ if (ImGui::CollapsingHeader("Renderer", ImGuiTreeNodeFlags_DefaultOpen))
+ {
+ auto& s = SettingsManager::get_settings();
+ const char* apis[] = { "OpenGL", "Vulkan" };
+ int cur = (s.graphics.render_api == "Vulkan") ? 1 : 0;
+ if (ImGui::Combo("Graphics API", &cur, apis, 2))
+ {
+ s.graphics.render_api = apis[cur];
+ SettingsManager::save_settings();
+ }
+ const char* running = (RendererAPI::get_api() == RendererAPI::API::Vulkan) ? "Vulkan" : "OpenGL";
+ if (s.graphics.render_api != running)
+ ImGui::TextColored(ImVec4(0.98f, 0.62f, 0.20f, 1.0f), "Restart to apply (%s running)", running);
+ else
+ ImGui::TextDisabled("Active backend: %s", running);
+ }
+
+ if (ImGui::CollapsingHeader("Environment", ImGuiTreeNodeFlags_DefaultOpen))
+ {
+ auto& hdri = HDRIManager::get();
+ std::string preview = hdri.get_hdri_name(ctx.scene.hdri_path);
+ if (ImGui::BeginCombo("Starfield", preview.c_str()))
+ {
+ for (const auto& path : hdri.get_available_hdri())
+ {
+ bool selected = (path == ctx.scene.hdri_path);
+ if (ImGui::Selectable(hdri.get_hdri_name(path).c_str(), selected))
+ ctx.scene.hdri_path = path; // RenderPath rebuilds the cubemap next frame
+ if (selected) ImGui::SetItemDefaultFocus();
+ }
+ ImGui::EndCombo();
+ }
+ ImGui::TextDisabled("Switching rebuilds the cubemap (brief pause).");
+ }
+ }
+ };
+
+ // Scene: place and edit objects
+ class SceneWorkspace : public Workspace
+ {
+ public:
+ auto name() const -> const char* override { return "Scene"; }
+ auto view() const -> View override { return View::Scene; }
+ auto on_ui(const UIContext& ctx) -> void override
+ {
+ Scene& sc = ctx.scene;
+ ImGui::TextDisabled("Drag to orbit, scroll to zoom. HDRI skybox behind.");
+ auto& objs = sc.objects;
+ if (sc.selected_object >= (int)objs.size()) sc.selected_object = (int)objs.size() - 1;
+
+ ImGui::Text("Spheres (%d)", (int)objs.size());
+ if (ImGui::Button("Add") && objs.size() < 64)
+ {
+ SceneObject o;
+ o.position = glm::vec3(((int)objs.size() % 5) * 5.0f - 10.0f, 2.0f, ((int)objs.size() / 5) * 5.0f);
+ o.radius = 1.5f;
+ o.color = glm::vec3(0.35f + 0.12f * (objs.size() % 5), 0.55f, 0.9f - 0.12f * (objs.size() % 4));
+ objs.push_back(o);
+ sc.selected_object = (int)objs.size() - 1;
+ }
+ ImGui::SameLine();
+ if (ImGui::Button("Delete") && !objs.empty())
+ {
+ objs.erase(objs.begin() + sc.selected_object);
+ if (sc.selected_object >= (int)objs.size()) sc.selected_object = (int)objs.size() - 1;
+ }
+
+ ImGui::BeginChild("obj_list", ImVec2(0, 120), true);
+ for (int i = 0; i < (int)objs.size(); ++i)
+ {
+ std::string label = "Sphere " + std::to_string(i);
+ if (ImGui::Selectable(label.c_str(), sc.selected_object == i)) sc.selected_object = i;
+ }
+ ImGui::EndChild();
+
+ if (sc.selected_object >= 0 && sc.selected_object < (int)objs.size())
+ {
+ SceneObject& o = objs[sc.selected_object];
+ ImGui::DragFloat3("Position", &o.position.x, 0.1f);
+ ImGui::DragFloat("Radius", &o.radius, 0.05f, 0.1f, 20.0f);
+ ImGui::ColorEdit3("Color", &o.color.x);
+ }
+ }
+ };
+
+ // Simulation: camera + accretion disk + quality
+ class SimulationWorkspace : public Workspace
+ {
+ public:
+ auto name() const -> const char* override { return "Simulation"; }
+ auto view() const -> View override { return View::BlackHole; }
+ auto on_ui(const UIContext& ctx) -> void override
+ {
+ Scene& sc = ctx.scene;
+ BlackHoleParams& bh = sc.black_hole;
+
+ if (ImGui::CollapsingHeader("Camera", ImGuiTreeNodeFlags_DefaultOpen))
+ {
+ bool ff = sc.is_free_fly();
+ if (ImGui::RadioButton("Orbital", !ff)) sc.set_free_fly(false);
+ ImGui::SameLine();
+ if (ImGui::RadioButton("Free-fly", ff)) sc.set_free_fly(true);
+ ImGui::SameLine();
+ if (ImGui::Button("Reset view")) sc.reset_sim_camera();
+ ImGui::SliderFloat("FOV", &bh.fov_degrees, 20.0f, 90.0f, "%.0f\xc2\xb0");
+ ImGui::TextDisabled(ff ? "WASD move | Q/E down-up | Shift boost | drag look"
+ : "Drag to orbit | scroll to zoom");
+ }
+
+ if (ImGui::CollapsingHeader("Accretion disk", ImGuiTreeNodeFlags_DefaultOpen))
+ {
+ ImGui::SliderFloat("Temperature", &bh.temperature, 2000.0f, 15000.0f, "%.0f K");
+ ImGui::SliderFloat("Brightness", &bh.brightness, 0.0f, 3.0f, "%.2f");
+ ImGui::SliderFloat("Inner radius", &bh.disk_inner_rs, 3.0f, 12.0f, "%.1f r_s");
+ if (bh.disk_outer_rs < bh.disk_inner_rs + 0.5f) bh.disk_outer_rs = bh.disk_inner_rs + 0.5f;
+ ImGui::SliderFloat("Outer radius", &bh.disk_outer_rs, bh.disk_inner_rs + 0.5f, 25.0f, "%.1f r_s");
+ ImGui::SliderFloat("Turbulence", &bh.turbulence, 0.0f, 2.0f, "%.2f");
+ ImGui::TextDisabled("Inner edge is the ISCO (3 r_s). Novikov-Thorne profile.");
+ }
+
+ if (ImGui::CollapsingHeader("Quality"))
+ {
+ ImGui::SliderInt("Integration steps", &bh.quality_steps, 2000, 15000);
+ ImGui::TextDisabled("Deeper lensing at higher cost. Settled frame is 4x supersampled.");
+ }
+ }
+ };
+
+ // Export: pick what to render out (not wired up yet)
+ class ExportWorkspace : public Workspace
+ {
+ public:
+ auto name() const -> const char* override { return "Export"; }
+ auto view() const -> View override { return View::None; }
+ auto on_ui(const UIContext&) -> void override
+ {
+ ImGui::TextDisabled("Render observables to disk for analysis.");
+ ImGui::Spacing();
+ if (ImGui::CollapsingHeader("Channels", ImGuiTreeNodeFlags_DefaultOpen))
+ {
+ ImGui::Checkbox("Colour (tonemapped)", &m_color);
+ ImGui::Checkbox("Redshift (g)", &m_redshift);
+ ImGui::Checkbox("Emission temperature", &m_temperature);
+ ImGui::Checkbox("Impact parameter", &m_impact);
+ }
+ if (ImGui::CollapsingHeader("Output", ImGuiTreeNodeFlags_DefaultOpen))
+ {
+ ImGui::Combo("Resolution", &m_resolution, "960 x 540\0" "1920 x 1080\0" "3840 x 2160\0");
+ ImGui::Combo("Format", &m_format, "PNG\0" "EXR (HDR)\0" "CSV (data)\0");
+ }
+ ImGui::Spacing();
+ ImGui::BeginDisabled();
+ ImGui::Button("Export frame", ImVec2(-1.0f, 0.0f));
+ ImGui::EndDisabled();
+ ImGui::TextDisabled("Not wired up yet: needs the RHI readback path + G-buffer shader outputs.");
+ }
+ private:
+ bool m_color = true, m_redshift = false, m_temperature = false, m_impact = false;
+ int m_resolution = 1, m_format = 0;
+ };
+ }
+
+ UILayer::UILayer()
+ {
+ m_workspaces.push_back(create_scope<SetupWorkspace>());
+ m_workspaces.push_back(create_scope<SceneWorkspace>());
+ m_workspaces.push_back(create_scope<SimulationWorkspace>());
+ m_workspaces.push_back(create_scope<ExportWorkspace>());
+
+ // Open on Simulation so the black hole greets the user on launch.
+ for (int i = 0; i < (int)m_workspaces.size(); ++i)
+ if (std::string(m_workspaces[i]->name()) == "Simulation") { m_landing = i; m_active = i; }
+ }
+
+ auto UILayer::draw(const UIContext& ctx) -> View
+ {
+ static bool styled = false;
+ if (!styled) { apply_donut_style(); styled = true; }
+
+ // Full-viewport dock space with a pass-through centre, so the panel docks to
+ // any edge while the render shows through the middle.
+ ImGui::DockSpaceOverViewport(0, ImGui::GetMainViewport(), ImGuiDockNodeFlags_PassthruCentralNode);
+
+ ImGui::SetNextWindowSize(ImVec2(360, 620), ImGuiCond_FirstUseEver);
+ ImGui::Begin("Donut");
+
+ ImGuiIO& io = ImGui::GetIO();
+ ImGui::TextDisabled("%s", ctx.device_name.empty() ? "GPU" : ctx.device_name.c_str());
+ ImGui::Text("%.0f FPS", io.Framerate);
+ ImGui::SameLine(); ImGui::TextDisabled("%.1f ms/frame", io.Framerate > 0 ? 1000.0f / io.Framerate : 0.0f);
+ ImGui::Spacing();
+
+ if (ImGui::BeginTabBar("workspaces"))
+ {
+ for (int i = 0; i < (int)m_workspaces.size(); ++i)
+ {
+ ImGuiTabItemFlags flags = (!m_landed && i == m_landing) ? ImGuiTabItemFlags_SetSelected : 0;
+ if (ImGui::BeginTabItem(m_workspaces[i]->name(), nullptr, flags))
+ {
+ m_active = i;
+ ImGui::Spacing();
+ m_workspaces[i]->on_ui(ctx);
+ ImGui::EndTabItem();
+ }
+ }
+ ImGui::EndTabBar();
+ m_landed = true;
+ }
+ ImGui::End();
+
+ return m_workspaces[m_active]->view();
+ }
+}