[gtk/wip/baedert/radial-gradient: 5/5] gl renderer: Consolidate color pre-multiplication
- From: Timm Bäder <baedert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk/wip/baedert/radial-gradient: 5/5] gl renderer: Consolidate color pre-multiplication
- Date: Fri, 18 Sep 2020 13:27:39 +0000 (UTC)
commit b91931b54b5c5f0c7ee5b333d7de59dabadbd110
Author: Timm Bäder <mail baedert org>
Date: Fri Sep 18 15:26:58 2020 +0200
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
gsk/resources/glsl/border.glsl | 4 +---
gsk/resources/glsl/color.glsl | 5 +----
gsk/resources/glsl/coloring.glsl | 5 +----
gsk/resources/glsl/linear_gradient.glsl | 11 ++++-------
gsk/resources/glsl/outset_shadow.glsl | 5 +----
gsk/resources/glsl/preamble.glsl | 4 ++++
gsk/resources/glsl/radial_gradient.glsl | 19 +++++++------------
7 files changed, 19 insertions(+), 34 deletions(-)
---
diff --git a/gsk/resources/glsl/border.glsl b/gsk/resources/glsl/border.glsl
index 894843cc50..3b9c7e4e78 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);
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..b8e97ef60f 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);
}
// FRAGMENT_SHADER:
diff --git a/gsk/resources/glsl/coloring.glsl b/gsk/resources/glsl/coloring.glsl
index e1b26540c8..e1ce0415aa 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);
}
// 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..d497fb32ee 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);
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);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]