From 925809ea75d7c37282da92e739ce82cc88a0df91 Mon Sep 17 00:00:00 2001 From: Georges Basile Stavracas Neto Date: Thu, 17 Dec 2020 00:42:16 -0300 Subject: [PATCH] clutter/blur: Pass direction as vec2 Yet another way to reduce the instruction count of the fragment shader. Passing a pair of floats once is virtually free, compared to computing horizontal and vertical on each fragment run. Part-of: --- clutter/clutter/clutter-blur.c | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/clutter/clutter/clutter-blur.c b/clutter/clutter/clutter-blur.c index 3c17c3566..c60451d0a 100644 --- a/clutter/clutter/clutter-blur.c +++ b/clutter/clutter/clutter-blur.c @@ -69,11 +69,9 @@ static const char *gaussian_blur_glsl_declarations = "uniform float sigma; \n" "uniform float pixel_step; \n" -"uniform int vertical; \n"; +"uniform vec2 direction; \n"; static const char *gaussian_blur_glsl = -" int horizontal = 1 - vertical; \n" -" \n" " vec2 uv = vec2 (cogl_tex_coord.st); \n" " \n" " vec3 gauss_coefficient; \n" @@ -96,8 +94,7 @@ static const char *gaussian_blur_glsl = " float gauss_ratio = gauss_coefficient.x / coefficient_subtotal; \n" " \n" " float foffset = float (i) + gauss_ratio; \n" -" vec2 offset = vec2 (foffset * pixel_step * float (horizontal), \n" -" foffset * pixel_step * float (vertical)); \n" +" vec2 offset = direction * foffset * pixel_step; \n" " \n" " ret += texture2D (cogl_sampler, uv + offset) * coefficient_subtotal; \n" " ret += texture2D (cogl_sampler, uv - offset) * coefficient_subtotal; \n" @@ -179,7 +176,7 @@ update_blur_uniforms (ClutterBlur *blur, gboolean vertical = pass->orientation == VERTICAL; int sigma_uniform; int pixel_step_uniform; - int vertical_uniform; + int direction_uniform; pixel_step_uniform = cogl_pipeline_get_uniform_location (pass->pipeline, "pixel_step"); @@ -205,13 +202,20 @@ update_blur_uniforms (ClutterBlur *blur, blur->sigma / blur->downscale_factor); } - vertical_uniform = - cogl_pipeline_get_uniform_location (pass->pipeline, "vertical"); - if (vertical_uniform > -1) + direction_uniform = + cogl_pipeline_get_uniform_location (pass->pipeline, "direction"); + if (direction_uniform > -1) { - cogl_pipeline_set_uniform_1i (pass->pipeline, - vertical_uniform, - vertical); + gboolean horizontal = !vertical; + float direction[2] = { + horizontal, + vertical, + }; + + cogl_pipeline_set_uniform_float (pass->pipeline, + direction_uniform, + 2, 1, + direction); } }