Commit 8ca46169 authored by Timm Bäder's avatar Timm Bäder 👎

gl renderer: Blur shader improvements

Use a two-pass blur shader, fix a few other things and unify the
blurring of blur nodes and blurred outset shadow nodes.

Related to #1283
parent 642ced0c
This diff is collapsed.
......@@ -73,7 +73,7 @@ struct _Program
struct {
int blur_radius_location;
int blur_size_location;
int dir_location;
int blur_dir_location;
} blur;
struct {
int color_location;
......
uniform float u_blur_radius;// = 40.0;
uniform vec2 u_blur_size;// = vec2(393, 393);
uniform float u_blur_radius;
uniform vec2 u_blur_size;
uniform vec2 u_blur_dir;
float Gaussian (float sigma, float x) {
return exp ( - (x * x) / (2.0 * sigma * sigma));
}
const float PI = 3.14159265;
const float RADIUS_MULTIPLIER = 3.0;
vec4 blur_pixel (in vec2 uv) {
float total = 0.0;
vec4 ret = vec4 (0);
float pixel_size_x = (1.0 / u_blur_size.x);
float pixel_size_y = (1.0 / u_blur_size.y);
// blur_radius 0 is NOT supported and MUST be caught before.
// XXX The magic value here is GAUSSIAN_SCALE_FACTOR from gskcairoblur.c
float radius = u_blur_radius * 2.30348;
// Partially from http://callumhay.blogspot.com/2010/09/gaussian-blur-shader-glsl.html
void main() {
float sigma = u_blur_radius; // *shrug*
float blur_radius = u_blur_radius * RADIUS_MULTIPLIER;
vec3 incrementalGaussian;
incrementalGaussian.x = 1.0 / (sqrt(2.0 * PI) * sigma);
incrementalGaussian.y = exp(-0.5 / (sigma * sigma));
incrementalGaussian.z = incrementalGaussian.y * incrementalGaussian.y;
int half_radius = max(int(radius / 2.0), 1);
vec2 pixel_step = vec2(1.0) / u_blur_size;
for (int y = -half_radius; y < half_radius; y ++) {
float fy = Gaussian (radius / 2.0, float(y));
float offset_y = float(y) * pixel_size_y;
float coefficientSum = 0;
vec4 sum = Texture(u_source, vUv) * incrementalGaussian.x;
coefficientSum += incrementalGaussian.x;
incrementalGaussian.xy *= incrementalGaussian.yz;
for (int x = -half_radius; x < half_radius; x ++) {
float fx = Gaussian (radius / 2.0, float(x));
float offset_x = float(x) * pixel_size_x;
int pixels_per_side = int(floor(blur_radius / 2.0));
for (int i = 1; i <= pixels_per_side; i++) {
vec2 p = i * pixel_step * u_blur_dir;
vec4 c = Texture(u_source, uv + vec2(offset_x, offset_y));
total += fx * fy;
ret += c * fx * fy;
}
}
sum += Texture(u_source, vUv - p) * incrementalGaussian.x;
sum += Texture(u_source, vUv + p) * incrementalGaussian.x;
return ret / total;
}
coefficientSum += 2.0 * incrementalGaussian.x;
incrementalGaussian.xy *= incrementalGaussian.yz;
}
void main() {
vec4 color = blur_pixel(vUv);
setOutputColor(color);
setOutputColor(sum / coefficientSum);
}
......@@ -43,7 +43,7 @@ static const char *css =
".b1 {"
" all: unset;"
" min-width: 100px;"
" min-height:100px;"
" min-height: 100px;"
" border-radius: 7px 7px 0px 0px;"
" box-shadow: 0px 0px 9px 0px rgba(0, 0, 0, 0.5);"
"}"
......@@ -93,6 +93,7 @@ main (int argc, char **argv)
GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
gtk_window_set_decorated (GTK_WINDOW (window), FALSE);
box = gtk_box_new (GTK_ORIENTATION_VERTICAL, 120);
top = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 120);
bottom = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 120);
......@@ -124,7 +125,6 @@ main (int argc, char **argv)
gtk_style_context_add_class (gtk_widget_get_style_context (w), "five");
gtk_container_add (GTK_CONTAINER (top), w);
/* Bottom */
w = gtk_button_new ();
gtk_widget_set_valign (w, GTK_ALIGN_CENTER);
......@@ -153,6 +153,4 @@ main (int argc, char **argv)
gtk_widget_show (window);
gtk_main ();
gtk_widget_destroy (window);
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment