@@ -26,13 +26,23 @@ static const char *blur_blend_fragment_shader =
26
26
precision mediump float;
27
27
28
28
@builtin@
29
+ uniform float sat;
29
30
uniform sampler2D bg_texture;
30
31
31
32
varying mediump vec2 uvpos[2];
32
33
34
+ vec3 saturation(vec3 rgb, float adjustment)
35
+ {
36
+ // Algorithm from Chapter 16 of OpenGL Shading Language
37
+ const vec3 w = vec3(0.2125, 0.7154, 0.0721);
38
+ vec3 intensity = vec3(dot(rgb, w));
39
+ return mix(intensity, rgb, adjustment);
40
+ }
41
+
33
42
void main()
34
43
{
35
44
vec4 bp = texture2D(bg_texture, uvpos[0]);
45
+ bp = vec4(saturation(bp.rgb, sat), bp.a);
36
46
vec4 wp = get_pixel(uvpos[1]);
37
47
vec4 c = clamp(4.0 * wp.a, 0.0, 1.0) * bp;
38
48
gl_FragColor = wp + (1.0 - wp.a) * c;
@@ -43,11 +53,13 @@ wf_blur_base::wf_blur_base(wf::output_t *output, std::string name)
43
53
this ->output = output;
44
54
this ->algorithm_name = name;
45
55
56
+ this ->saturation_opt .load_option (" blur/saturation" );
46
57
this ->offset_opt .load_option (" blur/" + algorithm_name + " _offset" );
47
58
this ->degrade_opt .load_option (" blur/" + algorithm_name + " _degrade" );
48
59
this ->iterations_opt .load_option (" blur/" + algorithm_name + " _iterations" );
49
60
50
61
this ->options_changed = [=] () { output->render ->damage_whole (); };
62
+ this ->saturation_opt .set_callback (options_changed);
51
63
this ->offset_opt .set_callback (options_changed);
52
64
this ->degrade_opt .set_callback (options_changed);
53
65
this ->iterations_opt .set_callback (options_changed);
@@ -233,6 +245,7 @@ void wf_blur_base::render(wf::texture_t src_tex, wlr_box src_box,
233
245
blend_program.uniformMatrix4f (" mvp" , glm::inverse (target_fb.transform ));
234
246
/* XXX: core should give us the number of texture units used */
235
247
blend_program.uniform1i (" bg_texture" , 1 );
248
+ blend_program.uniform1f (" sat" , saturation_opt);
236
249
237
250
blend_program.set_active_texture (src_tex);
238
251
GL_CALL (glActiveTexture (GL_TEXTURE0 + 1 ));
0 commit comments