Skip to content

Commit 720cb81

Browse files
authored
lightbox: Reduce color banding with dithering... (#11757)
...by using pseudo random generated noise.
1 parent 97af169 commit 720cb81

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

js/ui/lightbox.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,15 @@ uniform float brightness;\n\
1717
uniform float vignette_sharpness;\n';
1818

1919
const VIGNETTE_CODE = '\
20+
const float NOISE_GRANULARITY = 1.0/255.0;\n\
2021
cogl_color_out.a = cogl_color_in.a;\n\
2122
cogl_color_out.rgb = vec3(0.0, 0.0, 0.0);\n\
2223
vec2 position = cogl_tex_coord_in[0].xy - 0.5;\n\
2324
float t = length(2.0 * position);\n\
2425
t = clamp(t, 0.0, 1.0);\n\
2526
float pixel_brightness = mix(1.0, 1.0 - vignette_sharpness, t);\n\
27+
float pseudo_rand = fract(sin(dot(position.xy, vec2(12.9898,78.233))) * 43758.5453);\n\
28+
pixel_brightness += mix(-NOISE_GRANULARITY, NOISE_GRANULARITY, pseudo_rand);\n\
2629
cogl_color_out.a = cogl_color_out.a * (1 - pixel_brightness * brightness);';
2730
;
2831

0 commit comments

Comments
 (0)