From bdf8d0f1c31cb87eefdfd3cd956c9f2c309201d8 Mon Sep 17 00:00:00 2001 From: Nikita Churaev Date: Wed, 7 Mar 2018 00:14:44 +0300 Subject: [PATCH] compositor: improve vignette on background actor The shader used for computing a vignette currently has two problems: * The math is wrong such that the vignette isn't stretched across the whole actor and so ends abruptly * There is noticeable banding in its gradient This commit corrects both problems by fixing the computing and introducing noise dithering. --- src/compositor/meta-background-actor.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/compositor/meta-background-actor.c b/src/compositor/meta-background-actor.c index 2b619eb27..756b29e72 100644 --- a/src/compositor/meta-background-actor.c +++ b/src/compositor/meta-background-actor.c @@ -131,15 +131,19 @@ typedef enum { #define VIGNETTE_VERTEX_SHADER_CODE \ "position = cogl_tex_coord0_in.xy * scale + offset;\n" \ -#define VIGNETTE_FRAGMENT_SHADER_DECLARATIONS \ -"uniform float vignette_sharpness;\n" \ -"varying vec2 position;\n" \ +#define VIGNETTE_SQRT_2 "1.4142" + +#define VIGNETTE_FRAGMENT_SHADER_DECLARATIONS \ +"uniform float vignette_sharpness;\n" \ +"varying vec2 position;\n" \ +"float rand(vec2 p) { return fract(sin(dot(p, vec2(12.9898, 78.233))) * 43758.5453123); }\n" \ #define VIGNETTE_FRAGMENT_SHADER_CODE \ -"float t = 2.0 * length(position);\n" \ +"float t = " VIGNETTE_SQRT_2 " * length(position);\n" \ "t = min(t, 1.0);\n" \ "float pixel_brightness = 1.0 - t * vignette_sharpness;\n" \ "cogl_color_out.rgb = cogl_color_out.rgb * pixel_brightness;\n" \ +"cogl_color_out.rgb += (rand(position) - 0.5) / 255.0;\n" \ typedef struct _MetaBackgroundLayer MetaBackgroundLayer;