aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorhachem <im@hachem.wtf>2025-08-22 04:48:42 +0200
committerhachem <im@hachem.wtf>2025-08-22 04:48:42 +0200
commitb9c20fccac64e7aadd28ea6c621c4ffda2561c54 (patch)
treec0efeabd28e53d136f253fa5a7bab19c0fb765f6
parentf469a1d1e8413e07f3e3033e719161ffd17fe463 (diff)
[add]: add bloom and blur
-rw-r--r--Assets/Shaders/Blur.glsl60
-rw-r--r--Assets/Shaders/Geodesic.glsl21
-rw-r--r--src/Engine/Engine.cpp19
-rw-r--r--src/Engine/Engine.h12
-rw-r--r--src/States/SimulationState.cpp16
5 files changed, 121 insertions, 7 deletions
diff --git a/Assets/Shaders/Blur.glsl b/Assets/Shaders/Blur.glsl
new file mode 100644
index 0000000..984f0ba
--- /dev/null
+++ b/Assets/Shaders/Blur.glsl
@@ -0,0 +1,60 @@
+#type vertex
+
+#version 330 core
+
+layout (location = 0) in vec2 a_Pos;
+layout (location = 1) in vec2 a_TexCoord;
+
+out vec2 v_TexCoord;
+
+void main()
+{
+ gl_Position = vec4(a_Pos, 0.0, 1.0);
+ v_TexCoord = a_TexCoord;
+}
+
+#type fragment
+
+#version 330 core
+
+in vec2 v_TexCoord;
+out vec4 o_FragColor;
+
+uniform sampler2D u_ScreenTexture;
+uniform vec2 u_Resolution;
+uniform float u_BlurStrength;
+uniform float u_GlowIntensity;
+
+void main()
+{
+ vec2 texelSize = 1.0 / u_Resolution;
+ vec4 centerColor = texture(u_ScreenTexture, v_TexCoord);
+
+ float brightness = (centerColor.r + centerColor.g + centerColor.b) / 3.0;
+ float glowMask = smoothstep(0.05, 0.3, brightness);
+
+ vec4 blurredColor = vec4(0.0);
+ float totalWeight = 0.0;
+
+ for (int x = -8; x <= 8; x++)
+ {
+ for (int y = -8; y <= 8; y++)
+ {
+ vec2 offset = vec2(x, y) * texelSize * u_BlurStrength;
+ vec4 sampleColor = texture(u_ScreenTexture, v_TexCoord + offset);
+
+ float weight = exp(-(x*x + y*y) / (2.0 * 8.0 * 8.0));
+ blurredColor += sampleColor * weight;
+ totalWeight += weight;
+ }
+ }
+
+ blurredColor /= totalWeight;
+
+ vec3 emissionColor = vec3(1.0, 0.8, 0.6);
+ vec3 glowColor = emissionColor * glowMask * u_GlowIntensity * 2.0;
+ vec3 auraColor = blurredColor.rgb * glowMask * u_GlowIntensity * 0.8;
+ vec3 finalColor = centerColor.rgb + glowColor + auraColor;
+
+ o_FragColor = vec4(finalColor, centerColor.a);
+}
diff --git a/Assets/Shaders/Geodesic.glsl b/Assets/Shaders/Geodesic.glsl
index ace58a5..1799601 100644
--- a/Assets/Shaders/Geodesic.glsl
+++ b/Assets/Shaders/Geodesic.glsl
@@ -323,7 +323,11 @@ vec4 SampleDiskColor(vec3 pos)
float brightness_medium = fbm(rotated_brightness_pos * 5.0, 2);
float brightness_small = fbm(rotated_brightness_pos * 7.0, 2);
float brightness_noise = (brightness_large * 0.6 + brightness_medium * 0.3 + brightness_small * 0.1);
- float brightness = 1.0 + density * 1.0 + brightness_noise * 0.4;
+
+ // Enhanced brightness with glow effect
+ float baseBrightness = 1.0 + density * 1.5; // Increased density contribution
+ float glowBrightness = brightness_noise * 0.8; // Enhanced noise contribution
+ float brightness = baseBrightness + glowBrightness;
return vec4(baseColor * brightness, density);
}
@@ -413,14 +417,21 @@ void main()
vec3 diskColor = diskSample.rgb;
float stepLength = currentStepSize * 1e-8;
- float absorption = density * stepLength * 1.2;
- float scattering = density * stepLength * 0.8;
+
+ float absorption = density * stepLength * 0.8;
+ float scattering = density * stepLength * 1.5;
float extinction = absorption + scattering;
float stepTransmittance = exp(-extinction);
- vec3 emission = diskColor * density * stepLength * 2.5 * sqrt(disk_density);
- accumulatedColor.rgb += emission * transmittance;
+ vec3 emission = diskColor * density * stepLength * 4.0 * sqrt(disk_density);
+
+ vec3 glowColor = mix(diskColor, vec3(1.0, 0.8, 0.6), 0.3);
+ float glowIntensity = density * stepLength * 2.0;
+ vec3 atmosphericGlow = glowColor * glowIntensity * 0.8;
+
+ vec3 totalEmission = emission + atmosphericGlow;
+ accumulatedColor.rgb += totalEmission * transmittance;
transmittance *= stepTransmittance;
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>(Shader::Create("Assets/Shaders/ComputeTextureQuad.glsl"));
m_ComputeProgram = CreateComputeProgram("Assets/Shaders/Geodesic.glsl");
+ m_BlurShader = Ref<Shader>(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<ObjectData>& 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<Donut::Object>& objects);
void ExportHighResFrame(const std::string& filename, int width = 4096, int height = 3072);
void PrintObjectInfo() const;
@@ -120,6 +127,7 @@ namespace Donut
Ref<Texture2D> m_Texture;
Ref<Shader> m_ShaderProgram;
Ref<Shader> m_ComputeProgram;
+ Ref<Shader> m_BlurShader;
Ref<UniformBuffer> m_CameraUBO;
Ref<UniformBuffer> m_DiskUBO;
Ref<UniformBuffer> 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;
};
};
diff --git a/src/States/SimulationState.cpp b/src/States/SimulationState.cpp
index 28504e6..2a79b3c 100644
--- a/src/States/SimulationState.cpp
+++ b/src/States/SimulationState.cpp
@@ -60,7 +60,7 @@ namespace Donut
RenderCommand::SetViewport(0, 0, static_cast<uint32_t>(engine.GetWidth()), static_cast<uint32_t>(engine.GetHeight()));
engine.DispatchCompute(engine.GetCamera());
- engine.DrawFullScreenQuad();
+ engine.DrawBlurPass();
}
void SimulationState::OnEvent(Event& event)
@@ -244,6 +244,20 @@ namespace Donut
}
ImGui::TextDisabled("Rotation speed multiplier (0 = no rotation)");
+ float blurStrength = engine.GetBlurStrength();
+ if (ImGui::SliderFloat("Blur Strength", &blurStrength, 0.5f, 5.0f, "%.2f"))
+ {
+ engine.SetBlurStrength(blurStrength);
+ }
+ ImGui::TextDisabled("Blur radius for glow effect");
+
+ float glowIntensity = engine.GetGlowIntensity();
+ if (ImGui::SliderFloat("Glow Intensity", &glowIntensity, 0.1f, 3.0f, "%.2f"))
+ {
+ engine.SetGlowIntensity(glowIntensity);
+ }
+ ImGui::TextDisabled("Intensity of the glow effect");
+
ImGui::Spacing();
ImGui::TextColored(ImVec4(0.9f, 0.9f, 1.0f, 1.0f), "Camera");