summaryrefslogtreecommitdiff
path: root/shaders/gl_bloom_blur_fragment.glsl
diff options
context:
space:
mode:
authorPeter Fors <peter.fors@mindkiller.com>2025-10-09 22:07:52 +0200
committerPeter Fors <peter.fors@mindkiller.com>2025-10-09 22:07:52 +0200
commit030724a9aea346e4a9843d5842fb28c6d6c4cf1a (patch)
treef06fb84aaef64b2f4e2d81b3d2d3eef71bad83ec /shaders/gl_bloom_blur_fragment.glsl
parent412b2ef851516c1de8ba5006ddd284192cbcaf9b (diff)
Rearrangement and refactoring and optimizations and more accuracy
Diffstat (limited to 'shaders/gl_bloom_blur_fragment.glsl')
-rw-r--r--shaders/gl_bloom_blur_fragment.glsl50
1 files changed, 50 insertions, 0 deletions
diff --git a/shaders/gl_bloom_blur_fragment.glsl b/shaders/gl_bloom_blur_fragment.glsl
new file mode 100644
index 0000000..94eff93
--- /dev/null
+++ b/shaders/gl_bloom_blur_fragment.glsl
@@ -0,0 +1,50 @@
+out vec4 outcolor;
+in vec2 frag_texture_coord;
+
+uniform sampler2D source;
+uniform bool horizontal;
+
+// ========== QUALITY SETTINGS ==========
+// Change this to switch between quality levels:
+// 0 = Fastest (5-tap, best for integrated GPUs)
+// 1 = Medium quality (9-tap, good balance)
+// 2 = High quality (17-tap, beautiful bloom but expensive)
+#define BLUR_QUALITY 2
+
+#if BLUR_QUALITY == 0
+ // 5-tap gaussian blur (3 samples each direction)
+ const int SAMPLE_COUNT = 3;
+ const float weight[3] = float[](0.3829249226, 0.2419707245, 0.0606531529);
+ const float blur_radius = 1.0;
+#elif BLUR_QUALITY == 1
+ // 9-tap gaussian blur (5 samples each direction)
+ const int SAMPLE_COUNT = 5;
+ const float weight[5] = float[](0.227027, 0.1945946, 0.1216216, 0.054054, 0.016216);
+ const float blur_radius = 1.0;
+#else
+ // 17-tap gaussian blur (9 samples each direction)
+ const int SAMPLE_COUNT = 9;
+ const float weight[9] = float[](0.1964825501511404, 0.1782316199485724, 0.12149164501415554, 0.0652229951888931, 0.027835877787234808, 0.009270061520867907, 0.0024201487396289743, 0.0004963317290261215, 0.0000801326238056394);
+ const float blur_radius = 1.0;
+#endif
+
+void main() {
+ vec2 tex_offset = 1.0 / vec2(textureSize(source, 0));
+ vec3 result = texture(source, frag_texture_coord).rgb * weight[0];
+
+ if(horizontal) {
+ for(int i = 1; i < SAMPLE_COUNT; ++i) {
+ float offset = tex_offset.x * float(i) * blur_radius;
+ result += texture(source, frag_texture_coord + vec2(offset, 0.0)).rgb * weight[i];
+ result += texture(source, frag_texture_coord - vec2(offset, 0.0)).rgb * weight[i];
+ }
+ } else {
+ for(int i = 1; i < SAMPLE_COUNT; ++i) {
+ float offset = tex_offset.y * float(i) * blur_radius;
+ result += texture(source, frag_texture_coord + vec2(0.0, offset)).rgb * weight[i];
+ result += texture(source, frag_texture_coord - vec2(0.0, offset)).rgb * weight[i];
+ }
+ }
+
+ outcolor = vec4(result, 1.0);
+}