BEFORE ================================== uniform sampler2D tex; uniform float height; uniform float width; uniform float scrollbar_width; uniform float offset_bottom; uniform float offset_top; uniform bool rtl; void main () { vec4 color = cogl_color_in * texture2D (tex, vec2 (cogl_tex_coord_in[0].xy)); float y = height * cogl_tex_coord_in[0].y; float x = width * cogl_tex_coord_in[0].x; float ratio = 0.0; float fade_bottom_start = height - offset_bottom; if (offset_top != 0.0 && y < offset_top && ((rtl && x > scrollbar_width) || (!rtl && x < (width - scrollbar_width)))) { ratio = y / offset_top; cogl_color_out = color * ratio; } else if (offset_bottom != 0.0 && y > fade_bottom_start && ((rtl && x > scrollbar_width) || (!rtl && x < (width - scrollbar_width)))) { ratio = (height - y)/(height - fade_bottom_start); cogl_color_out = color * ratio; } else { cogl_color_out = color; } } ================================ AFTER =============================== uniform sampler2D tex; uniform float height; uniform float width; uniform float scrollbar_width; uniform float offset_bottom; uniform float offset_top; uniform bool rtl; void main () { vec4 color = cogl_color_in * texture2D (tex, vec2 (cogl_tex_coord_in[0].xy)); float y = height * cogl_tex_coord_in[0].y; float x = width * cogl_tex_coord_in[0].x; float ratio = 1.0; float fade_bottom_start = height - offset_bottom; float ratioA = y / offset_top; float ratioB = (height - y)/(height - fade_bottom_start); bool in_scroll_area = ((rtl && x > scrollbar_width) || (!rtl && x < (width - scrollbar_width))); bool fade_top = y < offset_top && in_scroll_area; bool fade_bottom = y > fade_bottom_start && in_scroll_area; if (fade_top) { ratio = ratioA; } else if (fade_bottom) { ratio = ratioB; } cogl_color_out = color * ratio; }