diff options
| author | Peter Fors <peter.fors@mindkiller.com> | 2025-10-09 22:07:52 +0200 |
|---|---|---|
| committer | Peter Fors <peter.fors@mindkiller.com> | 2025-10-09 22:07:52 +0200 |
| commit | 030724a9aea346e4a9843d5842fb28c6d6c4cf1a (patch) | |
| tree | f06fb84aaef64b2f4e2d81b3d2d3eef71bad83ec /shaders/gl_bloom_extract_fragment.glsl | |
| parent | 412b2ef851516c1de8ba5006ddd284192cbcaf9b (diff) | |
Rearrangement and refactoring and optimizations and more accuracy
Diffstat (limited to 'shaders/gl_bloom_extract_fragment.glsl')
| -rw-r--r-- | shaders/gl_bloom_extract_fragment.glsl | 34 |
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); +} |
