1/* 2 * st-scroll-view-fade.glsl: Edge fade effect for StScrollView 3 * 4 * Copyright 2010 Intel Corporation. 5 * Copyright 2011 Adel Gadllah 6 * 7 * This program is free software; you can redistribute it and/or modify it 8 * under the terms and conditions of the GNU Lesser General Public License, 9 * version 2.1, as published by the Free Software Foundation. 10 * 11 * This program is distributed in the hope it will be useful, but WITHOUT ANY 12 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 13 * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for 14 * more details. 15 * 16 * You should have received a copy of the GNU Lesser General Public License 17 * along with this program. If not, see <http://www.gnu.org/licenses/>. 18 */ 19 20uniform sampler2D tex; 21uniform float height; 22uniform float width; 23uniform float fade_offset_top; 24uniform float fade_offset_bottom; 25uniform float fade_offset_left; 26uniform float fade_offset_right; 27uniform bool fade_edges_top; 28uniform bool fade_edges_right; 29uniform bool fade_edges_bottom; 30uniform bool fade_edges_left; 31uniform bool extend_fade_area; 32 33uniform vec2 fade_area_topleft; 34uniform vec2 fade_area_bottomright; 35 36void main () 37{ 38 cogl_color_out = cogl_color_in * texture2D (tex, vec2 (cogl_tex_coord_in[0].xy)); 39 40 float y = height * cogl_tex_coord_in[0].y; 41 float x = width * cogl_tex_coord_in[0].x; 42 float ratio = 1.0; 43 44 if (x > fade_area_topleft[0] && x < fade_area_bottomright[0] && 45 y > fade_area_topleft[1] && y < fade_area_bottomright[1]) 46 { 47 float fade_top_start = fade_area_topleft[1] + fade_offset_top; 48 float fade_left_start = fade_area_topleft[0] + fade_offset_left; 49 float fade_bottom_start = fade_area_bottomright[1] - fade_offset_bottom; 50 float fade_right_start = fade_area_bottomright[0] - fade_offset_right; 51 bool fade_top = y < fade_top_start && fade_edges_top; 52 bool fade_bottom = y > fade_bottom_start && fade_edges_bottom; 53 bool fade_left = x < fade_left_start && fade_edges_left; 54 bool fade_right = x > fade_right_start && fade_edges_right; 55 56 if (fade_top) { 57 ratio *= (fade_area_topleft[1] - y) / (fade_area_topleft[1] - fade_top_start); 58 } 59 60 if (fade_bottom) { 61 ratio *= (fade_area_bottomright[1] - y) / (fade_area_bottomright[1] - fade_bottom_start); 62 } 63 64 if (fade_left) { 65 ratio *= (fade_area_topleft[0] - x) / (fade_area_topleft[0] - fade_left_start); 66 } 67 68 if (fade_right) { 69 ratio *= (fade_area_bottomright[0] - x) / (fade_area_bottomright[0] - fade_right_start); 70 } 71 } else if (extend_fade_area) { 72 if (x <= fade_area_topleft[0] && fade_edges_left || 73 x >= fade_area_bottomright[0] && fade_edges_right || 74 y <= fade_area_topleft[1] && fade_edges_top || 75 y >= fade_area_bottomright[1] && fade_edges_bottom) { 76 ratio = 0.0; 77 } 78 } 79 80 cogl_color_out *= ratio; 81} 82