diff options
Diffstat (limited to 'src/platform/vulkan/vulkan_renderer.cpp')
| -rw-r--r-- | src/platform/vulkan/vulkan_renderer.cpp | 58 |
1 files changed, 47 insertions, 11 deletions
diff --git a/src/platform/vulkan/vulkan_renderer.cpp b/src/platform/vulkan/vulkan_renderer.cpp index 8ecf088..8b0d0c0 100644 --- a/src/platform/vulkan/vulkan_renderer.cpp +++ b/src/platform/vulkan/vulkan_renderer.cpp @@ -105,6 +105,9 @@ namespace Donut VkDeviceMemory cam_mem = VK_NULL_HANDLE, disk_mem = VK_NULL_HANDLE, obj_mem = VK_NULL_HANDLE, sim_mem = VK_NULL_HANDLE; void* cam_mapped = nullptr; void* sim_mapped = nullptr; + void* disk_mapped = nullptr; // disk UBO, refilled from bh_params each frame + BlackHoleParams bh_params; // live UI-tunable disk/camera parameters + std::string gpu_name; // physical device name for the UI Camera camera{ 60.0f, (float)GEO_HI_W / (float)GEO_HI_H, 0.1f, 100.0f }; bool left_was_down = false; double last_frame_time = 0.0; // for free-fly dt @@ -323,7 +326,8 @@ namespace Donut VkPhysicalDeviceProperties props{}; vkGetPhysicalDeviceProperties(physical, &props); vkGetPhysicalDeviceMemoryProperties(physical, &mem_props); - DONUT_INFO("Vulkan device: {}", props.deviceName); + gpu_name = props.deviceName; + DONUT_INFO("Vulkan device: {}", gpu_name); return true; } @@ -670,12 +674,8 @@ namespace Donut camera.set_elevation(1.25f); void* p = nullptr; - vkMapMemory(device, cam_mem, 0, 128, 0, &cam_mapped); // camera UBO is refilled every frame - - // disk_r1=inner (ISCO 3 r_s), disk_r2=outer, disk_num=turbulence strength, - // thickness (unused by the thin-disk model), disk_density=exposure. - float disk_data[8] = { SagA_rs * 3.0f, SagA_rs * 12.0f, 0.4f, SagA_rs * 0.1f, 0.1f, 0, 0, 0 }; - vkMapMemory(device, disk_mem, 0, 32, 0, &p); memcpy(p, disk_data, sizeof(disk_data)); vkUnmapMemory(device, disk_mem); + vkMapMemory(device, cam_mem, 0, 128, 0, &cam_mapped); // camera UBO refilled every frame + vkMapMemory(device, disk_mem, 0, 32, 0, &disk_mapped); // disk UBO refilled from bh_params every frame std::vector<uint8_t> obj_data(800, 0); int num_objects = 1; memcpy(obj_data.data(), &num_objects, 4); @@ -1479,7 +1479,7 @@ namespace Donut } glm::vec3 right = glm::normalize(glm::cross(fwd, glm::vec3(0, 1, 0))); cam_data.pos = pos; cam_data.right = right; cam_data.up = glm::cross(right, fwd); cam_data.fwd = fwd; - cam_data.tan_half_fov = (float)tan(glm::radians(60.0f * 0.5f)); + cam_data.tan_half_fov = (float)tan(glm::radians(bh_params.fov_degrees * 0.5f)); cam_data.aspect = (float)GEO_HI_W / (float)GEO_HI_H; // 16:9, same for both targets cam_data.moving = user_moving ? 1u : 0u; if (cam_mapped) memcpy(cam_mapped, &cam_data, sizeof(cam_data)); @@ -1495,11 +1495,26 @@ namespace Donut // Sourced from settings.toml (max_steps_static), capped GPU-safe. constexpr int kStepCeil = 15000; struct SimUBO { int steps_moving; int steps_static; float early_exit; float time; } sim; - sim.steps_static = std::clamp(SettingsManager::get_max_steps_static(), 1000, kStepCeil); + sim.steps_static = std::clamp(bh_params.quality_steps, 1000, kStepCeil); sim.steps_moving = sim.steps_static; // same budget both frames; resolution is the lever sim.early_exit = SettingsManager::get_early_exit_distance(); sim.time = (float)(glfwGetTime() - start_time); if (sim_mapped) memcpy(sim_mapped, &sim, sizeof(sim)); + + // Disk UBO, refilled live from the UI-tunable parameters. Layout matches + // the shader Disk struct: r1, r2, turbulence, slab thickness, brightness, + // temperature. Radii are in Schwarzschild radii (x SagA_rs). + const float SagA_rs = 1.269e10f; + float disk_data[8] = { + std::max(bh_params.disk_inner_rs, 3.0f) * SagA_rs, + std::max(bh_params.disk_outer_rs, bh_params.disk_inner_rs + 0.5f) * SagA_rs, + std::max(bh_params.turbulence, 0.0f), + SagA_rs * 0.1f, // slab half-thickness (fixed) + std::max(bh_params.brightness, 0.0f), + std::max(bh_params.temperature, 1000.0f), + 0.0f, 0.0f, + }; + if (disk_mapped) memcpy(disk_mapped, disk_data, sizeof(disk_data)); } static double g_ScrollAccum = 0.0; @@ -1617,6 +1632,7 @@ namespace Donut if (cube_mem) vkFreeMemory(device, cube_mem, nullptr); if (cam_mapped) { vkUnmapMemory(device, cam_mem); cam_mapped = nullptr; } if (sim_mapped) { vkUnmapMemory(device, sim_mem); sim_mapped = nullptr; } + if (disk_mapped) { vkUnmapMemory(device, disk_mem); disk_mapped = nullptr; } VkBuffer ubos[4] = { cam_buf, disk_buf, obj_buf, sim_buf }; VkDeviceMemory umem[4] = { cam_mem, disk_mem, obj_mem, sim_mem }; for (int i = 0; i < 4; ++i) { if (ubos[i]) vkDestroyBuffer(device, ubos[i], nullptr); if (umem[i]) vkFreeMemory(device, umem[i], nullptr); } @@ -1791,7 +1807,7 @@ namespace Donut return true; } - auto VulkanRenderer::init_im_gui() -> bool + auto VulkanRenderer::init_ui() -> bool { Impl& v = *m_impl; if (v.device == VK_NULL_HANDLE) return false; @@ -1835,7 +1851,7 @@ namespace Donut return true; } - auto VulkanRenderer::on_resize(int width, int height) -> void + auto VulkanRenderer::resize(int width, int height) -> void { m_impl->framebuffer_resized = true; m_impl->width = width; m_impl->height = height; @@ -1905,6 +1921,26 @@ namespace Donut if (m_impl) m_impl->selected_object = index; } + auto VulkanRenderer::black_hole_params() -> BlackHoleParams& + { + return m_impl->bh_params; + } + + auto VulkanRenderer::reset_camera() -> void + { + if (!m_impl) return; + Camera& cam = m_impl->camera; + cam.set_camera_mode(CameraMode::Orbital); // also flips is_free_fly() back + cam.set_orbital_radius(4e11); + cam.set_azimuth(0.0f); + cam.set_elevation(1.25f); + } + + auto VulkanRenderer::device_name() const -> const std::string& + { + return m_impl->gpu_name; + } + auto VulkanRenderer::draw_frame(const glm::vec4& clear_color, const std::function<void()>& build_ui) -> void { Impl& v = *m_impl; |
