hachem.wtf
aboutsummaryrefslogtreecommitdiff
path: root/src/platform/vulkan/vulkan_renderer.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/platform/vulkan/vulkan_renderer.cpp')
-rw-r--r--src/platform/vulkan/vulkan_renderer.cpp51
1 files changed, 43 insertions, 8 deletions
diff --git a/src/platform/vulkan/vulkan_renderer.cpp b/src/platform/vulkan/vulkan_renderer.cpp
index 1a9f21b..882fbf3 100644
--- a/src/platform/vulkan/vulkan_renderer.cpp
+++ b/src/platform/vulkan/vulkan_renderer.cpp
@@ -98,6 +98,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;
+ BlackHoleParams bh_params;
+ std::string gpu_name;
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;
@@ -302,7 +305,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;
}
@@ -645,9 +649,7 @@ namespace Donut
void* p = nullptr;
vkMapMemory(device, cam_mem, 0, 128, 0, &cam_mapped);
-
- 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, disk_mem, 0, 32, 0, &disk_mapped);
std::vector<uint8_t> obj_data(800, 0);
int num_objects = 1; memcpy(obj_data.data(), &num_objects, 4);
@@ -1426,18 +1428,30 @@ 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;
cam_data.moving = user_moving ? 1u : 0u;
if (cam_mapped) memcpy(cam_mapped, &cam_data, sizeof(cam_data));
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;
sim.early_exit = SettingsManager::get_early_exit_distance();
sim.time = (float)(glfwGetTime() - start_time);
if (sim_mapped) memcpy(sim_mapped, &sim, sizeof(sim));
+
+ 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,
+ 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;
@@ -1554,6 +1568,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); }
@@ -1714,7 +1729,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;
@@ -1758,7 +1773,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;
@@ -1827,6 +1842,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);
+ 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;