From 77717ae7c4f7c8f180e5c5e24cf1098c02f3dbf4 Mon Sep 17 00:00:00 2001 From: hachem Date: Fri, 22 Aug 2025 04:48:42 +0200 Subject: feat: add bloom and blur --- src/engine/engine.cpp | 19 +++++++++++++++++++ src/engine/engine.h | 12 +++++++++++- src/states/simulation_state.cpp | 16 +++++++++++++++- 3 files changed, 45 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/engine/engine.cpp b/src/engine/engine.cpp index 435b3e0..9a88e9e 100644 --- a/src/engine/engine.cpp +++ b/src/engine/engine.cpp @@ -34,6 +34,7 @@ namespace Donut m_shader_program = Ref(Shader::create("assets/shaders/compute_texture_quad.glsl")); m_compute_program = create_compute_program("assets/shaders/geodesic.glsl"); + m_blur_shader = Ref(Shader::create("assets/shaders/blur.glsl")); m_camera_ubo = UniformBuffer::create(128, 1); m_disk_ubo = UniformBuffer::create(sizeof(float) * 5, 2); @@ -96,6 +97,24 @@ namespace Donut RenderCommand::enable_depth_test(); } + void Engine::draw_blur_pass() + { + RenderCommand::set_viewport(0, 0, m_width, m_height); + + m_blur_shader->bind(); + m_quad_vao->bind(); + + m_texture->bind(0); + m_blur_shader->set_int("u_ScreenTexture", 0); + m_blur_shader->set_float2("u_Resolution", glm::vec2(m_width, m_height)); + m_blur_shader->set_float("u_BlurStrength", m_blur_strength); + m_blur_shader->set_float("u_GlowIntensity", m_glow_intensity); + + RenderCommand::disable_depth_test(); + RenderCommand::draw_arrays(6); + RenderCommand::enable_depth_test(); + } + void Engine::dispatch_compute(const Camera& cam) { int cw = get_compute_width(); diff --git a/src/engine/engine.h b/src/engine/engine.h index 524f1a7..95cd1f0 100644 --- a/src/engine/engine.h +++ b/src/engine/engine.h @@ -66,6 +66,7 @@ namespace Donut ~Engine() = default; void draw_full_screen_quad(); + void draw_blur_pass(); void dispatch_compute(const Camera& cam); void upload_camera_ubo(const Camera& cam); void upload_objects_ubo(const std::vector& objs); @@ -109,6 +110,12 @@ namespace Donut float get_rotation_speed() const { return m_rotation_speed; } void set_rotation_speed(float speed) { m_rotation_speed = speed; } + float get_blur_strength() const { return m_blur_strength; } + void set_blur_strength(float strength) { m_blur_strength = strength; } + + float get_glow_intensity() const { return m_glow_intensity; } + void set_glow_intensity(float intensity) { m_glow_intensity = intensity; } + void load_objects_from_scene(const std::vector& objects); void export_high_res_frame(const std::string& filename, int width = 4096, int height = 3072); void print_object_info() const; @@ -120,6 +127,7 @@ namespace Donut Ref m_texture; Ref m_shader_program; Ref m_compute_program; + Ref m_blur_shader; Ref m_camera_ubo; Ref m_disk_ubo; Ref m_objects_ubo; @@ -145,7 +153,9 @@ namespace Donut float m_early_exit_distance = 5e11f; float m_disk_thickness = 0.1; - float m_disk_density = 1.2f; + float m_disk_density = 0.1f; float m_rotation_speed = 1.0f; + float m_blur_strength = 2.0f; + float m_glow_intensity = 0.1f; }; }; diff --git a/src/states/simulation_state.cpp b/src/states/simulation_state.cpp index 5c75569..6d7ae47 100644 --- a/src/states/simulation_state.cpp +++ b/src/states/simulation_state.cpp @@ -60,7 +60,7 @@ namespace Donut RenderCommand::set_viewport(0, 0, static_cast(engine.get_width()), static_cast(engine.get_height())); engine.dispatch_compute(engine.get_camera()); - engine.draw_full_screen_quad(); + engine.draw_blur_pass(); } void SimulationState::on_event(Event& event) @@ -244,6 +244,20 @@ namespace Donut } ImGui::TextDisabled("Rotation speed multiplier (0 = no rotation)"); + float blur_strength = engine.get_blur_strength(); + if (ImGui::SliderFloat("Blur Strength", &blur_strength, 0.5f, 5.0f, "%.2f")) + { + engine.set_blur_strength(blur_strength); + } + ImGui::TextDisabled("Blur radius for glow effect"); + + float glow_intensity = engine.get_glow_intensity(); + if (ImGui::SliderFloat("Glow Intensity", &glow_intensity, 0.1f, 3.0f, "%.2f")) + { + engine.set_glow_intensity(glow_intensity); + } + ImGui::TextDisabled("Intensity of the glow effect"); + ImGui::Spacing(); ImGui::TextColored(ImVec4(0.9f, 0.9f, 1.0f, 1.0f), "Camera"); -- cgit v1.3