st-scroll-view-fade: Reduce number of GLSL uniforms and instructions

The vvalue and hvalue uniforms are only used to decide whether we
should do fade the edges or not based on the fade_edges uniform.
The result does not change accross fragments so there is no reason
to recompute it for every fragment (pixel) so just split the edge
fade into two uniforms and compute the "should we fade the edges"
boolean once for every direction (when setting the uniforms) instead
of for every single fragment twice.

This reduces the number of uniforms as well as the the number of instructions
which are limited on older hardware. It should also be more efficent.

https://bugzilla.gnome.org/show_bug.cgi?id=708007
This commit is contained in:
Adel Gadllah 2013-09-13 09:33:27 +02:00
parent c1b1ebe97e
commit 4095a58eb9
2 changed files with 8 additions and 14 deletions

View File

@ -142,18 +142,17 @@ st_scroll_view_fade_paint_target (ClutterOffscreenEffect *effect)
st_adjustment_get_values (self->vadjustment, &value, &lower, &upper, NULL, NULL, &page_size); st_adjustment_get_values (self->vadjustment, &value, &lower, &upper, NULL, NULL, &page_size);
value = (value - lower) / (upper - page_size - lower); value = (value - lower) / (upper - page_size - lower);
clutter_shader_effect_set_uniform (shader, "vvalue", G_TYPE_FLOAT, 1, value); clutter_shader_effect_set_uniform (shader, "fade_edges_v", G_TYPE_INT, 1, self->fade_edges ? value >= 0.0 : value > 0.0);
st_adjustment_get_values (self->hadjustment, &value, &lower, &upper, NULL, NULL, &page_size); st_adjustment_get_values (self->hadjustment, &value, &lower, &upper, NULL, NULL, &page_size);
value = (value - lower) / (upper - page_size - lower); value = (value - lower) / (upper - page_size - lower);
clutter_shader_effect_set_uniform (shader, "hvalue", G_TYPE_FLOAT, 1, value); clutter_shader_effect_set_uniform (shader, "fade_edges_h", G_TYPE_INT, 1, self->fade_edges ? value >= 0.0 : value > 0.0);
clutter_shader_effect_set_uniform (shader, "vfade_offset", G_TYPE_FLOAT, 1, self->vfade_offset); clutter_shader_effect_set_uniform (shader, "vfade_offset", G_TYPE_FLOAT, 1, self->vfade_offset);
clutter_shader_effect_set_uniform (shader, "hfade_offset", G_TYPE_FLOAT, 1, self->hfade_offset); clutter_shader_effect_set_uniform (shader, "hfade_offset", G_TYPE_FLOAT, 1, self->hfade_offset);
clutter_shader_effect_set_uniform (shader, "tex", G_TYPE_INT, 1, 0); clutter_shader_effect_set_uniform (shader, "tex", G_TYPE_INT, 1, 0);
clutter_shader_effect_set_uniform (shader, "height", G_TYPE_FLOAT, 1, clutter_actor_get_height (self->actor)); clutter_shader_effect_set_uniform (shader, "height", G_TYPE_FLOAT, 1, clutter_actor_get_height (self->actor));
clutter_shader_effect_set_uniform (shader, "width", G_TYPE_FLOAT, 1, clutter_actor_get_width (self->actor)); clutter_shader_effect_set_uniform (shader, "width", G_TYPE_FLOAT, 1, clutter_actor_get_width (self->actor));
clutter_shader_effect_set_uniform (shader, "fade_edges", G_TYPE_INT, 1, self->fade_edges);
clutter_shader_effect_set_uniform (shader, "fade_area_topleft", CLUTTER_TYPE_SHADER_FLOAT, 2, fade_area_topleft); clutter_shader_effect_set_uniform (shader, "fade_area_topleft", CLUTTER_TYPE_SHADER_FLOAT, 2, fade_area_topleft);
clutter_shader_effect_set_uniform (shader, "fade_area_bottomright", CLUTTER_TYPE_SHADER_FLOAT, 2, fade_area_bottomright); clutter_shader_effect_set_uniform (shader, "fade_area_bottomright", CLUTTER_TYPE_SHADER_FLOAT, 2, fade_area_bottomright);

View File

@ -22,9 +22,8 @@ uniform float height;
uniform float width; uniform float width;
uniform float vfade_offset; uniform float vfade_offset;
uniform float hfade_offset; uniform float hfade_offset;
uniform float vvalue; uniform bool fade_edges_h;
uniform float hvalue; uniform bool fade_edges_v;
uniform bool fade_edges;
uniform vec2 fade_area_topleft; uniform vec2 fade_area_topleft;
uniform vec2 fade_area_bottomright; uniform vec2 fade_area_bottomright;
@ -45,14 +44,10 @@ void main ()
float ratio = 1.0; float ratio = 1.0;
float fade_bottom_start = fade_area_bottomright[1] - vfade_offset; float fade_bottom_start = fade_area_bottomright[1] - vfade_offset;
float fade_right_start = fade_area_bottomright[0] - hfade_offset; float fade_right_start = fade_area_bottomright[0] - hfade_offset;
bool fade_top = y < vfade_offset && (fade_edges ? vvalue >= 0.0 bool fade_top = y < vfade_offset && fade_edges_v;
: vvalue > 0.0); bool fade_bottom = y > fade_bottom_start && fade_edges_v;
bool fade_bottom = y > fade_bottom_start && (fade_edges ? vvalue <= 1.0 bool fade_left = x < hfade_offset && fade_edges_h;
: vvalue < 1.0); bool fade_right = x > fade_right_start && fade_edges_h;
bool fade_left = x < hfade_offset && (fade_edges ? hvalue >= 0.0
: hvalue > 0.0);
bool fade_right = x > fade_right_start && (fade_edges ? hvalue <= 1.0
: hvalue < 1.0);
float vfade_scale = height / vfade_offset; float vfade_scale = height / vfade_offset;
if (fade_top) { if (fade_top) {