summaryrefslogtreecommitdiff
path: root/shaders/gl_bloom_extract_fragment.glsl
blob: 6d0a806ade8699b6554c41f0bedfaa958b3313da (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
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);
}