summaryrefslogtreecommitdiff
path: root/shaders/gl_bloom_extract_fragment.glsl
diff options
context:
space:
mode:
Diffstat (limited to 'shaders/gl_bloom_extract_fragment.glsl')
-rw-r--r--shaders/gl_bloom_extract_fragment.glsl34
1 files changed, 34 insertions, 0 deletions
diff --git a/shaders/gl_bloom_extract_fragment.glsl b/shaders/gl_bloom_extract_fragment.glsl
new file mode 100644
index 0000000..6d0a806
--- /dev/null
+++ b/shaders/gl_bloom_extract_fragment.glsl
@@ -0,0 +1,34 @@
+out vec4 outcolor;
+in vec2 frag_texture_coord;
+
+uniform sampler2D source;
+uniform float threshold;
+
+// Bloom curve selection:
+// 0 = Linear (default) - simple linear fade
+// 1 = Smooth - smoothstep for more gradual fade-in
+// 2 = Power - adjustable power curve
+#define BLOOM_CURVE 0
+
+void main() {
+ vec3 color = texture(source, frag_texture_coord).rgb;
+ // Calculate perceptual luminance
+ float brightness = dot(color, vec3(0.2126, 0.7152, 0.0722));
+
+ // Inverted bloom: full bloom at threshold and above, fades below threshold
+ // At brightness >= threshold: bloom_amount = 1.0 (full bloom)
+ // At brightness = 0: bloom_amount = 0.0 (no bloom)
+ float bloom_amount = min(brightness / threshold, 1.0);
+
+#if BLOOM_CURVE == 1
+ // Smooth curve - more gradual fade-in using smoothstep
+ bloom_amount = smoothstep(0.0, 1.0, bloom_amount);
+#elif BLOOM_CURVE == 2
+ // Power curve - adjust exponent for different feel
+ // < 1.0 = gentler fade, > 1.0 = steeper fade
+ bloom_amount = pow(bloom_amount, 0.7);
+#endif
+ // BLOOM_CURVE == 0 uses linear (no modification needed)
+
+ outcolor = vec4(color * bloom_amount, 1.0);
+}