hachem.wtf
aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/core/application.cpp346
-rw-r--r--src/core/application.h41
-rw-r--r--src/core/hdri_manager.h2
-rw-r--r--src/ui/ui_layer.cpp267
-rw-r--r--src/ui/ui_layer.h23
-rw-r--r--src/ui/workspace.h24
6 files changed, 363 insertions, 340 deletions
diff --git a/src/core/application.cpp b/src/core/application.cpp
index 8b411c3..f751d2f 100644
--- a/src/core/application.cpp
+++ b/src/core/application.cpp
@@ -2,18 +2,14 @@
#include "rendering/render_api.h"
#include "settings_manager.h"
-#include "hdri_manager.h"
#include "platform/opengl/opengl_device.h"
#include "platform/vulkan/vulkan_device.h"
#include <GLFW/glfw3.h>
#include <imgui.h>
-
-#include <glm/gtc/matrix_transform.hpp>
+#include <glm/glm.hpp>
#include <algorithm>
-#include <cmath>
-#include <numbers>
namespace Donut
{
@@ -28,7 +24,6 @@ namespace Donut
}
Application::Application(const std::string& name, int width, int height)
- : m_running(true), m_minimized(false)
{
s_instance = this;
@@ -72,32 +67,10 @@ namespace Donut
return;
}
- m_hdri_path = "assets/hdri/hdr_blue_nebulae_1.hdr";
- m_cubemap = m_device->create_cubemap_from_hdri(m_hdri_path);
-
- m_scene_renderer = create_scope<SceneRenderer>();
- m_scene_renderer->init(*m_device);
- m_black_hole_renderer = create_scope<BlackHoleRenderer>();
- m_black_hole_renderer->init(*m_device);
-
- m_camera.set_camera_mode(CameraMode::Orbital);
- m_camera.set_orbital_target(glm::vec3(0.0f));
- m_camera.set_orbital_radius(4e11);
- m_camera.set_orbital_limits(2.2e11, 1.5e12);
- m_camera.set_orbital_speed(0.01f);
- m_camera.set_zoom_speed(3e10);
- m_camera.set_azimuth(0.0f);
- m_camera.set_elevation(1.25f);
-
- m_scene_camera.set_camera_mode(CameraMode::Orbital);
- m_scene_camera.set_orbital_target(glm::vec3(0.0f));
- m_scene_camera.set_orbital_radius(15.0);
- m_scene_camera.set_orbital_limits(2.0, 200.0);
- m_scene_camera.set_orbital_speed(0.01f);
- m_scene_camera.set_zoom_speed(2.0);
- m_scene_camera.set_azimuth(0.0f);
- m_scene_camera.set_elevation((float)std::numbers::pi / 3.0f);
- m_scene_camera.update_orbital();
+ m_scene = create_scope<Scene>();
+ m_render_path = create_scope<RenderPath>();
+ m_render_path->init(*m_device, m_scene->hdri_path);
+ m_ui = create_scope<UILayer>();
m_device->init_imgui();
ImGuiIO& io = ImGui::GetIO();
@@ -126,60 +99,19 @@ namespace Donut
if (!cmd) return;
m_device->imgui_new_frame();
- build_ui();
- process_input();
+ View view = m_ui->draw(UIContext{ *m_scene, m_device->device_name() });
+ update_input(view);
+ m_render_path->sync_hdri(m_scene->hdri_path);
- const glm::vec4 clear(0.05f, 0.06f, 0.10f, 1.0f);
int w = 0, h = 0;
glfwGetFramebufferSize((GLFWwindow*)m_window->get_native_window(), &w, &h);
-
- if (m_scene_mode)
- {
- float aspect = (float)w / (float)std::max(h, 1);
- m_scene_camera.set_projection(45.0f, aspect, 0.1f, 1000.0f);
- CameraView cv;
- cv.view = m_scene_camera.get_view_matrix();
- cv.projection = m_scene_camera.get_projection_matrix();
- cv.position = m_scene_camera.get_orbital_position();
- cv.fb_width = w; cv.fb_height = h;
-
- cmd->begin_render_pass(nullptr, clear);
- m_scene_renderer->render(*cmd, cv, m_scene_objects, m_selected_object, m_cubemap.get());
- m_device->imgui_render(*cmd);
- cmd->end_render_pass();
- }
- else
- {
- GeodesicView gv;
- glm::vec3 pos, fwd;
- if (m_camera.get_camera_mode() == CameraMode::FPS)
- {
- pos = m_camera.get_position();
- fwd = m_camera.get_forward_direction();
- }
- else
- {
- pos = m_camera.get_orbital_position();
- fwd = glm::normalize(m_camera.get_orbital_target() - pos);
- }
- glm::vec3 right = glm::normalize(glm::cross(fwd, glm::vec3(0, 1, 0)));
- gv.position = pos; gv.right = right; gv.up = glm::cross(right, fwd); gv.forward = fwd;
- gv.tan_half_fov = (float)tan(glm::radians(m_bh_params.fov_degrees * 0.5f));
- gv.aspect = (float)BlackHoleRenderer::GEO_HI_W / (float)BlackHoleRenderer::GEO_HI_H;
- gv.moving = m_user_moving;
- gv.time = (float)(glfwGetTime() - m_start_time);
-
- m_black_hole_renderer->render_geodesic(*cmd, gv, m_bh_params, m_cubemap.get());
- cmd->begin_render_pass(nullptr, clear);
- m_black_hole_renderer->blit(*cmd, w, h);
- m_device->imgui_render(*cmd);
- cmd->end_render_pass();
- }
+ float time = (float)(glfwGetTime() - m_start_time);
+ m_render_path->render(*cmd, *m_scene, view, w, h, m_user_moving, time);
m_device->end_frame();
}
- auto Application::process_input() -> void
+ auto Application::update_input(View view) -> void
{
GLFWwindow* window = (GLFWwindow*)m_window->get_native_window();
bool over_ui = ImGui::GetCurrentContext() && ImGui::GetIO().WantCaptureMouse;
@@ -192,11 +124,22 @@ namespace Donut
glfwGetCursorPos(window, &mx, &my);
bool left_down = glfwGetMouseButton(window, GLFW_MOUSE_BUTTON_LEFT) == GLFW_PRESS;
- if (!m_scene_mode && m_camera.get_camera_mode() == CameraMode::FPS)
+ if (view == View::None)
+ {
+ m_left_was_down = left_down;
+ g_scroll_accum = 0.0;
+ m_user_moving = false;
+ return;
+ }
+
+ const bool scene_view = view == View::Scene;
+
+ if (!scene_view && m_scene->sim_camera.get_camera_mode() == CameraMode::FPS)
{
+ Camera& cam = m_scene->sim_camera;
if (left_down && !m_left_was_down) { m_fps_last_x = mx; m_fps_last_y = my; }
if (left_down && !over_ui)
- m_camera.on_mouse_move(float(mx - m_fps_last_x), float(m_fps_last_y - my));
+ cam.on_mouse_move(float(mx - m_fps_last_x), float(m_fps_last_y - my));
m_fps_last_x = mx; m_fps_last_y = my;
m_left_was_down = left_down;
@@ -205,19 +148,19 @@ namespace Donut
if (!over_kb && dt > 0.0f)
{
float mdt = dt * (glfwGetKey(window, GLFW_KEY_LEFT_SHIFT) == GLFW_PRESS ? 4.0f : 1.0f);
- if (glfwGetKey(window, GLFW_KEY_W) == GLFW_PRESS) { m_camera.move_forward(mdt); moved = true; }
- if (glfwGetKey(window, GLFW_KEY_S) == GLFW_PRESS) { m_camera.move_backward(mdt); moved = true; }
- if (glfwGetKey(window, GLFW_KEY_A) == GLFW_PRESS) { m_camera.move_left(mdt); moved = true; }
- if (glfwGetKey(window, GLFW_KEY_D) == GLFW_PRESS) { m_camera.move_right(mdt); moved = true; }
- if (glfwGetKey(window, GLFW_KEY_E) == GLFW_PRESS) { m_camera.move_up(mdt); moved = true; }
- if (glfwGetKey(window, GLFW_KEY_Q) == GLFW_PRESS) { m_camera.move_down(mdt); moved = true; }
+ if (glfwGetKey(window, GLFW_KEY_W) == GLFW_PRESS) { cam.move_forward(mdt); moved = true; }
+ if (glfwGetKey(window, GLFW_KEY_S) == GLFW_PRESS) { cam.move_backward(mdt); moved = true; }
+ if (glfwGetKey(window, GLFW_KEY_A) == GLFW_PRESS) { cam.move_left(mdt); moved = true; }
+ if (glfwGetKey(window, GLFW_KEY_D) == GLFW_PRESS) { cam.move_right(mdt); moved = true; }
+ if (glfwGetKey(window, GLFW_KEY_E) == GLFW_PRESS) { cam.move_up(mdt); moved = true; }
+ if (glfwGetKey(window, GLFW_KEY_Q) == GLFW_PRESS) { cam.move_down(mdt); moved = true; }
}
g_scroll_accum = 0.0;
m_user_moving = moved || (left_down && !over_ui);
}
else
{
- Camera& cam = m_scene_mode ? m_scene_camera : m_camera;
+ Camera& cam = scene_view ? m_scene->scene_camera : m_scene->sim_camera;
if (left_down && !m_left_was_down && !over_ui)
cam.process_orbital_mouse_button(GLFW_MOUSE_BUTTON_LEFT, GLFW_PRESS, 0);
else if (!left_down && m_left_was_down)
@@ -234,223 +177,6 @@ namespace Donut
}
}
- auto Application::set_free_fly(bool enabled) -> void
- {
- const bool is_fps = m_camera.get_camera_mode() == CameraMode::FPS;
- if (enabled == is_fps) return;
- if (enabled)
- {
- glm::vec3 pos = m_camera.get_orbital_position();
- glm::vec3 fwd = glm::normalize(m_camera.get_orbital_target() - pos);
- float pitch = glm::degrees(asin(glm::clamp(fwd.y, -1.0f, 1.0f)));
- float yaw = glm::degrees(atan2(fwd.z, fwd.x));
- m_camera.set_camera_mode(CameraMode::FPS);
- m_camera.set_movement_speed(2.0e10f);
- m_camera.set_mouse_sensitivity(0.15f);
- m_camera.set_position(pos);
- m_camera.set_rotation(glm::vec3(pitch, yaw, 0.0f));
- }
- else
- {
- m_camera.set_camera_mode(CameraMode::Orbital);
- }
- }
-
- auto Application::reset_camera() -> void
- {
- m_camera.set_camera_mode(CameraMode::Orbital);
- m_camera.set_orbital_radius(4e11);
- m_camera.set_azimuth(0.0f);
- m_camera.set_elevation(1.25f);
- }
-
- auto Application::set_hdri(const std::string& path) -> void
- {
- if (m_hdri_path == path || !m_device) return;
- m_device->wait_idle();
- m_cubemap = m_device->create_cubemap_from_hdri(path);
- m_hdri_path = path;
- }
-
- 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_Separator] = ImVec4(0.20f, 0.22f, 0.26f, 1.00f);
- c[ImGuiCol_ScrollbarGrab] = ImVec4(0.24f, 0.26f, 0.30f, 1.00f);
- }
-
- auto Application::build_ui() -> void
- {
- static bool styled = false;
- if (!styled) { apply_donut_style(); styled = true; }
- if (!m_device) return;
-
- ImGui::DockSpaceOverViewport(0, ImGui::GetMainViewport(), ImGuiDockNodeFlags_PassthruCentralNode);
-
- ImGui::SetNextWindowSize(ImVec2(340, 580), ImGuiCond_FirstUseEver);
- ImGui::Begin("Donut \xc2\xb7 Black Hole");
-
- ImGuiIO& io = ImGui::GetIO();
- ImGui::TextDisabled("%s", m_device->device_name().empty() ? "GPU" : m_device->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::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);
- }
-
- ImGui::Spacing();
- ImGui::TextDisabled("VIEW");
- if (ImGui::RadioButton("Black hole", !m_scene_mode)) m_scene_mode = false;
- ImGui::SameLine();
- if (ImGui::RadioButton("Scene", m_scene_mode)) m_scene_mode = true;
- ImGui::Separator();
-
- if (m_scene_mode)
- {
- build_scene_ui();
- }
- else
- {
- BlackHoleParams& bh = m_bh_params;
-
- if (ImGui::CollapsingHeader("Camera", ImGuiTreeNodeFlags_DefaultOpen))
- {
- bool ff = m_camera.get_camera_mode() == CameraMode::FPS;
- if (ImGui::RadioButton("Orbital", !ff)) set_free_fly(false);
- ImGui::SameLine();
- if (ImGui::RadioButton("Free-fly", ff)) set_free_fly(true);
- ImGui::SameLine();
- if (ImGui::Button("Reset view")) reset_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.");
- }
-
- if (ImGui::CollapsingHeader("Environment", ImGuiTreeNodeFlags_DefaultOpen))
- {
- auto& hdri = HDRIManager::get();
- std::string preview = hdri.get_hdri_name(m_hdri_path);
- if (ImGui::BeginCombo("Starfield", preview.c_str()))
- {
- for (const auto& path : hdri.get_available_hdri())
- {
- bool selected = (path == m_hdri_path);
- if (ImGui::Selectable(hdri.get_hdri_name(path).c_str(), selected))
- set_hdri(path);
- if (selected) ImGui::SetItemDefaultFocus();
- }
- ImGui::EndCombo();
- }
- ImGui::TextDisabled("Switching rebuilds the cubemap (brief pause).");
- }
- }
-
- ImGui::End();
- }
-
- auto Application::build_scene_ui() -> void
- {
- if (!ImGui::CollapsingHeader("Objects", ImGuiTreeNodeFlags_DefaultOpen))
- return;
-
- ImGui::TextDisabled("Drag to orbit, scroll to zoom. HDRI skybox behind.");
- auto& objs = m_scene_objects;
- if (m_selected_object >= (int)objs.size()) m_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);
- m_selected_object = (int)objs.size() - 1;
- }
- ImGui::SameLine();
- if (ImGui::Button("Delete") && !objs.empty())
- {
- objs.erase(objs.begin() + m_selected_object);
- if (m_selected_object >= (int)objs.size()) m_selected_object = (int)objs.size() - 1;
- }
-
- ImGui::BeginChild("obj_list", ImVec2(0, 90), true);
- for (int i = 0; i < (int)objs.size(); ++i)
- {
- std::string label = "Sphere " + std::to_string(i);
- if (ImGui::Selectable(label.c_str(), m_selected_object == i)) m_selected_object = i;
- }
- ImGui::EndChild();
-
- if (m_selected_object >= 0 && m_selected_object < (int)objs.size())
- {
- SceneObject& o = objs[m_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);
- }
- }
-
auto Application::close() -> void
{
m_running = false;
@@ -480,14 +206,14 @@ namespace Donut
if (m_device)
{
m_device->wait_idle();
- m_scene_renderer.reset();
- m_black_hole_renderer.reset();
- m_cubemap.reset();
- HDRIManager::get().clear_cache();
+ if (m_render_path) m_render_path->shutdown();
+ m_render_path.reset();
+ m_ui.reset();
+ m_scene.reset();
m_device->shutdown();
m_device.reset();
}
SettingsManager::shutdown();
Logger::shutdown();
}
-};
+}
diff --git a/src/core/application.h b/src/core/application.h
index 84cc600..880a495 100644
--- a/src/core/application.h
+++ b/src/core/application.h
@@ -4,14 +4,14 @@
#include "window.h"
#include "event.h"
#include "log.h"
-#include "camera.h"
#include "rendering/rhi.h"
-#include "rendering/scene_renderer.h"
-#include "rendering/black_hole_renderer.h"
+#include "rendering/render_path.h"
+#include "rendering/view.h"
+#include "scene/scene.h"
+#include "ui/ui_layer.h"
#include <string>
-#include <vector>
namespace Donut
{
@@ -33,32 +33,15 @@ namespace Donut
auto on_shutdown() -> void;
auto on_event(Event& event) -> void;
- auto build_ui() -> void;
- auto build_scene_ui() -> void;
-
- auto process_input() -> void;
- auto set_free_fly(bool enabled) -> void;
- auto reset_camera() -> void;
- auto set_hdri(const std::string& path) -> void;
-
auto render_frame() -> void;
+ auto update_input(View view) -> void;
private:
- Scope<Window> m_window;
-
- Scope<RHI::Device> m_device;
- Scope<SceneRenderer> m_scene_renderer;
- Scope<BlackHoleRenderer> m_black_hole_renderer;
- Ref<RHI::Texture> m_cubemap;
-
- Camera m_camera{ 60.0f, 16.0f / 9.0f, 0.1f, 100.0f };
- Camera m_scene_camera{ 45.0f, 16.0f / 9.0f, 0.1f, 1000.0f };
-
- BlackHoleParams m_bh_params;
- std::vector<SceneObject> m_scene_objects{ SceneObject{} };
- int m_selected_object = 0;
- bool m_scene_mode = false;
- std::string m_hdri_path;
+ Scope<Window> m_window;
+ Scope<RHI::Device> m_device;
+ Scope<Scene> m_scene;
+ Scope<RenderPath> m_render_path;
+ Scope<UILayer> m_ui;
bool m_left_was_down = false;
double m_fps_last_x = 0.0, m_fps_last_y = 0.0;
@@ -66,8 +49,8 @@ namespace Donut
double m_start_time = 0.0;
bool m_user_moving = false;
- bool m_running;
- bool m_minimized;
+ bool m_running = true;
+ bool m_minimized = false;
static Application* s_instance;
};
diff --git a/src/core/hdri_manager.h b/src/core/hdri_manager.h
index d98830f..6b3df1e 100644
--- a/src/core/hdri_manager.h
+++ b/src/core/hdri_manager.h
@@ -1,7 +1,7 @@
#pragma once
#include "core/log.h"
-#include "rendering/texture.h"
+#include "platform/opengl/texture.h"
#include <string>
#include <unordered_map>
diff --git a/src/ui/ui_layer.cpp b/src/ui/ui_layer.cpp
new file mode 100644
index 0000000..ca83b59
--- /dev/null
+++ b/src/ui/ui_layer.cpp
@@ -0,0 +1,267 @@
+#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
+{
+ 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
+ {
+ 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;
+ if (selected) ImGui::SetItemDefaultFocus();
+ }
+ ImGui::EndCombo();
+ }
+ ImGui::TextDisabled("Switching rebuilds the cubemap (brief pause).");
+ }
+ }
+ };
+
+ 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);
+ }
+ }
+ };
+
+ 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.");
+ }
+ }
+ };
+
+ 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>());
+
+ 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; }
+
+ 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();
+ }
+}
diff --git a/src/ui/ui_layer.h b/src/ui/ui_layer.h
new file mode 100644
index 0000000..5032c05
--- /dev/null
+++ b/src/ui/ui_layer.h
@@ -0,0 +1,23 @@
+#pragma once
+
+#include "workspace.h"
+#include "rendering/view.h"
+#include "core/memory.h"
+
+#include <vector>
+
+namespace Donut
+{
+ class UILayer
+ {
+ public:
+ UILayer();
+ auto draw(const UIContext& ctx) -> View;
+
+ private:
+ std::vector<Scope<Workspace>> m_workspaces;
+ int m_active = 0;
+ int m_landing = 0;
+ bool m_landed = false;
+ };
+}
diff --git a/src/ui/workspace.h b/src/ui/workspace.h
new file mode 100644
index 0000000..7806f5c
--- /dev/null
+++ b/src/ui/workspace.h
@@ -0,0 +1,24 @@
+#pragma once
+
+#include "rendering/view.h"
+#include <string>
+
+namespace Donut
+{
+ class Scene;
+
+ struct UIContext
+ {
+ Scene& scene;
+ std::string device_name;
+ };
+
+ class Workspace
+ {
+ public:
+ virtual ~Workspace() = default;
+ virtual auto name() const -> const char* = 0;
+ virtual auto view() const -> View = 0;
+ virtual auto on_ui(const UIContext& ctx) -> void = 0;
+ };
+}