summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTimm Bäder <mail@baedert.org>2020-09-18 15:26:58 +0200
committerTimm Bäder <mail@baedert.org>2020-09-18 15:45:08 +0200
commita770ab34c47375d933c3dee155b894566cb932a4 (patch)
tree2ece376f481a7af59567307072bd70863a8c939e
parentb8e42407516900ab7d2e28ef3899684c1e072ab5 (diff)
downloadgtk+-a770ab34c47375d933c3dee155b894566cb932a4.tar.gz
gl renderer: Consolidate color pre-multiplication
Add a common function that tells us what it does and replace all the manual stuff with it. Fixes #3170
-rw-r--r--gsk/resources/glsl/border.glsl4
-rw-r--r--gsk/resources/glsl/color.glsl5
-rw-r--r--gsk/resources/glsl/coloring.glsl5
-rw-r--r--gsk/resources/glsl/linear_gradient.glsl11
-rw-r--r--gsk/resources/glsl/outset_shadow.glsl5
-rw-r--r--gsk/resources/glsl/preamble.glsl4
-rw-r--r--gsk/resources/glsl/radial_gradient.glsl19
7 files changed, 19 insertions, 34 deletions
diff --git a/gsk/resources/glsl/border.glsl b/gsk/resources/glsl/border.glsl
index 894843cc50..d35c60954c 100644
--- a/gsk/resources/glsl/border.glsl
+++ b/gsk/resources/glsl/border.glsl
@@ -10,9 +10,7 @@ _OUT_ _ROUNDED_RECT_UNIFORM_ transformed_inside_outline;
void main() {
gl_Position = u_projection * u_modelview * vec4(aPosition, 0.0, 1.0);
- final_color = u_color;
- final_color.rgb *= final_color.a; // pre-multiply
- final_color *= u_alpha;
+ final_color = premultiply(u_color) * u_alpha;
RoundedRect outside = create_rect(u_outline_rect);
RoundedRect inside = rounded_rect_shrink (outside, u_widths);
diff --git a/gsk/resources/glsl/color.glsl b/gsk/resources/glsl/color.glsl
index c80f501ac0..3dc2f1dcb7 100644
--- a/gsk/resources/glsl/color.glsl
+++ b/gsk/resources/glsl/color.glsl
@@ -6,10 +6,7 @@ _OUT_ vec4 final_color;
void main() {
gl_Position = u_projection * u_modelview * vec4(aPosition, 0.0, 1.0);
- final_color = u_color;
- // Pre-multiply alpha
- final_color.rgb *= final_color.a;
- final_color *= u_alpha;
+ final_color = premultiply(u_color) * u_alpha;
}
// FRAGMENT_SHADER:
diff --git a/gsk/resources/glsl/coloring.glsl b/gsk/resources/glsl/coloring.glsl
index e1b26540c8..6342ccb890 100644
--- a/gsk/resources/glsl/coloring.glsl
+++ b/gsk/resources/glsl/coloring.glsl
@@ -8,10 +8,7 @@ void main() {
vUv = vec2(aUv.x, aUv.y);
- final_color = u_color;
- // pre-multiply
- final_color.rgb *= final_color.a;
- final_color *= u_alpha;
+ final_color = premultiply(u_color) * u_alpha;
}
// FRAGMENT_SHADER:
diff --git a/gsk/resources/glsl/linear_gradient.glsl b/gsk/resources/glsl/linear_gradient.glsl
index cffe39294d..dea01344f0 100644
--- a/gsk/resources/glsl/linear_gradient.glsl
+++ b/gsk/resources/glsl/linear_gradient.glsl
@@ -25,10 +25,10 @@ void main() {
for (int i = 0; i < u_num_color_stops; i ++) {
color_offsets[i] = u_color_stops[(i * 5) + 0];
- color_stops[i].r = u_color_stops[(i * 5) + 1];
- color_stops[i].g = u_color_stops[(i * 5) + 2];
- color_stops[i].b = u_color_stops[(i * 5) + 3];
- color_stops[i].a = u_color_stops[(i * 5) + 4];
+ color_stops[i] = premultiply(vec4(u_color_stops[(i * 5) + 1],
+ u_color_stops[(i * 5) + 2],
+ u_color_stops[(i * 5) + 3],
+ u_color_stops[(i * 5) + 4]));
}
}
@@ -66,8 +66,5 @@ void main() {
}
}
- /* Pre-multiply */
- color.rgb *= color.a;
-
setOutputColor(color * u_alpha);
}
diff --git a/gsk/resources/glsl/outset_shadow.glsl b/gsk/resources/glsl/outset_shadow.glsl
index 40ef45f648..2a2a54ec6b 100644
--- a/gsk/resources/glsl/outset_shadow.glsl
+++ b/gsk/resources/glsl/outset_shadow.glsl
@@ -10,10 +10,7 @@ void main() {
vUv = vec2(aUv.x, aUv.y);
- final_color = u_color;
- // pre-multiply
- final_color.rgb *= final_color.a;
- final_color *= u_alpha;
+ final_color = premultiply(u_color) * u_alpha;
RoundedRect outline = create_rect(u_outline_rect);
rounded_rect_transform(outline, u_modelview);
diff --git a/gsk/resources/glsl/preamble.glsl b/gsk/resources/glsl/preamble.glsl
index 9dd711cbd2..013938899a 100644
--- a/gsk/resources/glsl/preamble.glsl
+++ b/gsk/resources/glsl/preamble.glsl
@@ -35,3 +35,7 @@ create_rect(vec4[3] data)
return RoundedRect(bounds, corner_points1, corner_points2);
}
+
+vec4 premultiply(vec4 c) {
+ return vec4(c.rgb * c.a, c.a);
+}
diff --git a/gsk/resources/glsl/radial_gradient.glsl b/gsk/resources/glsl/radial_gradient.glsl
index 84673fc470..9d8be275b3 100644
--- a/gsk/resources/glsl/radial_gradient.glsl
+++ b/gsk/resources/glsl/radial_gradient.glsl
@@ -21,10 +21,10 @@ void main() {
for (int i = 0; i < u_num_color_stops; i ++) {
color_offsets[i] = u_color_stops[(i * 5) + 0];
- color_stops[i].r = u_color_stops[(i * 5) + 1];
- color_stops[i].g = u_color_stops[(i * 5) + 2];
- color_stops[i].b = u_color_stops[(i * 5) + 3];
- color_stops[i].a = u_color_stops[(i * 5) + 4];
+ color_stops[i] = premultiply(vec4(u_color_stops[(i * 5) + 1],
+ u_color_stops[(i * 5) + 2],
+ u_color_stops[(i * 5) + 3],
+ u_color_stops[(i * 5) + 4]));
}
}
@@ -50,23 +50,18 @@ float abs_offset(float offset) {
return start + ((end - start) * offset);
}
-vec4 premultiply(vec4 c) {
- vec4 k = vec4(c.rgb * c.a, c.a);
- return k;
-}
-
void main() {
vec2 pixel = get_frag_coord();
vec2 rel = (center - pixel) / (u_radius);
float d = sqrt(dot(rel, rel));
if (d < abs_offset (color_offsets[0])) {
- setOutputColor(premultiply(color_stops[0]) * u_alpha);
+ setOutputColor(color_stops[0] * u_alpha);
return;
}
if (d > end) {
- setOutputColor(premultiply(color_stops[u_num_color_stops - 1]) * u_alpha);
+ setOutputColor(color_stops[u_num_color_stops - 1] * u_alpha);
return;
}
@@ -85,5 +80,5 @@ void main() {
}
}
- setOutputColor(premultiply(color) * u_alpha);
+ setOutputColor(color * u_alpha);
}