Skip to content

Commit 32398dd

Browse files
authored
blur: Add saturation option (#855)
This option controls the saturation of the blurred image.
1 parent a952aee commit 32398dd

File tree

3 files changed

+21
-0
lines changed

3 files changed

+21
-0
lines changed

metadata/blur.xml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,13 @@
3838
<_name>Bokeh</_name>
3939
</desc>
4040
</option>
41+
<option name="saturation" type="double">
42+
<_short>Blur saturation</_short>
43+
<_long>Sets the saturation of the blurred content.</_long>
44+
<default>1.0</default>
45+
<min>0.0</min>
46+
<max>3.0</max>
47+
</option>
4148
<!-- Box -->
4249
<option name="box_offset" type="double">
4350
<_short>Box offset</_short>

plugins/blur/blur-base.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,23 @@ static const char *blur_blend_fragment_shader =
2626
precision mediump float;
2727
2828
@builtin@
29+
uniform float sat;
2930
uniform sampler2D bg_texture;
3031
3132
varying mediump vec2 uvpos[2];
3233
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+
3342
void main()
3443
{
3544
vec4 bp = texture2D(bg_texture, uvpos[0]);
45+
bp = vec4(saturation(bp.rgb, sat), bp.a);
3646
vec4 wp = get_pixel(uvpos[1]);
3747
vec4 c = clamp(4.0 * wp.a, 0.0, 1.0) * bp;
3848
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)
4353
this->output = output;
4454
this->algorithm_name = name;
4555

56+
this->saturation_opt.load_option("blur/saturation");
4657
this->offset_opt.load_option("blur/" + algorithm_name + "_offset");
4758
this->degrade_opt.load_option("blur/" + algorithm_name + "_degrade");
4859
this->iterations_opt.load_option("blur/" + algorithm_name + "_iterations");
4960

5061
this->options_changed = [=] () { output->render->damage_whole(); };
62+
this->saturation_opt.set_callback(options_changed);
5163
this->offset_opt.set_callback(options_changed);
5264
this->degrade_opt.set_callback(options_changed);
5365
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,
233245
blend_program.uniformMatrix4f("mvp", glm::inverse(target_fb.transform));
234246
/* XXX: core should give us the number of texture units used */
235247
blend_program.uniform1i("bg_texture", 1);
248+
blend_program.uniform1f("sat", saturation_opt);
236249

237250
blend_program.set_active_texture(src_tex);
238251
GL_CALL(glActiveTexture(GL_TEXTURE0 + 1));

plugins/blur/blur.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ class wf_blur_base
101101
* should be set by the constructor */
102102
std::string algorithm_name;
103103

104+
wf::option_wrapper_t<double> saturation_opt;
104105
wf::option_wrapper_t<double> offset_opt;
105106
wf::option_wrapper_t<int> degrade_opt, iterations_opt;
106107
wf::config::option_base_t::updated_callback_t options_changed;

0 commit comments

Comments
 (0)