From b9c20fccac64e7aadd28ea6c621c4ffda2561c54 Mon Sep 17 00:00:00 2001 From: hachem Date: Fri, 22 Aug 2025 04:48:42 +0200 Subject: [add]: add bloom and blur --- src/Engine/Engine.cpp | 19 +++++++++++++++++++ src/Engine/Engine.h | 12 +++++++++++- 2 files changed, 30 insertions(+), 1 deletion(-) (limited to 'src/Engine') diff --git a/src/Engine/Engine.cpp b/src/Engine/Engine.cpp index 37cafd8..20a295f 100644 --- a/src/Engine/Engine.cpp +++ b/src/Engine/Engine.cpp @@ -34,6 +34,7 @@ namespace Donut m_ShaderProgram = Ref(Shader::Create("Assets/Shaders/ComputeTextureQuad.glsl")); m_ComputeProgram = CreateComputeProgram("Assets/Shaders/Geodesic.glsl"); + m_BlurShader = Ref(Shader::Create("Assets/Shaders/Blur.glsl")); m_CameraUBO = UniformBuffer::Create(128, 1); m_DiskUBO = UniformBuffer::Create(sizeof(float) * 5, 2); // Added density parameter @@ -96,6 +97,24 @@ namespace Donut RenderCommand::EnableDepthTest(); } + void Engine::DrawBlurPass() + { + RenderCommand::SetViewport(0, 0, m_Width, m_Height); + + m_BlurShader->Bind(); + m_QuadVAO->Bind(); + + m_Texture->Bind(0); + m_BlurShader->SetInt("u_ScreenTexture", 0); + m_BlurShader->SetFloat2("u_Resolution", glm::vec2(m_Width, m_Height)); + m_BlurShader->SetFloat("u_BlurStrength", m_BlurStrength); + m_BlurShader->SetFloat("u_GlowIntensity", m_GlowIntensity); + + RenderCommand::DisableDepthTest(); + RenderCommand::DrawArrays(6); + RenderCommand::EnableDepthTest(); + } + void Engine::DispatchCompute(const Camera& cam) { int cw = GetComputeWidth(); diff --git a/src/Engine/Engine.h b/src/Engine/Engine.h index a0b25b5..83f0b19 100644 --- a/src/Engine/Engine.h +++ b/src/Engine/Engine.h @@ -66,6 +66,7 @@ namespace Donut ~Engine() = default; void DrawFullScreenQuad(); + void DrawBlurPass(); void DispatchCompute(const Camera& cam); void UploadCameraUBO(const Camera& cam); void UploadObjectsUBO(const std::vector& objs); @@ -109,6 +110,12 @@ namespace Donut float GetRotationSpeed() const { return m_RotationSpeed; } void SetRotationSpeed(float speed) { m_RotationSpeed = speed; } + float GetBlurStrength() const { return m_BlurStrength; } + void SetBlurStrength(float strength) { m_BlurStrength = strength; } + + float GetGlowIntensity() const { return m_GlowIntensity; } + void SetGlowIntensity(float intensity) { m_GlowIntensity = intensity; } + void LoadObjectsFromScene(const std::vector& objects); void ExportHighResFrame(const std::string& filename, int width = 4096, int height = 3072); void PrintObjectInfo() const; @@ -120,6 +127,7 @@ namespace Donut Ref m_Texture; Ref m_ShaderProgram; Ref m_ComputeProgram; + Ref m_BlurShader; Ref m_CameraUBO; Ref m_DiskUBO; Ref m_ObjectsUBO; @@ -145,7 +153,9 @@ namespace Donut float m_EarlyExitDistance = 5e11f; float m_DiskThickness = 0.1; - float m_DiskDensity = 1.2f; + float m_DiskDensity = 0.1f; float m_RotationSpeed = 1.0f; + float m_BlurStrength = 2.0f; + float m_GlowIntensity = 0.1f; }; }; -- cgit v1.3